This is an automated email from the git hooks/post-receive script. sebastic pushed a commit to branch master in repository pyshp.
commit d004ac68b0134ec3a83607cff59d284066ca189f Author: Bas Couwenberg <[email protected]> Date: Thu Aug 24 22:57:23 2017 +0200 New upstream version 1.2.12+ds --- PKG-INFO | 2 +- changelog.txt | 6 ++++++ setup.cfg | 4 ++-- setup.py | 2 +- shapefile.py | 49 ++++++++++++++++++++++++++++++++++++-------- shapefiles/test/dtype.dbf | Bin 77 -> 77 bytes shapefiles/test/line.dbf | Bin 2122 -> 2122 bytes shapefiles/test/point.dbf | Bin 299 -> 299 bytes shapefiles/test/polygon.dbf | Bin 198 -> 198 bytes 9 files changed, 50 insertions(+), 13 deletions(-) diff --git a/PKG-INFO b/PKG-INFO index 66dc8fc..85f9094 100644 --- a/PKG-INFO +++ b/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 1.1 Name: pyshp -Version: 1.2.11 +Version: 1.2.12 Summary: Pure Python read/write support for ESRI Shapefile format Home-page: https://github.com/GeospatialPython/pyshp Author: Joel Lawhead diff --git a/changelog.txt b/changelog.txt index 9ff0a00..f7785ee 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +VERSION 1.2.12 + +2017-08-24 Karim Bahgat <[email protected]> + * Fixed errors caused by strict value type checking, as introduced in v1.2.11. Now more lenient by attempting force conversion of values to match the field type. + * Allow reading file-like objects without seek method (such as ZipFile or urllib.urlopen). + VERSION 1.2.11 2017-04-29 Karim Bahgat <[email protected]> diff --git a/setup.cfg b/setup.cfg index 861a9f5..72f9d44 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,5 +1,5 @@ [egg_info] -tag_build = -tag_date = 0 tag_svn_revision = 0 +tag_date = 0 +tag_build = diff --git a/setup.py b/setup.py index 9acd4f7..09a667b 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ from setuptools import setup setup(name='pyshp', - version='1.2.11', + version='1.2.12', description='Pure Python read/write support for ESRI Shapefile format', long_description=open('README.md').read(), author='Joel Lawhead', diff --git a/shapefile.py b/shapefile.py index c3eb89e..dbf846a 100644 --- a/shapefile.py +++ b/shapefile.py @@ -2,12 +2,12 @@ shapefile.py Provides read and write support for ESRI Shapefiles. author: jlawhead<at>geospatialpython.com -date: 2017/04/29 -version: 1.2.11 +date: 2017/08/24 +version: 1.2.12 Compatible with Python versions 2.7-3.x """ -__version__ = "1.2.11" +__version__ = "1.2.12" from struct import pack, unpack, calcsize, error, Struct import os @@ -16,6 +16,7 @@ import time import array import tempfile import itertools +import io from datetime import date # @@ -238,23 +239,35 @@ class Reader: if "shp" in kwargs.keys(): if hasattr(kwargs["shp"], "read"): self.shp = kwargs["shp"] - if hasattr(self.shp, "seek"): + # Copy if required + try: self.shp.seek(0) + except (NameError, io.UnsupportedOperation): + self.shp = io.BytesIO(self.shp.read()) if "shx" in kwargs.keys(): if hasattr(kwargs["shx"], "read"): self.shx = kwargs["shx"] - if hasattr(self.shx, "seek"): + # Copy if required + try: self.shx.seek(0) + except (NameError, io.UnsupportedOperation): + self.shx = io.BytesIO(self.shx.read()) if "dbf" in kwargs.keys(): if hasattr(kwargs["dbf"], "read"): self.dbf = kwargs["dbf"] - if hasattr(self.dbf, "seek"): + # Copy if required + try: self.dbf.seek(0) + except (NameError, io.UnsupportedOperation): + self.dbf = io.BytesIO(self.dbf.read()) if self.shp or self.dbf: self.load() else: raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.") + + + def load(self, shapefile=None): """Opens a shapefile from a filename or file-like object. Normally this method would be called by the @@ -509,11 +522,19 @@ class Reader: #not parseable as float, set to None value = None else: + # force to int try: - value = int(value) + # first try to force directly to int. + # forcing a large int to float and back to int + # will lose information and result in wrong nr. + value = int(value) except ValueError: - #not parseable as int, set to None - value = None + # forcing directly to int failed, so was probably a float. + try: + value = int(float(value)) + except ValueError: + #not parseable as int, set to None + value = None elif typ == 'D': # date: 8 bytes - date stored as a string in the format YYYYMMDD. if value.count(b('0')) == len(value): # QGIS NULL is all '0' chars @@ -932,8 +953,18 @@ class Writer: if value in MISSING: value = str("*"*size) # QGIS NULL elif not deci: + # force to int + try: + # first try to force directly to int. + # forcing a large int to float and back to int + # will lose information and result in wrong nr. + value = int(value) + except ValueError: + # forcing directly to int failed, so was probably a float. + value = int(float(value)) value = format(value, "d")[:size].rjust(size) # caps the size if exceeds the field size else: + value = float(value) value = format(value, ".%sf"%deci)[:size].rjust(size) # caps the size if exceeds the field size elif fieldType == "D": # date: 8 bytes - date stored as a string in the format YYYYMMDD. diff --git a/shapefiles/test/dtype.dbf b/shapefiles/test/dtype.dbf index 8226836..e3e9e9f 100644 Binary files a/shapefiles/test/dtype.dbf and b/shapefiles/test/dtype.dbf differ diff --git a/shapefiles/test/line.dbf b/shapefiles/test/line.dbf index 72ac67f..27b0618 100644 Binary files a/shapefiles/test/line.dbf and b/shapefiles/test/line.dbf differ diff --git a/shapefiles/test/point.dbf b/shapefiles/test/point.dbf index c77d097..726e40d 100644 Binary files a/shapefiles/test/point.dbf and b/shapefiles/test/point.dbf differ diff --git a/shapefiles/test/polygon.dbf b/shapefiles/test/polygon.dbf index 184088d..c1ed498 100644 Binary files a/shapefiles/test/polygon.dbf and b/shapefiles/test/polygon.dbf differ -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-grass/pyshp.git _______________________________________________ Pkg-grass-devel mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-grass-devel

