@@ -930,14 +930,19 @@ def __init__(self, *args, **kwargs):
930
930
self .encodingErrors = kwargs .pop ('encodingErrors' , 'strict' )
931
931
# See if a shapefile name was passed as the first argument
932
932
if len (args ) > 0 :
933
- if is_string (args [0 ]):
934
- path = args [0 ]
935
-
933
+ path = args [0 ]
934
+ try :
935
+ # Convert path-like objects to str
936
+ path = os .fsdecode (path )
937
+ except (AttributeError , TypeError ):
938
+ pass
939
+ if is_string (path ):
940
+
936
941
if '.zip' in path :
937
942
# Shapefile is inside a zipfile
938
943
if path .count ('.zip' ) > 1 :
939
944
# Multiple nested zipfiles
940
- raise ShapefileException ('Reading from multiple nested zipfiles is not supported: %s' % args [ 0 ] )
945
+ raise ShapefileException ('Reading from multiple nested zipfiles is not supported: %s' % path )
941
946
# Split into zipfile and shapefile paths
942
947
if path .endswith ('.zip' ):
943
948
zpath = path
@@ -1708,8 +1713,13 @@ def __init__(self, target=None, shapeType=None, autoBalance=False, **kwargs):
1708
1713
self .shapeType = shapeType
1709
1714
self .shp = self .shx = self .dbf = None
1710
1715
if target :
1716
+ try :
1717
+ # Convert path-like objects to str
1718
+ target = os .fsdecode (target )
1719
+ except (AttributeError , TypeError ):
1720
+ pass
1711
1721
if not is_string (target ):
1712
- raise Exception ('The target filepath {} must be of type str/unicode, not {}.' .format (repr (target ), type (target )) )
1722
+ raise Exception ('The target filepath {} must be of type str/unicode or path-like , not {}.' .format (repr (target ), type (target )) )
1713
1723
self .shp = self .__getFileObj (os .path .splitext (target )[0 ] + '.shp' )
1714
1724
self .shx = self .__getFileObj (os .path .splitext (target )[0 ] + '.shx' )
1715
1725
self .dbf = self .__getFileObj (os .path .splitext (target )[0 ] + '.dbf' )
0 commit comments