我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用os.path.decode()。
def decode_path(path): """ Ensure `path` is Unicode. Return `nodes.reprunicode` object. Decode file/path string in a failsave manner if not already done. """ # see also http://article.gmane.org/gmane.text.docutils.user/2905 if isinstance(path, unicode): return path try: path = path.decode(sys.getfilesystemencoding(), 'strict') except AttributeError: # default value None has no decode method return nodes.reprunicode(path) except UnicodeDecodeError: try: path = path.decode('utf-8', 'strict') except UnicodeDecodeError: path = path.decode('ascii', 'replace') return nodes.reprunicode(path)
def decode_path(path): """ Ensure `path` is Unicode. Return `nodes.reprunicode` object. Decode file/path string in a failsave manner if not already done. """ # see also http://article.gmane.org/gmane.text.docutils.user/2905 if isinstance(path, str): return path try: path = path.decode(sys.getfilesystemencoding(), 'strict') except AttributeError: # default value None has no decode method return nodes.reprunicode(path) except UnicodeDecodeError: try: path = path.decode('utf-8', 'strict') except UnicodeDecodeError: path = path.decode('ascii', 'replace') return nodes.reprunicode(path)