本文整理汇总了Python中ntpath.expanduser方法的典型用法代码示例。如果您正苦于以下问题:Python ntpath.expanduser方法的具体用法?Python ntpath.expanduser怎么用?Python ntpath.expanduser使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ntpath
的用法示例。
在下文中一共展示了ntpath.expanduser方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_expanduser
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import expanduser [as 别名]
def test_expanduser(self):
tester('ntpath.expanduser("test")', 'test')
with test_support.EnvironmentVarGuard() as env:
env.clear()
tester('ntpath.expanduser("~test")', '~test')
env['HOMEPATH'] = 'eric\\idle'
env['HOMEDRIVE'] = 'C:\\'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
del env['HOMEDRIVE']
tester('ntpath.expanduser("~test")', 'eric\\test')
tester('ntpath.expanduser("~")', 'eric\\idle')
env.clear()
env['USERPROFILE'] = 'C:\\eric\\idle'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
env.clear()
env['HOME'] = 'C:\\idle\\eric'
tester('ntpath.expanduser("~test")', 'C:\\idle\\test')
tester('ntpath.expanduser("~")', 'C:\\idle\\eric')
tester('ntpath.expanduser("~test\\foo\\bar")',
'C:\\idle\\test\\foo\\bar')
tester('ntpath.expanduser("~test/foo/bar")',
'C:\\idle\\test/foo/bar')
tester('ntpath.expanduser("~\\foo\\bar")',
'C:\\idle\\eric\\foo\\bar')
tester('ntpath.expanduser("~/foo/bar")',
'C:\\idle\\eric/foo/bar')
示例2: test_expanduser
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import expanduser [as 别名]
def test_expanduser(self):
tester('ntpath.expanduser("test")', 'test')
with support.EnvironmentVarGuard() as env:
env.clear()
tester('ntpath.expanduser("~test")', '~test')
env['HOMEPATH'] = 'eric\\idle'
env['HOMEDRIVE'] = 'C:\\'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
del env['HOMEDRIVE']
tester('ntpath.expanduser("~test")', 'eric\\test')
tester('ntpath.expanduser("~")', 'eric\\idle')
env.clear()
env['USERPROFILE'] = 'C:\\eric\\idle'
tester('ntpath.expanduser("~test")', 'C:\\eric\\test')
tester('ntpath.expanduser("~")', 'C:\\eric\\idle')
env.clear()
env['HOME'] = 'C:\\idle\\eric'
tester('ntpath.expanduser("~test")', 'C:\\idle\\test')
tester('ntpath.expanduser("~")', 'C:\\idle\\eric')
tester('ntpath.expanduser("~test\\foo\\bar")',
'C:\\idle\\test\\foo\\bar')
tester('ntpath.expanduser("~test/foo/bar")',
'C:\\idle\\test/foo/bar')
tester('ntpath.expanduser("~\\foo\\bar")',
'C:\\idle\\eric\\foo\\bar')
tester('ntpath.expanduser("~/foo/bar")',
'C:\\idle\\eric/foo/bar')
示例3: RemoteCopy
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import expanduser [as 别名]
def RemoteCopy(self, local_path, remote_path='', copy_to=True):
"""Copies a file to or from the VM.
Args:
local_path: Local path to file.
remote_path: Optional path of where to copy file on remote host.
copy_to: True to copy to vm, False to copy from vm.
Raises:
RemoteCommandError: If there was a problem copying the file.
"""
remote_path = remote_path or '~/'
# In order to expand "~" and "~user" we use ntpath.expanduser(),
# but it relies on environment variables being set. This modifies
# the HOME environment variable in order to use that function, and then
# restores it to its previous value.
home = os.environ.get('HOME')
try:
os.environ['HOME'] = self.home_dir
remote_path = ntpath.expanduser(remote_path)
finally:
if home is None:
del os.environ['HOME']
else:
os.environ['HOME'] = home
drive, remote_path = ntpath.splitdrive(remote_path)
remote_drive = (drive or self.system_drive).rstrip(':')
network_drive = '\\\\%s\\%s$' % (self.GetConnectionIp(), remote_drive)
if vm_util.RunningOnWindows():
self._PsDriveRemoteCopy(local_path, remote_path, copy_to, network_drive)
else:
self._SmbclientRemoteCopy(local_path, remote_path, copy_to, network_drive)
示例4: test_path_expanduser
# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import expanduser [as 别名]
def test_path_expanduser(self):
self.assertPathEqual(self.path.expanduser)