(filename)
| 251 | return filename |
| 252 | |
| 253 | def 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 | |
| 274 | magic_open = libmagic.magic_open |
no test coverage detected
searching dependent graphs…