From c33ef84efd7fc09736f06e44f5f88689e45177ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Wed, 22 Feb 2017 21:19:53 +0100 Subject: [PATCH 1/2] Fix seek being called on file-likes throwing UnsupportedOperationException() --- shapefile.py | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/shapefile.py b/shapefile.py index 5bdd50c..71d6ed3 100644 --- a/shapefile.py +++ b/shapefile.py @@ -240,17 +240,26 @@ def __init__(self, *args, **kwargs): if hasattr(kwargs["shp"], "read"): self.shp = kwargs["shp"] if hasattr(self.shp, "seek"): - self.shp.seek(0) + try: + self.shp.seek(0) + except UnsupportedOperationException: + pass if "shx" in kwargs.keys(): if hasattr(kwargs["shx"], "read"): self.shx = kwargs["shx"] if hasattr(self.shx, "seek"): - self.shx.seek(0) + try: + self.shp.seek(0) + except UnsupportedOperationException: + pass if "dbf" in kwargs.keys(): if hasattr(kwargs["dbf"], "read"): self.dbf = kwargs["dbf"] if hasattr(self.dbf, "seek"): - self.dbf.seek(0) + try: + self.shp.seek(0) + except UnsupportedOperationException: + pass if self.shp or self.dbf: self.load() else: From 7faede42765bd630f2c41405911b932dd6e929b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uli=20K=C3=B6hler?= Date: Wed, 22 Feb 2017 21:32:28 +0100 Subject: [PATCH 2/2] Fix seek being called on the wrong files --- shapefile.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shapefile.py b/shapefile.py index 71d6ed3..8a93898 100644 --- a/shapefile.py +++ b/shapefile.py @@ -249,7 +249,7 @@ def __init__(self, *args, **kwargs): self.shx = kwargs["shx"] if hasattr(self.shx, "seek"): try: - self.shp.seek(0) + self.shx.seek(0) except UnsupportedOperationException: pass if "dbf" in kwargs.keys(): @@ -257,7 +257,7 @@ def __init__(self, *args, **kwargs): self.dbf = kwargs["dbf"] if hasattr(self.dbf, "seek"): try: - self.shp.seek(0) + self.dbf.seek(0) except UnsupportedOperationException: pass if self.shp or self.dbf: