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


Python posixpath.join方法代码示例

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


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

示例1: _load_subject

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def _load_subject(ppath, url, credentials, cache_directory, df, sid):
        '''
        Creates a pseudo-path for the given subject and loads that subject as an hcp subject then
        returns it.
        '''
        from neuropythy.hcp import subject
        from posixpath import join as urljoin
        pm    = ppath._path_data['pathmod']
        creds = ppath.credentials
        # Make the pseudo-path; if auto-downloading is set to false, we want to create a pseudo-path
        # from only the cache path
        if config['hcp_auto_download'] in [False, None]:
            ppath = pseudo_path(os.path.join(cache_directory, str(sid)), delete=False)
        else:
            ppath = pseudo_path((pm.s3fs, urljoin(url, str(sid))),
                                credentials=credentials,
                                cache_path=os.path.join(cache_directory, str(sid)),
                                delete=False) # the base dir will be deleted if needs be
        return subject(ppath, default_alignment=df, name=str(sid)) 
开发者ID:noahbenson,项目名称:neuropythy,代码行数:21,代码来源:hcp.py

示例2: limited_join

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def limited_join(sep, items, max_chars=30, overflow_marker="..."):
    """Join a number of strings to one, limiting the length to *max_chars*.

    If the string overflows this limit, replace the last fitting item by
    *overflow_marker*.

    Returns: joined_string
    """
    full_str = sep.join(items)
    if len(full_str) < max_chars:
        return full_str

    n_chars = 0
    n_items = 0
    for j, item in enumerate(items):
        n_chars += len(item) + len(sep)
        if n_chars < max_chars - len(overflow_marker):
            n_items += 1
        else:
            break

    return sep.join(list(items[:n_items]) + [overflow_marker])


# -- Importing items ----------------------------------------------------------- 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:27,代码来源:autosummary__init__.py

示例3: import_by_name

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def import_by_name(name, prefixes=[None]):
    """Import a Python object that has the given *name*, under one of the
    *prefixes*.  The first name that succeeds is used.
    """
    tried = []
    for prefix in prefixes:
        try:
            if prefix:
                prefixed_name = '.'.join([prefix, name])
            else:
                prefixed_name = name
            obj, parent, modname = _import_by_name(prefixed_name)
            return prefixed_name, obj, parent, modname
        except ImportError:
            tried.append(prefixed_name)
    raise ImportError('no module named %s' % ' or '.join(tried)) 
开发者ID:pyGSTio,项目名称:pyGSTi,代码行数:18,代码来源:autosummary__init__.py

示例4: adjust_uri

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def adjust_uri(self, uri, relativeto):
        """Adjust the given ``uri`` based on the given relative URI."""

        key = (uri, relativeto)
        if key in self._uri_cache:
            return self._uri_cache[key]

        if uri[0] != "/":
            if relativeto is not None:
                v = self._uri_cache[key] = posixpath.join(
                    posixpath.dirname(relativeto), uri
                )
            else:
                v = self._uri_cache[key] = "/" + uri
        else:
            v = self._uri_cache[key] = uri
        return v 
开发者ID:remg427,项目名称:misp42splunk,代码行数:19,代码来源:lookup.py

示例5: export_protos

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def export_protos(destination):
  """Exports the compiled protos for the bundle.

  The engine initialization process has already built all protos and made them
  importable as `PB`. We rely on `PB.__path__` because this allows the
  `--proto-override` flag to work.

  Args:
    * repo (RecipeRepo) - The repo to export.
    * destination (str) - The absolute path we're exporting to (we'll export to
      a subfolder `_pb/PB`).
  """
  shutil.copytree(
      PB_PATH[0], # root of generated PB folder.
      os.path.join(destination, '_pb', 'PB'),
      ignore=lambda _base, names: [n for n in names if n.endswith('.pyc')],
  ) 
开发者ID:luci,项目名称:recipes-py,代码行数:19,代码来源:cmd.py

示例6: __call__

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def __call__(self, dirname):
    """Makes a directory.

    Args:
      * dirname (str) - Directory to make (abs or relative).
    """
    if dirname in self.made_dirs:
      return
    toks = dirname.split(os.path.sep)
    try:
      os.makedirs(dirname)
    except OSError as ex:
      if ex.errno != errno.EEXIST:
        raise
    curpath = toks[0] + os.path.sep
    for tok in toks[1:]:
      curpath = os.path.join(curpath, tok)
      self.made_dirs.add(curpath) 
开发者ID:luci,项目名称:recipes-py,代码行数:20,代码来源:proto_support.py

示例7: _collect_protos

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def _collect_protos(argfile_fd, proto_files, dest):
  """Copies all proto_files into dest.

  Writes this list of files to `argfile_fd` which will be passed to protoc.

  Args:
    * argfile_fd (int): An open writable file descriptor for the argfile.
    * proto_files (List[Tuple[src_abspath: str, dest_relpath: str]])
    * dest (str): Path to the directory where we should collect the .proto
    files.

  Side-effects:
    * Each dest_relpath is written to `argfile_fd` on its own line.
    * Closes `argfile_fd`.
  """
  try:
    _makedirs = _DirMaker()
    for src_abspath, dest_relpath in proto_files:
      destpath = os.path.join(dest, dest_relpath)
      _makedirs(os.path.dirname(destpath))
      shutil.copyfile(src_abspath, destpath)
      os.write(argfile_fd, dest_relpath)
      os.write(argfile_fd, '\n')
  finally:
    os.close(argfile_fd)  # for windows 
开发者ID:luci,项目名称:recipes-py,代码行数:27,代码来源:proto_support.py

示例8: _check_digest

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def _check_digest(proto_package, dgst):
  """Checks protos installed in `{proto_package_path}/PB`.

  Args:
    * proto_package_base (str) - The absolute path to the folder where we will
      look for '.../PB/csum
    * dgst (str) - The digest of the proto files which we believe need to be
      built.

  Returns True iff csum matches dgst.
  """
  try:
    csum_path = os.path.join(proto_package, 'PB', 'csum')
    with open(csum_path, 'rb') as cur_dgst_f:
      return cur_dgst_f.read() == dgst
  except (OSError, IOError) as exc:
    if exc.errno != errno.ENOENT:
      raise 
开发者ID:luci,项目名称:recipes-py,代码行数:20,代码来源:proto_support.py

示例9: open_binary

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def open_binary(self, name, content_type=None, tags=None, for_process=False):
    """Returns (file): A file-like object for a single binary stream.

    This creates a new butler BINARY stream with the specified parameters.

    Args:
      name (str): the LogDog name of the stream.
      content_type (str): The optional content type of the stream. If None, a
          default content type will be chosen by the Butler.
      tags (dict): An optional key/value dictionary pair of LogDog stream tags.
      for_process (bool): Indicates that this stream will be directly attached
        to a subprocess's stdout/stderr

    Returns (file): A file-like object to a Butler binary stream. This object
        can have UTF-8 content written to it with its `write` method, and must
        be closed when finished using its `close` method.
    """
    params = StreamParams.make(
        name=posixpath.join(self._namespace, name),
        type=StreamParams.BINARY,
        content_type=content_type,
        tags=tags)
    return self._BasicStream(self, params,
                             self.new_connection(params, for_process)) 
开发者ID:luci,项目名称:recipes-py,代码行数:26,代码来源:stream.py

示例10: open_datagram

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def open_datagram(self, name, content_type=None, tags=None):
    """Creates a new butler DATAGRAM stream with the specified parameters.

    Args:
      name (str): the LogDog name of the stream.
      content_type (str): The optional content type of the stream. If None, a
          default content type will be chosen by the Butler.
      tags (dict): An optional key/value dictionary pair of LogDog stream tags.

    Returns (_DatagramStream): A datagram stream object. Datagrams can be
        written to it using its `send` method. This object must be closed when
        finished by using its `close` method.
    """
    params = StreamParams.make(
        name=posixpath.join(self._namespace, name),
        type=StreamParams.DATAGRAM,
        content_type=content_type,
        tags=tags)
    return self._DatagramStream(self, params,
                                self.new_connection(params, False)) 
开发者ID:luci,项目名称:recipes-py,代码行数:22,代码来源:stream.py

示例11: _get_incdec_value

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def _get_incdec_value(match, inc_or_dec, count):
    """Get an incremented/decremented URL based on a URL match."""
    pre, zeroes, number, post = match.groups()
    # This should always succeed because we match \d+
    val = int(number)
    if inc_or_dec == 'decrement':
        if val < count:
            raise Error("Can't decrement {} by {}!".format(val, count))
        val -= count
    elif inc_or_dec == 'increment':
        val += count
    else:
        raise ValueError("Invalid value {} for inc_or_dec!".format(inc_or_dec))
    if zeroes:
        if len(number) < len(str(val)):
            zeroes = zeroes[1:]
        elif len(number) > len(str(val)):
            zeroes += '0'

    return ''.join([pre, zeroes, str(val), post]) 
开发者ID:qutebrowser,项目名称:qutebrowser,代码行数:22,代码来源:navigate.py

示例12: safe_join

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def safe_join(directory, *pathnames):
    """Safely join `directory` and one or more untrusted `pathnames`.  If this
    cannot be done, this function returns ``None``.

    :param directory: the base directory.
    :param pathnames: the untrusted pathnames relative to that directory.
    """
    parts = [directory]
    for filename in pathnames:
        if filename != "":
            filename = posixpath.normpath(filename)
        for sep in _os_alt_seps:
            if sep in filename:
                return None
        if os.path.isabs(filename) or filename == ".." or filename.startswith("../"):
            return None
        parts.append(filename)
    return posixpath.join(*parts) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:20,代码来源:security.py

示例13: __str__

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def __str__(self):
        message = []
        message.append("Could not build url for endpoint %r" % self.endpoint)
        if self.method:
            message.append(" (%r)" % self.method)
        if self.values:
            message.append(" with values %r" % sorted(self.values.keys()))
        message.append(".")
        if self.suggested:
            if self.endpoint == self.suggested.endpoint:
                if self.method and self.method not in self.suggested.methods:
                    message.append(
                        " Did you mean to use methods %r?"
                        % sorted(self.suggested.methods)
                    )
                missing_values = self.suggested.arguments.union(
                    set(self.suggested.defaults or ())
                ) - set(self.values.keys())
                if missing_values:
                    message.append(
                        " Did you forget to specify values %r?" % sorted(missing_values)
                    )
            else:
                message.append(" Did you mean %r instead?" % self.suggested.endpoint)
        return u"".join(message) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:routing.py

示例14: make_redirect_url

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def make_redirect_url(self, path_info, query_args=None, domain_part=None):
        """Creates a redirect URL.

        :internal:
        """
        suffix = ""
        if query_args:
            suffix = "?" + self.encode_query_args(query_args)
        return str(
            "%s://%s/%s%s"
            % (
                self.url_scheme or "http",
                self.get_host(domain_part),
                posixpath.join(
                    self.script_name[:-1].lstrip("/"), path_info.lstrip("/")
                ),
                suffix,
            )
        ) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:21,代码来源:routing.py

示例15: metadata

# 需要导入模块: import posixpath [as 别名]
# 或者: from posixpath import join [as 别名]
def metadata(self):
        pathname = os.path.join(self.dirname, self.filename)
        name_ver = '%s-%s' % (self.name, self.version)
        info_dir = '%s.dist-info' % name_ver
        wrapper = codecs.getreader('utf-8')
        with ZipFile(pathname, 'r') as zf:
            wheel_metadata = self.get_wheel_metadata(zf)
            wv = wheel_metadata['Wheel-Version'].split('.', 1)
            file_version = tuple([int(i) for i in wv])
            if file_version < (1, 1):
                fn = 'METADATA'
            else:
                fn = METADATA_FILENAME
            try:
                metadata_filename = posixpath.join(info_dir, fn)
                with zf.open(metadata_filename) as bf:
                    wf = wrapper(bf)
                    result = Metadata(fileobj=wf)
            except KeyError:
                raise ValueError('Invalid wheel, because %s is '
                                 'missing' % fn)
        return result 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,代码来源:wheel.py


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