@@ -100,6 +100,7 @@ def from_buffer(self, buf):
100
100
# if we're on python3, convert buf to bytes
101
101
# otherwise this string is passed as wchar*
102
102
# which is not what libmagic expects
103
+ # NEXTBREAK: only take bytes
103
104
if type (buf ) == str and str != bytes :
104
105
buf = buf .encode ('utf-8' , errors = 'replace' )
105
106
return maybe_decode (magic_buffer (self .cookie , buf ))
@@ -229,6 +230,7 @@ def errorcheck_negative_one(result, func, args):
229
230
# return str on python3. Don't want to unconditionally
230
231
# decode because that results in unicode on python2
231
232
def maybe_decode (s ):
233
+ # NEXTBREAK: remove
232
234
if str == bytes :
233
235
return s
234
236
else :
@@ -237,13 +239,28 @@ def maybe_decode(s):
237
239
return s .decode ('utf-8' , 'backslashreplace' )
238
240
239
241
242
+ try :
243
+ from os import PathLike
244
+ def unpath (filename ):
245
+ if isinstance (filename , PathLike ):
246
+ return filename .__fspath__ ()
247
+ else :
248
+ return filename
249
+ except ImportError :
250
+ def unpath (filename ):
251
+ return filename
252
+
240
253
def coerce_filename (filename ):
241
254
if filename is None :
242
255
return None
256
+
257
+ filename = unpath (filename )
258
+
243
259
# ctypes will implicitly convert unicode strings to bytes with
244
260
# .encode('ascii'). If you use the filesystem encoding
245
261
# then you'll get inconsistent behavior (crashes) depending on the user's
246
262
# LANG environment variable
263
+ # NEXTBREAK: remove
247
264
is_unicode = (sys .version_info [0 ] <= 2 and
248
265
isinstance (filename , unicode )) or \
249
266
(sys .version_info [0 ] >= 3 and
0 commit comments