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