MCPcopy Create free account
hub / github.com/twisted/twisted / _asFilesystemText

Function _asFilesystemText

src/twisted/python/filepath.py:713–731  ·  view source on GitHub ↗

Return C{path} as a string of L{unicode} suitable for use on this system's filesystem. @param path: The path to be made suitable. @type path: L{bytes} or L{unicode} @param encoding: The encoding to use if coercing to L{unicode}. If none is given, L{sys.getfilesystemenc

(path: bytes | str, encoding: str | None = None)

Source from the content-addressed store, hash-verified

711
712
713def _asFilesystemText(path: bytes | str, encoding: str | None = None) -> str:
714 """
715 Return C{path} as a string of L{unicode} suitable for use on this system's
716 filesystem.
717
718 @param path: The path to be made suitable.
719 @type path: L{bytes} or L{unicode}
720
721 @param encoding: The encoding to use if coercing to L{unicode}. If none
722 is given, L{sys.getfilesystemencoding} is used.
723
724 @return: L{unicode}
725 """
726 if isinstance(path, str):
727 return path
728 else:
729 if encoding is None:
730 encoding = sys.getfilesystemencoding()
731 return path.decode(encoding, errors="surrogateescape")
732
733
734def _coerceToFilesystemEncoding(

Callers 2

_asTextPathMethod · 0.85

Calls 2

getfilesystemencodingMethod · 0.80
decodeMethod · 0.45

Tested by

no test coverage detected