[fiona] 01/06: Imported Upstream version 1.6.3

Sebastiaan Couwenberg sebastic at moszumanska.debian.org
Fri Dec 25 01:47:36 UTC 2015


This is an automated email from the git hooks/post-receive script.

sebastic pushed a commit to branch master
in repository fiona.

commit 774de739ec84610a72461fc0af0ff90439fae6b5
Author: Bas Couwenberg <sebastic at xs4all.nl>
Date:   Fri Dec 25 01:56:37 2015 +0100

    Imported Upstream version 1.6.3
---
 CHANGES.txt           |  9 +++++++++
 fiona/__init__.py     |  2 +-
 fiona/errors.py       | 21 ++++++++++++++++++++-
 fiona/ogrext.pyx      | 40 +++++++++++++++++++++++++---------------
 tests/test_unicode.py | 28 ++++++++++++++++++++++++++++
 5 files changed, 83 insertions(+), 17 deletions(-)

diff --git a/CHANGES.txt b/CHANGES.txt
index 64e8d90..ed42d05 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -3,6 +3,15 @@ Changes
 
 All issue numbers are relative to https://github.com/Toblerity/Fiona/issues.
 
+1.6.3 (2015-09-22)
+------------------
+- Daytime has been decreasing in the Northern Hemisphere, but is now
+  increasing again as it should.
+- Non-UTF strings were being passed into OGR functions in some situations
+  and on Windows this would sometimes crash a Python process (#303). Fiona
+  now raises errors derived from UnicodeError when field names or field
+  values can't be encoded.
+
 1.6.2 (2015-09-22)
 ------------------
 - Providing only PROJ4 representations in the dataset meta property resulted in
diff --git a/fiona/__init__.py b/fiona/__init__.py
index ac0592c..6277ab8 100644
--- a/fiona/__init__.py
+++ b/fiona/__init__.py
@@ -63,7 +63,7 @@ writing modes) flush contents to disk when their ``with`` blocks end.
 """
 
 __all__ = ['bounds', 'listlayers', 'open', 'prop_type', 'prop_width']
-__version__ = "1.6.2"
+__version__ = "1.6.3"
 
 import logging
 import os
diff --git a/fiona/errors.py b/fiona/errors.py
index ac48847..ed520d0 100644
--- a/fiona/errors.py
+++ b/fiona/errors.py
@@ -1,14 +1,33 @@
+# Errors.
+
+
 class FionaValueError(ValueError):
     """Fiona-specific value errors"""
 
+
 class DriverError(FionaValueError):
     """Encapsulates unsupported driver and driver mode errors."""
 
+
 class SchemaError(FionaValueError):
     """When a schema mapping has no properties or no geometry."""
 
+
 class CRSError(FionaValueError):
     """When a crs mapping has neither init or proj items."""
 
+
 class DataIOError(IOError):
-    """IO errors involving driver registration or availability"""
+    """IO errors involving driver registration or availability."""
+
+
+class FieldNameEncodeError(UnicodeEncodeError):
+    """Failure to encode a field name."""
+
+
+class StringFieldEncodeError(UnicodeEncodeError):
+    """Failure to encode a string field value."""
+
+
+class StringFieldDecodeError(UnicodeDecodeError):
+    """Failure to decode a string field value."""
diff --git a/fiona/ogrext.pyx b/fiona/ogrext.pyx
index 85b9b02..9773ebd 100644
--- a/fiona/ogrext.pyx
+++ b/fiona/ogrext.pyx
@@ -16,7 +16,9 @@ from fiona cimport ograpi
 from fiona._geometry cimport GeomBuilder, OGRGeomBuilder
 from fiona._err import cpl_errs
 from fiona._geometry import GEOMETRY_TYPES
-from fiona.errors import DriverError, SchemaError, CRSError, FionaValueError
+from fiona.errors import (
+    DriverError, SchemaError, CRSError, FionaValueError, FieldNameEncodeError,
+    StringFieldEncodeError, StringFieldDecodeError)
 from fiona.odict import OrderedDict
 from fiona.rfc3339 import parse_date, parse_datetime, parse_time
 from fiona.rfc3339 import FionaDateType, FionaDateTimeType, FionaTimeType
@@ -180,9 +182,10 @@ cdef class FeatureBuilder:
                 try:
                     val = ograpi.OGR_F_GetFieldAsString(feature, i)
                     val = val.decode(encoding)
-                except UnicodeDecodeError:
-                    log.warn(
-                        "Failed to decode %s using %s codec", val, encoding)
+                except UnicodeError as exc:
+                    raise StringFieldDecodeError(
+                        "Failed to decode {0} using {1} codec: {2}".format(
+                            val, encoding, str(exc)))
 
                 # Does the text contain a JSON object? Let's check.
                 # Let's check as cheaply as we can.
@@ -258,11 +261,15 @@ cdef class OGRFeatureBuilder:
                 "Looking up %s in %s", key, repr(session._schema_mapping))
             ogr_key = session._schema_mapping[key]
             schema_type = collection.schema['properties'][key]
+
+            # Catch and re-raise unicode encoding errors.
             try:
                 key_bytes = ogr_key.encode(encoding)
-            except UnicodeDecodeError:
-                log.warn("Failed to encode %s using %s codec", key, encoding)
-                key_bytes = ogr_key
+            except UnicodeError as exc:
+                raise FieldNameEncodeError(
+                    "Failed to encode {0} using {1} codec: {2}".format(
+                        key, encoding, str(exc)))
+
             key_c = key_bytes
             i = ograpi.OGR_F_GetFieldIndex(cogr_feature, key_c)
             if i < 0:
@@ -304,12 +311,15 @@ cdef class OGRFeatureBuilder:
                 ograpi.OGR_F_SetFieldDateTime(
                     cogr_feature, i, 0, 0, 0, hh, mm, ss, 0)
             elif isinstance(value, string_types):
+                
+                # Catch and re-raise string field value encoding errors.
                 try:
                     value_bytes = value.encode(encoding)
-                except UnicodeDecodeError:
-                    log.warn(
-                        "Failed to encode %s using %s codec", value, encoding)
-                    value_bytes = value
+                except UnicodeError as exc:
+                    raise StringFieldEncodeError(
+                        "Failed to encode {0} using {1} codec: {2}".format(
+                            value, encoding, str(exc)))
+
                 string_c = value_bytes
                 ograpi.OGR_F_SetFieldString(cogr_feature, i, string_c)
             elif value is None:
@@ -376,7 +386,7 @@ cdef class Session:
             path = collection.path
         try:
             path_b = path.encode('utf-8')
-        except UnicodeDecodeError:
+        except UnicodeError:
             # Presume already a UTF-8 encoded string
             path_b = path
         path_c = path_b
@@ -699,7 +709,7 @@ cdef class WritingSession(Session):
             if os.path.exists(path):
                 try:
                     path_b = path.encode('utf-8')
-                except UnicodeDecodeError:
+                except UnicodeError:
                     path_b = path
                 path_c = path_b
                 with cpl_errs:
@@ -735,7 +745,7 @@ cdef class WritingSession(Session):
         elif collection.mode == 'w':
             try:
                 path_b = path.encode('utf-8')
-            except UnicodeDecodeError:
+            except UnicodeError:
                 path_b = path
             path_c = path_b
             driver_b = collection.driver.encode()
@@ -1188,7 +1198,7 @@ def _listlayers(path):
     # Open OGR data source.
     try:
         path_b = path.encode('utf-8')
-    except UnicodeDecodeError:
+    except UnicodeError:
         path_b = path
     path_c = path_b
     with cpl_errs:
diff --git a/tests/test_unicode.py b/tests/test_unicode.py
index 5e94876..6696567 100644
--- a/tests/test_unicode.py
+++ b/tests/test_unicode.py
@@ -13,6 +13,7 @@ import fiona
 
 logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
 
+
 class UnicodePathTest(unittest.TestCase):
 
     def setUp(self):
@@ -44,3 +45,30 @@ class UnicodePathTest(unittest.TestCase):
         if sys.version_info < (3,):
             with fiona.open(path) as c:
                 assert len(c) == 67
+
+
+class UnicodeStringFieldTest(unittest.TestCase):
+
+    def setUp(self):
+        self.tempdir = tempfile.mkdtemp()
+
+    def tearDown(self):
+        shutil.rmtree(self.tempdir)
+
+    def test_write(self):
+        schema = {
+            'geometry': 'Point',
+            'properties': {'label': 'str', u'verit\xe9': 'int'}}
+        with fiona.open(os.path.join(self.tempdir, "test-write.shp"),
+                        "w", "ESRI Shapefile", schema=schema,
+                        encoding='utf-8') as c:
+            c.writerecords([
+                {'type': 'Feature', 'geometry': {'type': 'Point',
+                                                 'coordinates': [0, 0]},
+                                    'properties': {'label': u'Ba\u2019kelalan',
+                                                   u'verit\xe9': 0}}])
+
+        with fiona.open(os.path.join(self.tempdir)) as c:
+            f = next(c)
+            self.assertEquals(f['properties']['label'], u'Ba\u2019kelalan')
+            self.assertEquals(f['properties'][u'verit\xe9'], 0)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/fiona.git



More information about the Pkg-grass-devel mailing list