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


Python pathlib.PurePosixPath方法代码示例

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


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

示例1: _ftp_put

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def _ftp_put(self, local_path, path, atomic):
        normpath = str(PurePosixPath(path))
        folder = str(PurePosixPath(path).parent)
        self._ftp_mkdirs(folder)

        # go back to ftp root folder
        self.conn.cwd("/")

        # random file name
        if atomic:
            tmp_path = folder + os.sep + 'luigi-tmp-%09d' % random.randrange(0, 1e10)
        else:
            tmp_path = normpath

        self.conn.storbinary('STOR %s' % tmp_path, open(local_path, 'rb'))

        if atomic:
            self.conn.rename(tmp_path, normpath) 
开发者ID:d6t,项目名称:d6tpipe,代码行数:20,代码来源:ftp.py

示例2: should_domain_substitute

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def should_domain_substitute(path, relative_path, search_regex, unused_patterns):
    """
    Returns True if a path should be domain substituted in the source tree; False otherwise

    path is the pathlib.Path to the file from the current working directory.
    relative_path is the pathlib.Path to the file from the source tree.
    search_regex is a compiled regex object to search for domain names
    unused_patterns is a UnusedPatterns object
    """
    relative_path_posix = relative_path.as_posix().lower()
    for include_pattern in DOMAIN_INCLUDE_PATTERNS:
        if PurePosixPath(relative_path_posix).match(include_pattern):
            unused_patterns.domain_include_patterns.discard(include_pattern)
            for exclude_prefix in DOMAIN_EXCLUDE_PREFIXES:
                if relative_path_posix.startswith(exclude_prefix):
                    unused_patterns.domain_exclude_prefixes.discard(exclude_prefix)
                    return False
            return _check_regex_match(path, search_regex)
    return False 
开发者ID:Eloston,项目名称:ungoogled-chromium,代码行数:21,代码来源:update_lists.py

示例3: get_path_from_template

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def get_path_from_template(path_template: str, path_type: PathType = PathType.AUTO) -> str:
    """Replace tags in the given path template and return either Windows or Linux formatted path."""
    # automatically select path type depending on running OS
    if path_type == PathType.AUTO:
        if platform.system() == "Windows":
            path_type = PathType.WINDOWS
        elif platform.system() == "Linux":
            path_type = PathType.LINUX
        else:
            raise RuntimeError("Unknown platform")

    path_template = path_template.replace("<USERNAME>", get_user_name())

    # return correctly formatted path
    if path_type == PathType.WINDOWS:
        return str(pathlib.PureWindowsPath(path_template))
    elif path_type == PathType.LINUX:
        return str(pathlib.PurePosixPath(path_template))
    else:
        raise RuntimeError("Unknown platform") 
开发者ID:produvia,项目名称:ai-platform,代码行数:22,代码来源:submit.py

示例4: test_different_flavours_unordered

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def test_different_flavours_unordered(self):
        p = pathlib.PurePosixPath('a')
        q = pathlib.PureWindowsPath('a')
        with self.assertRaises(TypeError):
            p < q
        with self.assertRaises(TypeError):
            p <= q
        with self.assertRaises(TypeError):
            p > q
        with self.assertRaises(TypeError):
            p >= q


#
# Tests for the concrete classes
#

# Make sure any symbolic links in the base test path are resolved 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:20,代码来源:test_pathlib.py

示例5: __init__

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def __init__(self,
                 login=None,
                 password=None, *,
                 base_path=pathlib.Path("."),
                 home_path=pathlib.PurePosixPath("/"),
                 permissions=None,
                 maximum_connections=None,
                 read_speed_limit=None,
                 write_speed_limit=None,
                 read_speed_limit_per_connection=None,
                 write_speed_limit_per_connection=None):
        self.login = login
        self.password = password
        self.base_path = pathlib.Path(base_path)
        self.home_path = pathlib.PurePosixPath(home_path)
        if not self.home_path.is_absolute():
            raise errors.PathIsNotAbsolute(home_path)
        self.permissions = permissions or [Permission()]
        self.maximum_connections = maximum_connections
        self.read_speed_limit = read_speed_limit
        self.write_speed_limit = write_speed_limit
        self.read_speed_limit_per_connection = read_speed_limit_per_connection
        # damn 80 symbols
        self.write_speed_limit_per_connection = \
            write_speed_limit_per_connection 
开发者ID:aio-libs,项目名称:aioftp,代码行数:27,代码来源:server.py

示例6: get_permissions

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def get_permissions(self, path):
        """
        Return nearest parent permission for `path`.

        :param path: path which permission you want to know
        :type path: :py:class:`str` or :py:class:`pathlib.PurePosixPath`

        :rtype: :py:class:`aioftp.Permission`
        """
        path = pathlib.PurePosixPath(path)
        parents = filter(lambda p: p.is_parent(path), self.permissions)
        perm = min(
            parents,
            key=lambda p: len(path.relative_to(p.path).parts),
            default=Permission(),
        )
        return perm 
开发者ID:aio-libs,项目名称:aioftp,代码行数:19,代码来源:server.py

示例7: parse_list_line

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def parse_list_line(self, b):
        """
        Parse LIST response with both Microsoft Windows® parser and
        UNIX parser

        :param b: response line
        :type b: :py:class:`bytes` or :py:class:`str`

        :return: (path, info)
        :rtype: (:py:class:`pathlib.PurePosixPath`, :py:class:`dict`)
        """
        ex = []
        parsers = (
            self.parse_list_line_custom,
            self.parse_list_line_unix,
            self.parse_list_line_windows,
        )
        for parser in parsers:
            if parser is None:
                continue
            try:
                return parser(b)
            except (ValueError, KeyError, IndexError) as e:
                ex.append(e)
        raise ValueError("All parsers failed to parse", b, ex) 
开发者ID:aio-libs,项目名称:aioftp,代码行数:27,代码来源:client.py

示例8: parse_mlsx_line

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def parse_mlsx_line(self, b):
        """
        Parsing MLS(T|D) response.

        :param b: response line
        :type b: :py:class:`bytes` or :py:class:`str`

        :return: (path, info)
        :rtype: (:py:class:`pathlib.PurePosixPath`, :py:class:`dict`)
        """
        if isinstance(b, bytes):
            s = b.decode(encoding=self.encoding)
        else:
            s = b
        line = s.rstrip()
        facts_found, _, name = line.partition(" ")
        entry = {}
        for fact in facts_found[:-1].split(";"):
            key, _, value = fact.partition("=")
            entry[key.lower()] = value
        return pathlib.PurePosixPath(name), entry 
开发者ID:aio-libs,项目名称:aioftp,代码行数:23,代码来源:client.py

示例9: exists

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def exists(self, path):
        """
        :py:func:`asyncio.coroutine`

        Check path for existence.

        :param path: path to check
        :type path: :py:class:`str` or :py:class:`pathlib.PurePosixPath`

        :rtype: :py:class:`bool`
        """
        try:
            await self.stat(path)
            return True
        except errors.StatusCodeError as e:
            if e.received_codes[-1].matches("550"):
                return False
            raise 
开发者ID:aio-libs,项目名称:aioftp,代码行数:20,代码来源:client.py

示例10: remove

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def remove(self, path):
        """
        :py:func:`asyncio.coroutine`

        High level remove method for removing path recursively (file or
        directory).

        :param path: path to remove
        :type path: :py:class:`str` or :py:class:`pathlib.PurePosixPath`
        """
        if await self.exists(path):
            info = await self.stat(path)
            if info["type"] == "file":
                await self.remove_file(path)
            elif info["type"] == "dir":
                for name, info in (await self.list(path)):
                    if info["type"] in ("dir", "file"):
                        await self.remove(name)
                await self.remove_directory(path) 
开发者ID:aio-libs,项目名称:aioftp,代码行数:21,代码来源:client.py

示例11: upload_stream

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def upload_stream(self, destination, *, offset=0):
        """
        Create stream for write data to `destination` file.

        :param destination: destination path of file on server side
        :type destination: :py:class:`str` or :py:class:`pathlib.PurePosixPath`

        :param offset: byte offset for stream start position
        :type offset: :py:class:`int`

        :rtype: :py:class:`aioftp.DataConnectionThrottleStreamIO`
        """
        return self.get_stream(
            "STOR " + str(destination),
            "1xx",
            offset=offset,
        ) 
开发者ID:aio-libs,项目名称:aioftp,代码行数:19,代码来源:client.py

示例12: append_stream

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def append_stream(self, destination, *, offset=0):
        """
        Create stream for append (write) data to `destination` file.

        :param destination: destination path of file on server side
        :type destination: :py:class:`str` or :py:class:`pathlib.PurePosixPath`

        :param offset: byte offset for stream start position
        :type offset: :py:class:`int`

        :rtype: :py:class:`aioftp.DataConnectionThrottleStreamIO`
        """
        return self.get_stream(
            "APPE " + str(destination),
            "1xx",
            offset=offset,
        ) 
开发者ID:aio-libs,项目名称:aioftp,代码行数:19,代码来源:client.py

示例13: test_client_list_override_with_custom

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def test_client_list_override_with_custom(pair_factory, Client):
    meta = {"type": "file", "works": True}

    def parser(b):
        import pickle
        return pickle.loads(bytes.fromhex(b.decode().rstrip("\r\n")))

    async def builder(_, path):
        import pickle
        return pickle.dumps((path, meta)).hex()

    async with pair_factory(Client(parse_list_line_custom=parser)) as pair:
        pair.server.commands_mapping["mlst"] = not_implemented
        pair.server.commands_mapping["mlsd"] = not_implemented
        pair.server.build_list_string = builder
        await pair.client.make_directory("bar")
        (path, stat), *_ = files = await pair.client.list()
        assert len(files) == 1
        assert path == pathlib.PurePosixPath("bar")
        assert stat == meta 
开发者ID:aio-libs,项目名称:aioftp,代码行数:22,代码来源:test_list_fallback.py

示例14: test_pipes_base

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def test_pipes_base(cleanup_pipe):
    import d6tflow.pipes
    d6tflow.pipes.init(cfg['d6tpipe_pipe1'],profile=cfg['d6tpipe_profile'])

    t1 = Task1()
    pipe1 = d6tflow.pipes.get_pipe()
    pipedir = pipe1.dirpath
    t1filepath = t1.output().path
    t1file = str(PurePosixPath(t1filepath.relative_to(pipedir)))

    assert d6tflow.run(t1)
    assert t1.complete()
    with fuckit:
        pipe1._pullpush_luigi([t1file], op='remove')
    assert pipe1.push_preview()==[t1file]
    assert pipe1.push()==[t1file]
    assert pipe1.scan_remote(cached=False) == [t1file]
    # cleanup
    pipe1.delete_files(confirm=False, all_local=True)
    assert pipe1.scan_remote(cached=False) == [] 
开发者ID:d6t,项目名称:d6tflow,代码行数:22,代码来源:main.py

示例15: modurl

# 需要导入模块: import pathlib [as 别名]
# 或者: from pathlib import PurePosixPath [as 别名]
def modurl(qualname):
    """Get the full GitHub URL for some object’s qualname."""
    obj, module = get_obj_module(qualname)
    github_url = github_url_scvelo
    try:
        path = PurePosixPath(Path(module.__file__).resolve().relative_to(project_dir))
    except ValueError:
        # trying to document something from another package
        github_url = (
            github_url_read_loom
            if "read_loom" in qualname
            else github_url_read
            if "read" in qualname
            else github_url_scanpy
        )
        path = "/".join(module.__file__.split("/")[-2:])
    start, end = get_linenos(obj)
    fragment = f"#L{start}-L{end}" if start and end else ""
    return f"{github_url}/{path}{fragment}" 
开发者ID:theislab,项目名称:scvelo,代码行数:21,代码来源:conf.py


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