本文整理汇总了Python中ntpath.sep方法的典型用法代码示例。如果您正苦于以下问题:Python ntpath.sep方法的具体用法?Python ntpath.sep怎么用?Python ntpath.sep使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ntpath
的用法示例。
在下文中一共展示了ntpath.sep方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_windows_colon
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import sep [as 别名]
def test_windows_colon(self):
import SimpleHTTPServer
with test_support.swap_attr(SimpleHTTPServer.os, 'path', ntpath):
path = self.handler.translate_path('c:c:c:foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('\\c:../filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:\\c:..\\foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
示例2: test_windows_colon
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import sep [as 别名]
def test_windows_colon(self):
with support.swap_attr(server.os, 'path', ntpath):
path = self.handler.translate_path('c:c:c:foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('\\c:../filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:\\c:..\\foo/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
path = self.handler.translate_path('c:c:foo\\c:c:bar/filename')
path = path.replace(ntpath.sep, os.sep)
self.assertEqual(path, self.translated)
示例3: to_os_native_path
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import sep [as 别名]
def to_os_native_path(path):
"""
Normalize a path to use the native OS path separator.
"""
path = path.replace(posixpath.sep, os.path.sep)
path = path.replace(ntpath.sep, os.path.sep)
path = path.rstrip(os.path.sep)
return path
示例4: test_nt_helpers
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import sep [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)
示例5: visitFuncDo
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import sep [as 别名]
def visitFuncDo(self, ctx):
func = self.visit(ctx.specialExpr(0))
namespace = self.visit(ctx.specialExpr(1)) if ctx.IN() else ''
args = self.visit(ctx.args(0)) or []
kwargs = {}
if ctx.FORM():
if ctx.NAME():
kwargs['name'] = str(self.visit(ctx.nameId))
if ctx.LINKED():
kwargs['linked'] = True
if args:
kwargs['args'] = args
if ctx.NOSHOW():
kwargs['noshow'] = True
form_call = make_func_code('vfpfunc.do_form', func, **kwargs)
if ctx.TO():
return add_args_to_code('{} = {}', (self.visit(ctx.toId), form_call))
else:
return form_call
if os.path.splitext(namespace)[0] == self.filename:
namespace = ''
if not namespace:
if func in self.function_list:
return make_func_code(func, *args)
if os.path.splitext(func)[1] in ('.prg', '.mpr', '.spr'):
namespace = os.path.splitext(func)[0]
if os.path.splitext(func)[1] in ('.mpr', '.spr'):
namespace += os.path.splitext(func)[1].replace('.', '_')
func = 'MAIN'
else:
func = self.scopeId(func, 'func')
return make_func_code(func, *args)
if namespace.endswith('.prg'):
namespace = namespace[:-4]
if string_type(namespace) and valid_identifier(namespace):
namespace = ntpath.normpath(ntpath.splitext(namespace)[0]).replace(ntpath.sep, '.')
if namespace != 'vfpfunc':
self.imports.append('import ' + namespace)
mod = CodeStr(namespace)
else:
if string_type(namespace):
namespace = CodeStr(repr(namespace))
mod = make_func_code('vfpfunc.module', namespace)
if string_type(func):
func = CodeStr(func)
func = add_args_to_code('{}.{}', (mod, func))
if string_type(namespace):
return make_func_code(func, *args)
else:
func = make_func_code('getattr', mod, func)
return make_func_code(func, *args)