Skip to content

Fix file like objects without seek support not being readable (without allow_copy) #96

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions shapefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import array
import tempfile
import itertools
import io
from datetime import date

#
Expand Down Expand Up @@ -238,23 +239,35 @@ def __init__(self, *args, **kwargs):
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
Expand Down