当前位置: 首页>>代码示例>>Python>>正文


Python ntpath.expanduser方法代码示例

本文整理汇总了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') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:36,代码来源:test_ntpath.py

示例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') 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:36,代码来源:test_ntpath.py

示例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) 
开发者ID:GoogleCloudPlatform,项目名称:PerfKitBenchmarker,代码行数:36,代码来源:windows_virtual_machine.py

示例4: test_path_expanduser

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import expanduser [as 别名]
def test_path_expanduser(self):
        self.assertPathEqual(self.path.expanduser) 
开发者ID:bkerler,项目名称:android_universal,代码行数:4,代码来源:test_ntpath.py


注:本文中的ntpath.expanduser方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。