|
16 | 16 | import array
|
17 | 17 | import tempfile
|
18 | 18 | import itertools
|
| 19 | +import io |
19 | 20 | from datetime import date
|
20 | 21 |
|
21 | 22 | #
|
@@ -238,23 +239,35 @@ def __init__(self, *args, **kwargs):
|
238 | 239 | if "shp" in kwargs.keys():
|
239 | 240 | if hasattr(kwargs["shp"], "read"):
|
240 | 241 | self.shp = kwargs["shp"]
|
241 |
| - if hasattr(self.shp, "seek"): |
| 242 | + # Copy if required |
| 243 | + try: |
242 | 244 | self.shp.seek(0)
|
| 245 | + except (NameError, io.UnsupportedOperation): |
| 246 | + self.shp = io.BytesIO(self.shp.read()) |
243 | 247 | if "shx" in kwargs.keys():
|
244 | 248 | if hasattr(kwargs["shx"], "read"):
|
245 | 249 | self.shx = kwargs["shx"]
|
246 |
| - if hasattr(self.shx, "seek"): |
| 250 | + # Copy if required |
| 251 | + try: |
247 | 252 | self.shx.seek(0)
|
| 253 | + except (NameError, io.UnsupportedOperation): |
| 254 | + self.shx = io.BytesIO(self.shx.read()) |
248 | 255 | if "dbf" in kwargs.keys():
|
249 | 256 | if hasattr(kwargs["dbf"], "read"):
|
250 | 257 | self.dbf = kwargs["dbf"]
|
251 |
| - if hasattr(self.dbf, "seek"): |
| 258 | + # Copy if required |
| 259 | + try: |
252 | 260 | self.dbf.seek(0)
|
| 261 | + except (NameError, io.UnsupportedOperation): |
| 262 | + self.dbf = io.BytesIO(self.dbf.read()) |
253 | 263 | if self.shp or self.dbf:
|
254 | 264 | self.load()
|
255 | 265 | else:
|
256 | 266 | raise ShapefileException("Shapefile Reader requires a shapefile or file-like object.")
|
257 | 267 |
|
| 268 | + |
| 269 | + |
| 270 | + |
258 | 271 | def load(self, shapefile=None):
|
259 | 272 | """Opens a shapefile from a filename or file-like
|
260 | 273 | object. Normally this method would be called by the
|
|
0 commit comments