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


Python ntpath.splitdrive方法代码示例

本文整理汇总了Python中ntpath.splitdrive方法的典型用法代码示例。如果您正苦于以下问题:Python ntpath.splitdrive方法的具体用法?Python ntpath.splitdrive怎么用?Python ntpath.splitdrive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ntpath的用法示例。


在下文中一共展示了ntpath.splitdrive方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _rename_information

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def _rename_information(src, dst, replace_if_exists=False, **kwargs):
    verb = 'replace' if replace_if_exists else 'rename'
    norm_src = ntpath.normpath(src)
    norm_dst = ntpath.normpath(dst)

    if not norm_dst.startswith('\\\\'):
        raise ValueError("dst must be an absolute path to where the file or directory should be %sd." % verb)

    src_root = ntpath.splitdrive(norm_src)[0]
    dst_root, dst_name = ntpath.splitdrive(norm_dst)
    if src_root.lower() != dst_root.lower():
        raise ValueError("Cannot %s a file to a different root than the src." % verb)

    raw = SMBRawIO(src, mode='r', share_access='rwd', desired_access=FilePipePrinterAccessMask.DELETE,
                   create_options=CreateOptions.FILE_OPEN_REPARSE_POINT, **kwargs)
    with SMBFileTransaction(raw) as transaction:
        file_rename = FileRenameInformation()
        file_rename['replace_if_exists'] = replace_if_exists
        file_rename['file_name'] = to_text(dst_name[1:])  # dst_name has \ prefix from splitdrive, we remove that.
        set_info(transaction, file_rename) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:22,代码来源:_os.py

示例2: test_splitdrive

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def test_splitdrive(self):
        tester('ntpath.splitdrive("c:\\foo\\bar")',
               ('c:', '\\foo\\bar'))
        tester('ntpath.splitdrive("c:/foo/bar")',
               ('c:', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitdrive("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\\\conky\\mountpoint\\foo\\bar")',
            ('', '\\\\\\conky\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("///conky/mountpoint/foo/bar")',
            ('', '///conky/mountpoint/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\\\mountpoint\\foo\\bar")',
               ('', '\\\\conky\\\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("//conky//mountpoint/foo/bar")',
               ('', '//conky//mountpoint/foo/bar'))
        # Issue #19911: UNC part containing U+0130
        self.assertEqual(ntpath.splitdrive(u'//conky/MOUNTPOİNT/foo/bar'),
                         (u'//conky/MOUNTPOİNT', '/foo/bar'))
        self.assertEqual(ntpath.splitdrive("//"), ("", "//")) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:23,代码来源:test_ntpath.py

示例3: do_get

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_get(self, src_path):

        try:
            import ntpath
            newPath = ntpath.normpath(ntpath.join(self.__pwd, src_path))
            drive, tail = ntpath.splitdrive(newPath) 
            filename = ntpath.basename(tail)
            fh = open(filename,'wb')
            self.__transferClient.getFile(drive[:-1]+'$', tail, fh.write)
            fh.close()

        except Exception as e:
            logging.error(str(e))

            if os.path.exists(filename):
                os.remove(filename) 
开发者ID:aas-n,项目名称:spraykatz,代码行数:18,代码来源:wmiexec_delete.py

示例4: do_put

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_put(self, s):
        try:
            params = s.split(' ')
            if len(params) > 1:
                src_path = params[0]
                dst_path = params[1]
            elif len(params) == 1:
                src_path = params[0]
                dst_path = ''
            src_file = os.path.basename(src_path)
            fh = open(src_path, 'rb')
            dst_path = dst_path.replace('/','\\')
            import ntpath
            pathname = ntpath.join(ntpath.join(self.__pwd,dst_path), src_file)
            drive, tail = ntpath.splitdrive(pathname)
            self.__transferClient.putFile(drive[:-1]+'$', tail, fh.read)
            fh.close()
        except Exception as e:
            logging.critical(str(e))
            pass 
开发者ID:aas-n,项目名称:spraykatz,代码行数:22,代码来源:wmiexec_delete.py

示例5: __init__

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def __init__(
        self,
        min_len: Optional[int] = 1,
        max_len: Optional[int] = None,
        platform: PlatformType = None,
        check_reserved: bool = True,
    ) -> None:
        super().__init__(
            min_len=min_len, max_len=max_len, check_reserved=check_reserved, platform=platform,
        )

        self.__fname_validator = FileNameValidator(
            min_len=min_len, max_len=max_len, check_reserved=check_reserved, platform=platform
        )

        if self._is_universal() or self._is_windows():
            self.__split_drive = ntpath.splitdrive
        else:
            self.__split_drive = posixpath.splitdrive 
开发者ID:thombashi,项目名称:pathvalidate,代码行数:21,代码来源:_filepath.py

示例6: flat_rootname

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def flat_rootname(filename):
    """A base for a flat file name to correspond to this file.

    Useful for writing files about the code where you want all the files in
    the same directory, but need to differentiate same-named files from
    different directories.

    For example, the file a/b/c.py will return 'a_b_c_py'

    """
    name = ntpath.splitdrive(filename)[1]
    name = re.sub(r"[\\/.:]", "_", name)
    if len(name) > MAX_FLAT:
        h = hashlib.sha1(name.encode('UTF-8')).hexdigest()
        name = name[-(MAX_FLAT-len(h)-1):] + '_' + h
    return name 
开发者ID:nedbat,项目名称:coveragepy-bbmirror,代码行数:18,代码来源:files.py

示例7: test_splitdrive

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def test_splitdrive(self):
        tester('ntpath.splitdrive("c:\\foo\\bar")',
               ('c:', '\\foo\\bar'))
        tester('ntpath.splitdrive("c:/foo/bar")',
               ('c:', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitdrive("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\\\conky\\mountpoint\\foo\\bar")',
            ('', '\\\\\\conky\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("///conky/mountpoint/foo/bar")',
            ('', '///conky/mountpoint/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\\\mountpoint\\foo\\bar")',
               ('', '\\\\conky\\\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("//conky//mountpoint/foo/bar")',
               ('', '//conky//mountpoint/foo/bar'))
        # Issue #19911: UNC part containing U+0130
        self.assertEqual(ntpath.splitdrive('//conky/MOUNTPOİNT/foo/bar'),
                         ('//conky/MOUNTPOİNT', '/foo/bar')) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:22,代码来源:test_ntpath.py

示例8: do_put

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_put(self, s):
        try:
            params = s.split(' ')
            if len(params) > 1:
                src_path = params[0]
                dst_path = params[1]
            elif len(params) == 1:
                src_path = params[0]
                dst_path = ''

            src_file = os.path.basename(src_path)
            fh = open(src_path, 'rb')
            dst_path = string.replace(dst_path, '/','\\')
            pathname = ntpath.join(ntpath.join(self.__pwd,dst_path), src_file)
            drive, tail = ntpath.splitdrive(pathname)
            logging.info("Uploading %s to %s" % (src_file, pathname))
            self.__transferClient.putFile(drive[:-1]+'$', tail, fh.read)
            fh.close()
        except Exception as e:
            logging.critical(str(e))
            pass 
开发者ID:ShawnDEvans,项目名称:smbmap,代码行数:23,代码来源:smbmap.py

示例9: win_to_cygwin_path

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def win_to_cygwin_path(path):
    """
    Converts a Windows path to a Cygwin path.

    :param path: Windows path to convert.
        Must be an absolute path.
    :type path: str

    :returns: Cygwin path.
    :rtype: str

    :raises ValueError: Cannot convert the path.
    """
    drive, path = ntpath.splitdrive(path)
    if not drive:
        raise ValueError("Not an absolute path!")
    t = { "\\": "/", "/": "\\/" }
    path = "".join( t.get(c, c) for c in path )
    return "/cygdrive/%s%s" % (drive[0].lower(), path)


#------------------------------------------------------------------------------ 
开发者ID:blackye,项目名称:luscan-devel,代码行数:24,代码来源:external.py

示例10: test_splitdrive

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def test_splitdrive(self):
        tester('ntpath.splitdrive("c:\\foo\\bar")',
               ('c:', '\\foo\\bar'))
        tester('ntpath.splitdrive("c:/foo/bar")',
               ('c:', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\mountpoint\\foo\\bar")',
               ('\\\\conky\\mountpoint', '\\foo\\bar'))
        tester('ntpath.splitdrive("//conky/mountpoint/foo/bar")',
               ('//conky/mountpoint', '/foo/bar'))
        tester('ntpath.splitdrive("\\\\\\conky\\mountpoint\\foo\\bar")',
            ('', '\\\\\\conky\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("///conky/mountpoint/foo/bar")',
            ('', '///conky/mountpoint/foo/bar'))
        tester('ntpath.splitdrive("\\\\conky\\\\mountpoint\\foo\\bar")',
               ('', '\\\\conky\\\\mountpoint\\foo\\bar'))
        tester('ntpath.splitdrive("//conky//mountpoint/foo/bar")',
               ('', '//conky//mountpoint/foo/bar'))
        # Issue #19911: UNC part containing U+0130
        self.assertEqual(ntpath.splitdrive(u'//conky/MOUNTPOİNT/foo/bar'),
                         (u'//conky/MOUNTPOİNT', '/foo/bar')) 
开发者ID:gcblue,项目名称:gcblue,代码行数:22,代码来源:test_ntpath.py

示例11: do_put

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_put(self, s):
        try:
            params = s.split(' ')
            if len(params) > 1:
                src_path = params[0]
                dst_path = params[1]
            elif len(params) == 1:
                src_path = params[0]
                dst_path = ''

            src_file = os.path.basename(src_path)
            fh = open(src_path, 'rb')
            dst_path = dst_path.replace('/','\\')
            import ntpath
            pathname = ntpath.join(ntpath.join(self._pwd, dst_path), src_file)
            drive, tail = ntpath.splitdrive(pathname)
            logging.info("Uploading %s to %s" % (src_file, pathname))
            self.__transferClient.putFile(drive[:-1]+'$', tail, fh.read)
            fh.close()
        except Exception as e:
            logging.critical(str(e))
            pass 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:24,代码来源:dcomexec.py

示例12: do_get

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_get(self, src_path):

        try:
            import ntpath
            newPath = ntpath.normpath(ntpath.join(self.__pwd, src_path))
            drive, tail = ntpath.splitdrive(newPath) 
            filename = ntpath.basename(tail)
            fh = open(filename,'wb')
            logging.info("Downloading %s\\%s" % (drive, tail))
            self.__transferClient.getFile(drive[:-1]+'$', tail, fh.write)
            fh.close()

        except Exception as e:
            logging.error(str(e))

            if os.path.exists(filename):
                os.remove(filename) 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:19,代码来源:wmiexec.py

示例13: do_put

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_put(self, s):
        try:
            params = s.split(' ')
            if len(params) > 1:
                src_path = params[0]
                dst_path = params[1]
            elif len(params) == 1:
                src_path = params[0]
                dst_path = ''

            src_file = os.path.basename(src_path)
            fh = open(src_path, 'rb')
            dst_path = dst_path.replace('/','\\')
            import ntpath
            pathname = ntpath.join(ntpath.join(self.__pwd,dst_path), src_file)
            drive, tail = ntpath.splitdrive(pathname)
            logging.info("Uploading %s to %s" % (src_file, pathname))
            self.__transferClient.putFile(drive[:-1]+'$', tail, fh.read)
            fh.close()
        except Exception as e:
            logging.critical(str(e))
            pass 
开发者ID:Coalfire-Research,项目名称:Slackor,代码行数:24,代码来源:wmiexec.py

示例14: do_put

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def do_put(self, s):
        try:
            params = s.split(' ')
            if len(params) > 1:
                src_path = params[0]
                dst_path = params[1]
            elif len(params) == 1:
                src_path = params[0]
                dst_path = ''

            src_file = os.path.basename(src_path)
            fh = open(src_path, 'rb')
            dst_path = string.replace(dst_path, '/','\\')
            import ntpath
            pathname = ntpath.join(ntpath.join(self.__pwd,dst_path), src_file)
            drive, tail = ntpath.splitdrive(pathname)
            logging.info("Uploading %s to %s" % (src_file, pathname))
            self.__transferClient.putFile(drive[:-1]+'$', tail, fh.read)
            fh.close()
        except Exception, e:
            logging.critical(str(e))
            pass 
开发者ID:tholum,项目名称:PiBunny,代码行数:24,代码来源:mmcexec.py

示例15: link

# 需要导入模块: import ntpath [as 别名]
# 或者: from ntpath import splitdrive [as 别名]
def link(src, dst, follow_symlinks=True, **kwargs):
    """
    Create a hard link pointing to src named dst. The src argument must be an absolute path in the same share as
    src.

    :param src: The full UNC path to used as the source of the hard link.
    :param dst: The full UNC path to create the hard link at.
    :param follow_symlinks: Whether to link to the src target (True) or src itself (False) if src is a symlink.
    :param kwargs: Common arguments used to build the SMB Session.
    """
    norm_src = ntpath.normpath(src)
    norm_dst = ntpath.normpath(dst)

    if not norm_src.startswith('\\\\'):
        raise ValueError("src must be the absolute path to where the file is hard linked to.")

    src_root = ntpath.splitdrive(norm_src)[0]
    dst_root, dst_name = ntpath.splitdrive(norm_dst)
    if src_root.lower() != dst_root.lower():
        raise ValueError("Cannot hardlink a file to a different root than the src.")

    raw = SMBFileIO(norm_src, mode='r', share_access='rwd',
                    desired_access=FilePipePrinterAccessMask.FILE_WRITE_ATTRIBUTES,
                    create_options=0 if follow_symlinks else CreateOptions.FILE_OPEN_REPARSE_POINT, **kwargs)
    with SMBFileTransaction(raw) as transaction:
        link_info = FileLinkInformation()
        link_info['replace_if_exists'] = False
        link_info['file_name'] = to_text(dst_name[1:])
        set_info(transaction, link_info) 
开发者ID:jborean93,项目名称:smbprotocol,代码行数:31,代码来源:_os.py


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