This is an automated email from the git hooks/post-receive script. johanvdw-guest pushed a commit to branch master in repository fiona.
commit efc2709a3640ca7f5335a4d8d0684168ce467e6e Author: Johan Van de Wauw <[email protected]> Date: Tue Jan 31 09:51:05 2017 +0100 Imported Upstream version 1.7.2 --- CHANGES.txt | 23 ++++++++++++++++++++++- fiona/__init__.py | 3 ++- fiona/collection.py | 31 +++++++++++++++++++++++++------ fiona/ogrext1.pyx | 8 ++++---- fiona/ogrext2.pyx | 8 ++++---- tests/test_bigint.py | 2 +- tests/test_bytescollection.py | 16 +++++++++++----- tests/test_collection.py | 2 +- tests/test_drivers.py | 2 +- tests/test_feature.py | 2 +- tests/test_geojson.py | 2 +- tests/test_geometry.py | 2 +- tests/test_geopackage.py | 2 +- tests/test_layer.py | 2 +- tests/test_listing.py | 2 +- tests/test_multiconxn.py | 14 +++++++------- tests/test_props.py | 6 +++--- tests/test_read_drivers.py | 2 +- tests/test_remove.py | 2 +- tests/test_revolvingdoor.py | 2 +- tests/test_rfc3339.py | 2 +- tests/test_schema.py | 4 ++-- tests/test_slice.py | 2 +- tests/test_unicode.py | 8 ++++---- tests/test_vfs.py | 2 +- 25 files changed, 99 insertions(+), 52 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 3ca052d..c9bc5b6 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -3,12 +3,33 @@ Changes All issue numbers are relative to https://github.com/Toblerity/Fiona/issues. +1.7.2 (2017-01-27) +------------------ + +Future Deprecation: + +- `Collection.__next__()` is buggy in that it can lead to duplication of + features when used in combination with `Collection.filter()` or + `Collection.__iter__()`. It will be removed in Fiona 2.0. Please check for + usage of this deprecated feature by running your tests or programs with + `PYTHONWARNINGS="always:::fiona"` or `-W"always:::fiona"` and switch from + `next(collection)` to `next(iter(collection))` (#301). + +Bug fix: + +- Zipped streams of bytes can be accessed by `BytesCollection` (#318). + +1.7.1.post1 (2016-12-23) +------------------------ +- New binary wheels using version 1.2.0 of sgillies/frs-wheel-builds. See + https://github.com/sgillies/frs-wheel-builds/blob/master/CHANGES.txt. + 1.7.1 (2016-11-16) ------------------ Bug Fixes: -- Prevent Fiona from stumbling over '*Z', '*M', and '*ZM' geometry types +- Prevent Fiona from stumbling over 'Z', 'M', and 'ZM' geometry types introduced in GDAL 2.1 (#384). Fiona 1.7.1 doesn't add explicit support for these types, they are coerced to geometry types 1-7 ('Point', 'LineString', etc.) diff --git a/fiona/__init__.py b/fiona/__init__.py index 8904c2d..a010654 100644 --- a/fiona/__init__.py +++ b/fiona/__init__.py @@ -81,7 +81,7 @@ import uuid __all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width'] -__version__ = "1.7.1" +__version__ = "1.7.2" __gdal_version__ = get_gdal_release_name().decode('utf-8') log = logging.getLogger('Fiona') @@ -90,6 +90,7 @@ class NullHandler(logging.Handler): pass log.addHandler(NullHandler()) + def open( path, mode='r', diff --git a/fiona/collection.py b/fiona/collection.py index d64cde7..15be3e4 100644 --- a/fiona/collection.py +++ b/fiona/collection.py @@ -3,6 +3,7 @@ import os +import warnings from fiona import compat from fiona.ogrext import Iterator, ItemsIterator, KeysIterator @@ -311,6 +312,9 @@ class Collection(object): def __next__(self): """Returns next record from iterator.""" + warnings.warn("Collection.__next__() is buggy and will be removed in " + "Fiona 2.0. Switch to `next(iter(collection))`.", + DeprecationWarning, stacklevel=2) if not self.iterator: iter(self) return next(self.iterator) @@ -418,11 +422,21 @@ class Collection(object): self.__exit__(None, None, None) +def get_filetype(bytesbuf): + """Detect compression type of bytesbuf. + + ZIP only. TODO: add others relevant to GDAL/OGR.""" + if bytesbuf[:4].startswith(b'PK\x03\x04'): + return 'zip' + else: + return '' + + class BytesCollection(Collection): """BytesCollection takes a buffer of bytes and maps that to a virtual file that can then be opened by fiona. """ - def __init__(self, bytesbuf): + def __init__(self, bytesbuf, **kwds): """Takes buffer of bytes whose contents is something we'd like to open with Fiona and maps it to a virtual file. """ @@ -433,11 +447,15 @@ class BytesCollection(Collection): # it is garbage collected while in use. self.bytesbuf = bytesbuf - # Map the buffer to a file. - self.virtual_file = buffer_to_virtual_file(self.bytesbuf) + # Map the buffer to a file. If the buffer contains a zipfile we + # take extra steps in naming the buffer and in opening it. + filetype = get_filetype(self.bytesbuf) + ext = '.zip' if filetype == 'zip' else '' + self.virtual_file = buffer_to_virtual_file(self.bytesbuf, ext=ext) # Instantiate the parent class. - super(BytesCollection, self).__init__(self.virtual_file) + super(BytesCollection, self).__init__(self.virtual_file, vsi=filetype, + **kwds) def close(self): """Removes the virtual file associated with the class.""" @@ -460,9 +478,10 @@ def vsi_path(path, vsi=None, archive=None): # an OGR VSI path (see cpl_vsi.h). if vsi: if archive: - result = "/vsi%s/%s%s" % (vsi, archive, path) + result = '/'.join([ + '/vsi{}'.format(vsi), archive.strip('/'), path.strip('/')]) else: - result = "/vsi%s/%s" % (vsi, path) + result = '/'.join(['/vsi{}'.format(vsi), path.strip('/')]) else: result = path return result diff --git a/fiona/ogrext1.pyx b/fiona/ogrext1.pyx index 90fcd3b..442c3db 100644 --- a/fiona/ogrext1.pyx +++ b/fiona/ogrext1.pyx @@ -1246,10 +1246,12 @@ def _listlayers(path): return layer_names -def buffer_to_virtual_file(bytesbuf): +def buffer_to_virtual_file(bytesbuf, ext=''): """Maps a bytes buffer to a virtual file. + + `ext` is empty or begins with a period and contains at most one period. """ - vsi_filename = os.path.join('/vsimem', uuid.uuid4().hex) + vsi_filename = os.path.join('/vsimem', uuid.uuid4().hex + ext) vsi_cfilename = vsi_filename if not isinstance(vsi_filename, string_types) else vsi_filename.encode('utf-8') vsi_handle = ogrext1.VSIFileFromMemBuffer(vsi_cfilename, bytesbuf, len(bytesbuf), 0) @@ -1263,5 +1265,3 @@ def buffer_to_virtual_file(bytesbuf): def remove_virtual_file(vsi_filename): vsi_cfilename = vsi_filename if not isinstance(vsi_filename, string_types) else vsi_filename.encode('utf-8') return ogrext1.VSIUnlink(vsi_cfilename) - - diff --git a/fiona/ogrext2.pyx b/fiona/ogrext2.pyx index ff0db11..a367d93 100644 --- a/fiona/ogrext2.pyx +++ b/fiona/ogrext2.pyx @@ -1315,10 +1315,12 @@ def _listlayers(path): return layer_names -def buffer_to_virtual_file(bytesbuf): +def buffer_to_virtual_file(bytesbuf, ext=''): """Maps a bytes buffer to a virtual file. + + `ext` is empty or begins with a period and contains at most one period. """ - vsi_filename = os.path.join('/vsimem', uuid.uuid4().hex) + vsi_filename = os.path.join('/vsimem', uuid.uuid4().hex + ext) vsi_cfilename = vsi_filename if not isinstance(vsi_filename, string_types) else vsi_filename.encode('utf-8') vsi_handle = ogrext2.VSIFileFromMemBuffer(vsi_cfilename, bytesbuf, len(bytesbuf), 0) @@ -1332,5 +1334,3 @@ def buffer_to_virtual_file(bytesbuf): def remove_virtual_file(vsi_filename): vsi_cfilename = vsi_filename if not isinstance(vsi_filename, string_types) else vsi_filename.encode('utf-8') return ogrext2.VSIUnlink(vsi_cfilename) - - diff --git a/tests/test_bigint.py b/tests/test_bigint.py index 35f4eaa..6a9f9a3 100644 --- a/tests/test_bigint.py +++ b/tests/test_bigint.py @@ -60,7 +60,7 @@ class TestBigInt(unittest.TestCase): with fiona.open(name) as src: if get_gdal_version_num() >= calc_gdal_version_num(2, 0, 0): - first = next(src) + first = next(iter(src)) self.assertEqual(first['properties'][fieldname], a_bigint) diff --git a/tests/test_bytescollection.py b/tests/test_bytescollection.py index 9318f61..ebce7f5 100644 --- a/tests/test_bytescollection.py +++ b/tests/test_bytescollection.py @@ -2,6 +2,7 @@ import sys import unittest +import pytest import six import fiona @@ -24,14 +25,14 @@ class ReadingTest(unittest.TestCase): strbuf = src.read() self.assertRaises(ValueError, fiona.BytesCollection, strbuf) - @unittest.skipIf(FIXME_WINDOWS, + @unittest.skipIf(FIXME_WINDOWS, reason="FIXME on Windows. Please look into why this test is not working.") def test_open_repr(self): # I'm skipping checking the name of the virtual file as it produced by uuid. self.assertTrue(repr(self.c).startswith("<open BytesCollection '/vsimem/")) self.assertTrue(repr(self.c).endswith(":OGRGeoJSON', mode 'r' at %s>" % hex(id(self.c)))) - @unittest.skipIf(FIXME_WINDOWS, + @unittest.skipIf(FIXME_WINDOWS, reason="FIXME on Windows. Please look into why this test is not working.") def test_closed_repr(self): # I'm skipping checking the name of the virtual file as it produced by uuid. @@ -56,7 +57,7 @@ class ReadingTest(unittest.TestCase): def test_mode(self): self.assertEqual(self.c.mode, 'r') - @unittest.skipIf(FIXME_WINDOWS, + @unittest.skipIf(FIXME_WINDOWS, reason="FIXME on Windows. Please look into why this test is not working.") def test_collection(self): self.assertEqual(self.c.encoding, 'utf-8') @@ -157,8 +158,8 @@ class ReadingTest(unittest.TestCase): self.assertEqual(f['properties']['STATE'], 'UT') def test_re_iter_list(self): - f = list(self.c)[0] # Run through iterator - f = list(self.c)[0] # Run through a new, reset iterator + f = list(self.c)[0] # Run through iterator + f = list(self.c)[0] # Run through a new, reset iterator self.assertEqual(f['id'], "0") self.assertEqual(f['properties']['STATE'], 'UT') @@ -216,4 +217,9 @@ class FilterReadingTest(unittest.TestCase): self.assertEqual(len(results), 26) +def test_zipped_bytes_collection(): + with open('tests/data/coutwildrnp.zip', 'rb') as src: + zip_file_bytes = src.read() + with fiona.BytesCollection(zip_file_bytes) as col: + assert col.name == 'coutwildrnp' diff --git a/tests/test_collection.py b/tests/test_collection.py index 2be8911..dc31a5a 100644 --- a/tests/test_collection.py +++ b/tests/test_collection.py @@ -17,7 +17,7 @@ FIXME_WINDOWS = sys.platform.startswith('win') WILDSHP = 'tests/data/coutwildrnp.shp' -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) TEMPDIR = tempfile.gettempdir() diff --git a/tests/test_drivers.py b/tests/test_drivers.py index 9d88aa9..63f3e28 100644 --- a/tests/test_drivers.py +++ b/tests/test_drivers.py @@ -8,7 +8,7 @@ import unittest import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) FIXME_WINDOWS = sys.platform.startswith('win') diff --git a/tests/test_feature.py b/tests/test_feature.py index afb2cb1..9bf765f 100644 --- a/tests/test_feature.py +++ b/tests/test_feature.py @@ -11,7 +11,7 @@ from fiona import collection from fiona.collection import Collection from fiona.ogrext import featureRT -#logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +#logging.basicConfig(stream=sys.stderr, level=logging.INFO) class PointRoundTripTest(unittest.TestCase): def setUp(self): diff --git a/tests/test_geojson.py b/tests/test_geojson.py index e6c26c2..60d95cd 100644 --- a/tests/test_geojson.py +++ b/tests/test_geojson.py @@ -10,7 +10,7 @@ import fiona from fiona.collection import supported_drivers from fiona.errors import FionaValueError, DriverError, SchemaError, CRSError -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) class ReadingTest(unittest.TestCase): diff --git a/tests/test_geometry.py b/tests/test_geometry.py index fba95b5..3889fad 100644 --- a/tests/test_geometry.py +++ b/tests/test_geometry.py @@ -8,7 +8,7 @@ from fiona._geometry import (GeomBuilder, geometryRT) from fiona.errors import UnsupportedGeometryTypeError -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) def geometry_wkb(wkb): diff --git a/tests/test_geopackage.py b/tests/test_geopackage.py index 3572183..0a5c88c 100644 --- a/tests/test_geopackage.py +++ b/tests/test_geopackage.py @@ -15,7 +15,7 @@ from fiona.errors import FionaValueError, DriverError, SchemaError, CRSError from fiona.ogrext import calc_gdal_version_num, get_gdal_version_num -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) class ReadingTest(unittest.TestCase): diff --git a/tests/test_layer.py b/tests/test_layer.py index c7b07af..f7e3833 100644 --- a/tests/test_layer.py +++ b/tests/test_layer.py @@ -7,7 +7,7 @@ import unittest import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) from .test_collection import ReadingTest diff --git a/tests/test_listing.py b/tests/test_listing.py index d9b29aa..65a00f0 100644 --- a/tests/test_listing.py +++ b/tests/test_listing.py @@ -9,7 +9,7 @@ import fiona.ogrext FIXME_WINDOWS = sys.platform.startswith("win") -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) def test_single_file_private(): with fiona.drivers(): diff --git a/tests/test_multiconxn.py b/tests/test_multiconxn.py index 4405014..b5e441c 100644 --- a/tests/test_multiconxn.py +++ b/tests/test_multiconxn.py @@ -8,7 +8,7 @@ import unittest import fiona from fiona.compat import OrderedDict -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) FIXME_WINDOWS = sys.platform.startswith("win") @@ -28,9 +28,9 @@ class ReadAccess(unittest.TestCase): self.assertEqual(sorted(self.c.schema.items()), sorted(c2.schema.items())) def test_meta(self): - f1 = next(self.c) + f1 = next(iter(self.c)) with fiona.open("tests/data/coutwildrnp.shp", "r", layer="coutwildrnp") as c2: - f2 = next(c2) + f2 = next(iter(c2)) self.assertEqual(f1, f2) @unittest.skipIf(FIXME_WINDOWS, @@ -68,14 +68,14 @@ class ReadWriteAccess(unittest.TestCase): def test_read(self): c2 = fiona.open(os.path.join(self.tempdir, "multi_write_test.shp"), "r") - f2 = next(c2) + f2 = next(iter(c2)) del f2['id'] self.assertEqual(self.f, f2) def test_read_after_close(self): c2 = fiona.open(os.path.join(self.tempdir, "multi_write_test.shp"), "r") self.c.close() - f2 = next(c2) + f2 = next(iter(c2)) del f2['id'] self.assertEqual(self.f, f2) @@ -117,13 +117,13 @@ class LayerCreation(unittest.TestCase): def test_read(self): c2 = fiona.open(os.path.join(self.dir, "write_test.shp"), "r") - f2 = next(c2) + f2 = next(iter(c2)) del f2['id'] self.assertEqual(self.f, f2) def test_read_after_close(self): c2 = fiona.open(os.path.join(self.dir, "write_test.shp"), "r") self.c.close() - f2 = next(c2) + f2 = next(iter(c2)) del f2['id'] self.assertEqual(self.f, f2) diff --git a/tests/test_props.py b/tests/test_props.py index 7bcefcc..a55d665 100644 --- a/tests/test_props.py +++ b/tests/test_props.py @@ -80,7 +80,7 @@ def test_read_json_object_properties(): f.write(data) with fiona.open(filename) as src: - ftr = next(src) + ftr = next(iter(src)) props = ftr['properties'] assert props['upperLeftCoordinate']['latitude'] == 45.66894 assert props['upperLeftCoordinate']['longitude'] == 87.91166 @@ -146,7 +146,7 @@ def test_write_json_object_properties(): dst.write(data) with fiona.open(filename) as src: - ftr = next(src) + ftr = next(iter(src)) props = ftr['properties'] assert props['upperLeftCoordinate']['latitude'] == 45.66894 assert props['upperLeftCoordinate']['longitude'] == 87.91166 @@ -187,7 +187,7 @@ def test_json_prop_decode_non_geojson_driver(): dst.write(feature) with fiona.open(filename) as src: - actual = next(src) + actual = next(iter(src)) assert isinstance(actual['properties']['ulc'], text_type) a = json.loads(actual['properties']['ulc']) diff --git a/tests/test_read_drivers.py b/tests/test_read_drivers.py index fd42a92..9989041 100644 --- a/tests/test_read_drivers.py +++ b/tests/test_read_drivers.py @@ -7,7 +7,7 @@ import fiona from fiona.errors import FionaValueError -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) def test_read_fail(): with pytest.raises(FionaValueError): diff --git a/tests/test_remove.py b/tests/test_remove.py index f665ed3..654b6b4 100644 --- a/tests/test_remove.py +++ b/tests/test_remove.py @@ -8,7 +8,7 @@ import pytest import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) def create_sample_data(filename, driver): diff --git a/tests/test_revolvingdoor.py b/tests/test_revolvingdoor.py index ba402e0..abff6e0 100644 --- a/tests/test_revolvingdoor.py +++ b/tests/test_revolvingdoor.py @@ -10,7 +10,7 @@ import unittest import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) log = logging.getLogger('fiona.tests') class RevolvingDoorTest(unittest.TestCase): diff --git a/tests/test_rfc3339.py b/tests/test_rfc3339.py index 131eca6..ac981b0 100644 --- a/tests/test_rfc3339.py +++ b/tests/test_rfc3339.py @@ -8,7 +8,7 @@ import unittest from fiona.rfc3339 import parse_date, parse_datetime, parse_time from fiona.rfc3339 import group_accessor, pattern_date -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) class DateParseTest(unittest.TestCase): diff --git a/tests/test_schema.py b/tests/test_schema.py index f8e90e3..61c5459 100644 --- a/tests/test_schema.py +++ b/tests/test_schema.py @@ -124,7 +124,7 @@ class ShapefileSchema(unittest.TestCase): ('INTPTLON10', 'str:80'), ('GEOID10', 'str:80'), ('Decommisio', 'str:80')]) ) - f = next(c) + f = next(iter(c)) self.assertEqual(f['properties']['EstimatedP'], 27773.0) @@ -153,7 +153,7 @@ class FieldTruncationTestCase(unittest.TestCase): dst.write(rec) with fiona.open(name) as src: - first = next(src) + first = next(iter(src)) assert first['geometry'] == {'type': 'Point', 'coordinates': (0, 0)} assert first['properties']['a_fieldnam'] == 3.0 diff --git a/tests/test_slice.py b/tests/test_slice.py index 57e0394..1b0d2d3 100644 --- a/tests/test_slice.py +++ b/tests/test_slice.py @@ -3,7 +3,7 @@ import sys import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) def test_collection_get(): with fiona.open('tests/data/coutwildrnp.shp') as src: diff --git a/tests/test_unicode.py b/tests/test_unicode.py index 70e7a1c..98aa374 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -13,7 +13,7 @@ import six import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) FIXME_WINDOWS = sys.platform.startswith('win') @@ -88,7 +88,7 @@ class UnicodeStringFieldTest(unittest.TestCase): 'num': 0}}]) with fiona.open(os.path.join(self.tempdir), encoding='latin1') as c: - f = next(c) + f = next(iter(c)) # Next assert fails. self.assertEqual(f['properties']['label'], u'徐汇区') @@ -106,7 +106,7 @@ class UnicodeStringFieldTest(unittest.TestCase): 'label': u'Ba\u2019kelalan', u'verit\xe9': 0}}]) with fiona.open(os.path.join(self.tempdir), encoding='utf-8') as c: - f = next(c) + f = next(iter(c)) self.assertEqual(f['properties']['label'], u'Ba\u2019kelalan') self.assertEqual(f['properties'][u'verit\xe9'], 0) @@ -124,6 +124,6 @@ class UnicodeStringFieldTest(unittest.TestCase): 'properties': {'label': u'徐汇区', 'num': 0}}]) with fiona.open(os.path.join(self.tempdir), encoding='gb18030') as c: - f = next(c) + f = next(iter(c)) self.assertEqual(f['properties']['label'], u'徐汇区') self.assertEqual(f['properties']['num'], 0) diff --git a/tests/test_vfs.py b/tests/test_vfs.py index ce33980..b5c2d61 100644 --- a/tests/test_vfs.py +++ b/tests/test_vfs.py @@ -6,7 +6,7 @@ import unittest import fiona -logging.basicConfig(stream=sys.stderr, level=logging.DEBUG) +logging.basicConfig(stream=sys.stderr, level=logging.INFO) from .test_collection import ReadingTest -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/fiona.git _______________________________________________ Pkg-grass-devel mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

