本文整理匯總了Python中nt._getfinalpathname方法的典型用法代碼示例。如果您正苦於以下問題:Python nt._getfinalpathname方法的具體用法?Python nt._getfinalpathname怎麽用?Python nt._getfinalpathname使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類nt
的用法示例。
在下文中一共展示了nt._getfinalpathname方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: resolve
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def resolve(self, path, strict=False):
s = str(path)
if not s:
return os.getcwd()
previous_s = None
if _getfinalpathname is not None:
if strict:
return self._ext_to_normal(_getfinalpathname(s))
else:
tail_parts = [] # End of the path after the first one not found
while True:
try:
s = self._ext_to_normal(_getfinalpathname(s))
except FileNotFoundError:
previous_s = s
s, tail = os.path.split(s)
tail_parts.append(tail)
if previous_s == s:
return path
else:
return os.path.join(s, *reversed(tail_parts))
# Means fallback on absolute
return None
示例2: resolve
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def resolve(self, path, strict=False):
s = str(path)
if not s:
return os.getcwd()
previous_s = None
if _getfinalpathname is not None:
if strict:
return self._ext_to_normal(_getfinalpathname(s))
else:
# End of the path after the first one not found
tail_parts = []
while True:
try:
s = self._ext_to_normal(_getfinalpathname(s))
except FileNotFoundError:
previous_s = s
s, tail = os.path.split(s)
tail_parts.append(tail)
if previous_s == s:
return path
else:
return os.path.join(s, *reversed(tail_parts))
# Means fallback on absolute
return None
示例3: resolve
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def resolve(self, path, strict=False):
s = str(path)
if not s:
return os.getcwd()
previous_s = None
if _getfinalpathname is not None:
if strict:
return self._ext_to_normal(_getfinalpathname(s))
else:
# End of the path after the first one not found
tail_parts = []
def _try_func():
result[0] = self._ext_to_normal(_getfinalpathname(s))
# if there was no exception, set flag to 0
result[1] = 0
def _exc_func(exc):
pass
while True:
result = [None, 1]
_try_except_filenotfounderror(_try_func, _exc_func)
if result[1] == 1: # file not found exception raised
previous_s = s
s, tail = os.path.split(s)
tail_parts.append(tail)
if previous_s == s:
return path
else:
s = result[0]
return os.path.join(s, *reversed(tail_parts))
# Means fallback on absolute
return None
示例4: _getfinalpathname
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def _getfinalpathname(f):
return normcase(abspath(f))
示例5: resolve
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def resolve(self, path):
s = str(path)
if not s:
return os.getcwd()
if _getfinalpathname is not None:
return self._ext_to_normal(_getfinalpathname(s))
# Means fallback on absolute
return None
示例6: test_nt_helpers
# 需要導入模塊: import nt [as 別名]
# 或者: from nt import _getfinalpathname [as 別名]
def test_nt_helpers(self):
# Trivial validation that the helpers do not break, and support both
# unicode and bytes (UTF-8) paths
drive, path = ntpath.splitdrive(sys.executable)
drive = drive.rstrip(ntpath.sep) + ntpath.sep
self.assertEqual(drive, nt._getvolumepathname(sys.executable))
self.assertEqual(drive.encode(),
nt._getvolumepathname(sys.executable.encode()))
cap, free = nt._getdiskusage(sys.exec_prefix)
self.assertGreater(cap, 0)
self.assertGreater(free, 0)
b_cap, b_free = nt._getdiskusage(sys.exec_prefix.encode())
# Free space may change, so only test the capacity is equal
self.assertEqual(b_cap, cap)
self.assertGreater(b_free, 0)
for path in [sys.prefix, sys.executable]:
final_path = nt._getfinalpathname(path)
self.assertIsInstance(final_path, str)
self.assertGreater(len(final_path), 0)
b_final_path = nt._getfinalpathname(path.encode())
self.assertIsInstance(b_final_path, bytes)
self.assertGreater(len(b_final_path), 0)