mapproxy/mapproxy — pull request #105 by walkermatt (2013-07-17 10:39:26+00:00)
Title: Ensure OGRShapeReader internal data source is closed

@olt I've been experimenting with using `mapproxy.util.geom.load_datasource` to load features for use in an authorization filter. I found that when load testing I was running into the following error:

OGRShapeReaderError: PQconnectdb failed.
FATAL: sorry, too many clients already

When I looked into it I found that the internal OGR data source was not getting closed in `OGRShapeReader`. This pull attempts to ensure that the data source is closed when the `close` method is called and uses a context manager when creating an instance to ensure `close` is called when the reader is no longer required.

I've tested manually using `CtypesOGRShapeReader` on Linux and Windows and `OSGeoOGRShapeReader` on Windows.