MCPcopy Create free account
hub / github.com/ahupp/python-magic / coerce_filename

Function coerce_filename

magic/__init__.py:253–271  ·  view source on GitHub ↗
(filename)

Source from the content-addressed store, hash-verified

251 return filename
252
253def coerce_filename(filename):
254 if filename is None:
255 return None
256
257 filename = unpath(filename)
258
259 # ctypes will implicitly convert unicode strings to bytes with
260 # .encode('ascii'). If you use the filesystem encoding
261 # then you'll get inconsistent behavior (crashes) depending on the user's
262 # LANG environment variable
263 # NEXTBREAK: remove
264 is_unicode = (sys.version_info[0] <= 2 and
265 isinstance(filename, unicode)) or \
266 (sys.version_info[0] >= 3 and
267 isinstance(filename, str))
268 if is_unicode:
269 return filename.encode('utf-8', 'surrogateescape')
270 else:
271 return filename
272
273
274magic_open = libmagic.magic_open

Callers 2

magic_fileFunction · 0.85
magic_loadFunction · 0.85

Calls 1

unpathFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…