• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python posixpath.isabs函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中posixpath.isabs函数的典型用法代码示例。如果您正苦于以下问题:Python isabs函数的具体用法?Python isabs怎么用?Python isabs使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: test_isabs

    def test_isabs(self):
        self.assertIs(posixpath.isabs(""), False)
        self.assertIs(posixpath.isabs("/"), True)
        self.assertIs(posixpath.isabs("/foo"), True)
        self.assertIs(posixpath.isabs("/foo/bar"), True)
        self.assertIs(posixpath.isabs("foo/bar"), False)

        self.assertRaises(TypeError, posixpath.isabs)
开发者ID:CaoYouXin,项目名称:myfirstapicloudapp,代码行数:8,代码来源:test_posixpath.py


示例2: test_isabs

    def test_isabs(self):
        self.assertIs(posixpath.isabs(""), False)
        self.assertIs(posixpath.isabs("/"), True)
        self.assertIs(posixpath.isabs("/foo"), True)
        self.assertIs(posixpath.isabs("/foo/bar"), True)
        self.assertIs(posixpath.isabs("foo/bar"), False)

        self.assertIs(posixpath.isabs(b""), False)
        self.assertIs(posixpath.isabs(b"/"), True)
        self.assertIs(posixpath.isabs(b"/foo"), True)
        self.assertIs(posixpath.isabs(b"/foo/bar"), True)
        self.assertIs(posixpath.isabs(b"foo/bar"), False)
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:12,代码来源:test_posixpath.py


示例3: _is_current_platform_abspath

def _is_current_platform_abspath(path):
    """
    Check if the path is an obsolute path for the current platform.

    :param str path: Path to validate.

    :returns bool: True if absolute for this platform, False otherwise.
    """
    if sys.platform == "win32":
        # ntpath likes to consider a path starting with / to be absolute,
        # but it is not!
        return ntpath.isabs(path) and not posixpath.isabs(path)
    else:
        return posixpath.isabs(path)
开发者ID:adriankrupa,项目名称:tk-core,代码行数:14,代码来源:includes.py


示例4: _subdirectory

 def _subdirectory(self, info, args):
     _, args = cmake_argparse(args, {"EXCLUDE_FROM_ALL": "-"})
     subdir = info.source_relative_path(args[0])
     real_subdir = info.real_path(subdir)
     if posixpath.isabs(subdir):
         info.report(ERROR, "EXTERNAL_SUBDIR", subdir=subdir)
         return
     if not os.path.isdir(real_subdir):
         info.report(ERROR, "MISSING_SUBDIR", subdir=subdir)
         return
     if subdir in info.subdirs:
         info.report(ERROR, "DUPLICATE_SUBDIR", subdir=subdir)
         return
     info.subdirs.add(subdir)
     old_subdir = info.subdir
     old_parent_var = info.parent_var
     old_find_packages = info.find_packages
     info.parent_var = info.var
     info.var = copy(info.var)
     info.find_packages = copy(info.find_packages)
     try:
         info.var["CMAKE_CURRENT_SOURCE_DIR"] = posixpath.join(PathConstants.PACKAGE_SOURCE, subdir)
         info.var["CMAKE_CURRENT_BINARY_DIR"] = posixpath.join(PathConstants.PACKAGE_BINARY, subdir)
         info.generated_files.add(subdir)
         info.subdir = subdir
         self._parse_file(info, os.path.join(real_subdir, "CMakeLists.txt"))
     finally:
         info.var = info.parent_var
         info.parent_var = old_parent_var
         info.subdir = old_subdir
         info.find_packages = old_find_packages
开发者ID:fkie,项目名称:catkin_lint,代码行数:31,代码来源:linter.py


示例5: _include_file

 def _include_file(self, info, args):
     opts, args = cmake_argparse(args, {"OPTIONAL": "-", "RESULT_VARIABLE": "?", "NO_POLICY_SCOPE": "-"})
     if not args:
         return
     if "/" not in args[0] and "." not in args[0]:
         incl_file = "NOTFOUND"
     else:
         incl_file = info.source_relative_path(args[0])
         if incl_file.startswith(PathConstants.DISCOVERED_PATH):
             return
         skip_parsing = False
         if info.manifest.name in self._include_blacklist:
             for glob_pattern in self._include_blacklist[info.manifest.name]:
                 if fnmatch(incl_file, glob_pattern):
                     skip_parsing = True
                     break
         real_file = os.path.join(info.path, os.path.normpath(incl_file))
         if os.path.isfile(real_file):
             if not skip_parsing:
                 self._parse_file(info, real_file)
         else:
             if not opts["OPTIONAL"]:
                 if posixpath.isabs(incl_file):
                     info.report(ERROR, "EXTERNAL_FILE", cmd="include", file=args[0])
                 else:
                     info.report(ERROR, "MISSING_FILE", cmd="include", file=incl_file)
             incl_file = "NOTFOUND"
     if opts["RESULT_VARIABLE"]:
         info.var[opts["RESULT_VARIABLE"]] = incl_file
开发者ID:fkie,项目名称:catkin_lint,代码行数:29,代码来源:linter.py


示例6: _abspath

def _abspath(root, value):
    # not all variables are paths: only absolutize if it looks like a relative path
    if root and \
        (value.startswith('./') or \
        ('/' in value and not (posixpath.isabs(value) or ntpath.isabs(value)))):
        value = os.path.join(root, value)
    return value
开发者ID:Shumberg,项目名称:rez,代码行数:7,代码来源:rex.py


示例7: read_file

def read_file(filename, binary=False):
    """Get the contents of a file contained with qutebrowser.

    Args:
        filename: The filename to open as string.
        binary: Whether to return a binary string.
                If False, the data is UTF-8-decoded.

    Return:
        The file contents as string.
    """
    assert not posixpath.isabs(filename), filename
    assert os.path.pardir not in filename.split(posixpath.sep), filename

    if not binary and filename in _resource_cache:
        return _resource_cache[filename]

    if hasattr(sys, 'frozen'):
        # PyInstaller doesn't support pkg_resources :(
        # https://github.com/pyinstaller/pyinstaller/wiki/FAQ#misc
        fn = os.path.join(os.path.dirname(sys.executable), filename)
        if binary:
            with open(fn, 'rb') as f:
                return f.read()
        else:
            with open(fn, 'r', encoding='utf-8') as f:
                return f.read()
    else:
        data = pkg_resources.resource_string(qutebrowser.__name__, filename)
        if not binary:
            data = data.decode('UTF-8')
        return data
开发者ID:The-Compiler,项目名称:qutebrowser,代码行数:32,代码来源:utils.py


示例8: un_posix

def un_posix(valid_posix_path,drive=None):
    
    if os.name == "posix":
        return valid_posix_path
    
    else:
        global drives
        if not posixpath.isabs(valid_posix_path):
            return valid_posix_path# what to do? for now assert
        assert posixpath.isabs(valid_posix_path), "un_posix() needs an absolute posix style path, not %s" % valid_posix_path
        #drive = get_drive_by_hash(valid_posix_path)
        drive = get_drive(valid_posix_path)
        
        assert drive, "We cannot make this path (%s) local to the platform without knowing the drive" % valid_posix_path
        path = systempath.join(drive,systempath.normpath(valid_posix_path))
        return path
开发者ID:augustomorais,项目名称:Cascadenik,代码行数:16,代码来源:nonposix.py


示例9: on_final

 def on_final(info):
     for pkg in info.export_packages - info.export_dep:
         if info.env.is_known_pkg(pkg):
             if pkg == "message_runtime":
                 if pkg not in info.exec_dep:
                     info.report(ERROR, "MISSING_DEPEND", pkg=pkg, type="run" if info.manifest.package_format < 2 else "exec", file_location=("package.xml", 0))
             else:
                 info.report(ERROR, "MISSING_DEPEND", pkg=pkg, type="run" if info.manifest.package_format < 2 else "build_export", file_location=("package.xml", 0))
     for pkg in (info.find_packages & info.build_dep & info.export_dep) - info.export_packages:
         if re.search(r"_(msg|message)s?(_|$)", pkg) and info.env.is_catkin_pkg(pkg):
             info.report(WARNING, "SUGGEST_CATKIN_DEPEND", pkg=pkg, file_location=info.location_of("catkin_package"))
     if info.export_includes and info.libraries and not info.export_libs:
         info.report(WARNING, "MISSING_EXPORT_LIB", file_location=info.location_of("catkin_package"))
     if info.executables or info.libraries:
         for incl in info.export_includes - info.build_includes:
             info.report(WARNING, "UNUSED_INCLUDE_PATH", path=incl, file_location=info.location_of("catkin_package"))
     for incl in info.export_includes:
         if not info.is_existing_path(incl, check=os.path.isdir, require_source_folder=True):
             info.report(ERROR, "MISSING_INCLUDE_PATH", path=incl, file_location=info.location_of("catkin_package"))
     includes = info.build_includes | info.export_includes
     for d1 in includes:
         if not posixpath.isabs(d1):
             for d2 in includes:
                 if d1.startswith("%s/" % d2):
                     info.report(WARNING, "AMBIGUOUS_INCLUDE_PATH", path=info.report_path(d1), parent_path=info.report_path(d2))
     for lib in info.export_libs:
         if lib in info.targets:
             if info.target_outputs[lib] != lib:
                 info.report(ERROR, "EXPORT_LIB_RENAMED", target=lib, file_location=info.location_of("catkin_package"))
             if lib in info.executables:
                 info.report(ERROR, "EXPORT_LIB_NOT_LIB", target=lib, file_location=info.location_of("catkin_package"))
开发者ID:fkie,项目名称:catkin_lint,代码行数:31,代码来源:build.py


示例10: is_existing_path

 def is_existing_path(self, path, check=os.path.exists, require_source_folder=False, discovered_path_ok=True):
     if self.condition_is_checked("EXISTS %s" % path) or (check == os.path.isdir and self.condition_is_checked("IS_DIRECTORY %s" % path)):
         return True
     tmp = path.replace(os.path.sep, "/")
     if tmp.startswith(PathConstants.PACKAGE_SOURCE):
         tmp = path[len(PathConstants.PACKAGE_SOURCE) + 1:]
     if check(os.path.normpath(os.path.join(self.path, self.subdir, tmp))):
         return True
     tmp = posixpath.normpath(posixpath.join(self.var["CMAKE_CURRENT_SOURCE_DIR"], path.replace(os.path.sep, "/")))
     if tmp.startswith(PathConstants.PACKAGE_SOURCE):
         if not require_source_folder and not posixpath.isabs(path) and tmp[len(PathConstants.PACKAGE_SOURCE) + 1:] in self.generated_files:
             return True
         if not require_source_folder and tmp in self.generated_files:
             return True
         return check(os.path.join(self.path, os.path.normpath(tmp[len(PathConstants.PACKAGE_SOURCE) + 1:])))
     if not require_source_folder and tmp.startswith(PathConstants.PACKAGE_BINARY):
         return tmp[len(PathConstants.PACKAGE_BINARY) + 1:] in self.generated_files
     if not require_source_folder and tmp in self.generated_files:
         return True
     if not require_source_folder and tmp.startswith(PathConstants.CATKIN_DEVEL):
         s = tmp[len(PathConstants.CATKIN_DEVEL) + 1:]
         for t in ["include", "lib", "share", "bin"]:
             if s.startswith(t):
                 return True
     if not require_source_folder and tmp.startswith(PathConstants.CATKIN_INSTALL):
         s = tmp[len(PathConstants.CATKIN_INSTALL) + 1:]
         for t in ["include", "lib", "share", "bin"]:
             if s.startswith(t):
                 return True
     return tmp.startswith(PathConstants.DISCOVERED_PATH) and discovered_path_ok
开发者ID:fkie,项目名称:catkin_lint,代码行数:30,代码来源:linter.py


示例11: Extract

  def Extract(self):
    """Extract the tarfile to the current directory."""
    if self.verbose:
      sys.stdout.write('|' + ('-' * 48) + '|\n')
      sys.stdout.flush()
      dots_outputted = 0

    win32_symlinks = {}
    for m in self.tar:
      if self.verbose:
        cnt = self.read_file.tell()
        curdots = cnt * 50 / self.read_filesize
        if dots_outputted < curdots:
          for dot in xrange(dots_outputted, curdots):
            sys.stdout.write('.')
          sys.stdout.flush()
          dots_outputted = curdots

      # For hardlinks in Windows, we try to use mklink, and instead copy on
      # failure.
      if m.islnk() and sys.platform == 'win32':
        CreateWin32Link(m.name, m.linkname, self.verbose)
      # On Windows we treat symlinks as if they were hard links.
      # Proper Windows symlinks supported by everything can be made with
      # mklink, but only by an Administrator.  The older toolchains are
      # built with Cygwin, so they could use Cygwin-style symlinks; but
      # newer toolchains do not use Cygwin, and nothing else on the system
      # understands Cygwin-style symlinks, so avoid them.
      elif m.issym() and sys.platform == 'win32':
        # For a hard link, the link target (m.linkname) always appears
        # in the archive before the link itself (m.name), so the links
        # can just be made on the fly.  However, a symlink might well
        # appear in the archive before its target file, so there would
        # not yet be any file to hard-link to.  Hence, we have to collect
        # all the symlinks and create them in dependency order at the end.
        linkname = m.linkname
        if not posixpath.isabs(linkname):
          linkname = posixpath.join(posixpath.dirname(m.name), linkname)
        linkname = posixpath.normpath(linkname)
        win32_symlinks[posixpath.normpath(m.name)] = linkname
      # Otherwise, extract normally.
      else:
        self.tar.extract(m)

    win32_symlinks_left = win32_symlinks.items()
    while win32_symlinks_left:
      this_symlink = win32_symlinks_left.pop(0)
      name, linkname = this_symlink
      if linkname in win32_symlinks:
        # The target is itself a symlink not yet created.
        # Wait for it to come 'round on the guitar.
        win32_symlinks_left.append(this_symlink)
      else:
        del win32_symlinks[name]
        CreateWin32Link(name, linkname, self.verbose)

    if self.verbose:
      sys.stdout.write('\n')
      sys.stdout.flush()
开发者ID:dsagal,项目名称:native_client,代码行数:59,代码来源:cygtar.py


示例12: construct_asset_path

 def construct_asset_path(self, asset_path, css_path, output_filename, variant=None):
     """Return a rewritten asset URL for a stylesheet"""
     public_path = self.absolute_path(asset_path, os.path.dirname(css_path).replace('\\', '/'))
     if self.embeddable(public_path, variant):
         return "__EMBED__%s" % public_path
     if not posixpath.isabs(asset_path):
         asset_path = self.relative_path(public_path, output_filename)
     return asset_path
开发者ID:almost,项目名称:django-pipeline,代码行数:8,代码来源:__init__.py


示例13: resolve

    def resolve(self, hdfs_path):
        """Return absolute, normalized path, with special markers expanded.

    :param hdfs_path: Remote path.

    Currently supported markers:

    * `'#LATEST'`: this marker gets expanded to the most recently updated file
      or folder. They can be combined using the `'{N}'` suffix. For example,
      `'foo/#LATEST{2}'` is equivalent to `'foo/#LATEST/#LATEST'`.

    """
        path = hdfs_path
        if not psp.isabs(path):
            if not self.root or not psp.isabs(self.root):
                root = self._get_home_directory("/").json()["Path"]
                self.root = psp.join(root, self.root) if self.root else root
                _logger.debug("Updated root to %r.", self.root)
            path = psp.join(self.root, path)
        path = psp.normpath(path)

        def expand_latest(match):
            """Substitute #LATEST marker."""
            prefix = match.string[: match.start()]
            suffix = ""
            n = match.group(1)  # n as in {N} syntax
            for _ in repeat(None, int(n) if n else 1):
                statuses = self._list_status(psp.join(prefix, suffix)).json()
                candidates = sorted(
                    [
                        (-status["modificationTime"], status["pathSuffix"])
                        for status in statuses["FileStatuses"]["FileStatus"]
                    ]
                )
                if not candidates:
                    raise HdfsError("Cannot expand #LATEST. %r is empty.", prefix)
                elif len(candidates) == 1 and candidates[0][1] == "":
                    raise HdfsError("Cannot expand #LATEST. %r is a file.", prefix)
                suffix = psp.join(suffix, candidates[0][1])
            return "/" + suffix

        path = re.sub(r"/?#LATEST(?:{(\d+)})?(?=/|$)", expand_latest, path)
        # #LATEST expansion (could cache the pattern, but not worth it)

        _logger.debug("Resolved path %r to %r.", hdfs_path, path)
        return path
开发者ID:yonglehou,项目名称:hdfs-1,代码行数:46,代码来源:client.py


示例14: _is_absolute_path

    def _is_absolute_path(self, path):
        if posixpath.isabs(path):
            return True

        if ntpath.isabs(path):
            return True

        return False
开发者ID:4teamwork,项目名称:opengever.core,代码行数:8,代码来源:fileloader.py


示例15: _is_abs

def _is_abs(path):
    """
    Check if path is absolute on any platform.

    :param str path: Path to validate.

    :returns bool: True is absolute on any platform, False otherwise.
    """
    return posixpath.isabs(path) or ntpath.isabs(path)
开发者ID:adriankrupa,项目名称:tk-core,代码行数:9,代码来源:includes.py


示例16: validate_path

def validate_path(path, ctx=None):
    ctx = ctx or validation.Context.raise_on_error(prefix="Invalid path: ")
    if not path:
        ctx.error("not specified")
        return
    if posixpath.isabs(path):
        ctx.error("must not be absolute: %s", path)
    if any(p in (".", "..") for p in path.split(posixpath.sep)):
        ctx.error('must not contain ".." or "." components: %s', path)
开发者ID:rmistry,项目名称:luci-py,代码行数:9,代码来源:validation.py


示例17: am_add_srcdir

def am_add_srcdir(path, am, prefix =""):
    dir = path
    if dir[0] == '$':
        return ""
    elif not posixpath.isabs(dir):
        dir = "$(srcdir)/" + dir
    else:
        return ""
    return prefix+dir
开发者ID:f7753,项目名称:monetdb,代码行数:9,代码来源:am.py


示例18: _make_absolute

    def _make_absolute(self, inpath):
        """Makes the given path absolute if it's not already. It is assumed that the path is
        relative to self._homedir"""
        (scheme, netloc, path, query, fragment) = urlparse.urlsplit(inpath)

        if scheme or posixpath.isabs(path):
            # if a scheme is specified, assume it's absolute.
            return path
        return posixpath.join(get_whoops("/").home(), path)
开发者ID:Mappy,项目名称:luigi,代码行数:9,代码来源:webhdfs.py


示例19: resolve

  def resolve(self, hdfs_path):
    """Return absolute, normalized path, with special markers expanded.

    :param hdfs_path: Remote path.

    Currently supported markers:

    * `'#LATEST'`: this marker gets expanded to the most recently updated file
      or folder. They can be combined using the `'{N}'` suffix. For example,
      `'foo/#LATEST{2}'` is equivalent to `'foo/#LATEST/#LATEST'`.

    """
    path = hdfs_path
    if not posixpath.isabs(path):
      if not self.root:
        raise HdfsError('Path %r is relative but no root found.', path)
      if not posixpath.isabs(self.root):
        raise HdfsError('Non-absolute root found: %r', self.root)
      path = posixpath.join(self.root, path)
    path = posixpath.normpath(path)

    def expand_latest(match):
      """Substitute #LATEST marker."""
      prefix = match.string[:match.start()]
      suffix = ''
      n = match.group(1) # n as in {N} syntax
      for _ in repeat(None, int(n) if n else 1):
        statuses = self._list_status(posixpath.join(prefix, suffix)).json()
        candidates = sorted([
          (-status['modificationTime'], status['pathSuffix'])
          for status in statuses['FileStatuses']['FileStatus']
        ])
        if not candidates:
          raise HdfsError('Cannot expand #LATEST. %r is empty.', prefix)
        elif len(candidates) == 1 and candidates[0][1] == '':
          raise HdfsError('Cannot expand #LATEST. %r is a file.', prefix)
        suffix = posixpath.join(suffix, candidates[0][1])
      return '/' + suffix

    path = re.sub(r'/?#LATEST(?:{(\d+)})?(?=/|$)', expand_latest, path)
    # #LATEST expansion (could cache the pattern, but not worth it)

    self._logger.debug('Resolved path %r to %r.', hdfs_path, path)
    return quote(path, '/=')
开发者ID:jesseliu77,项目名称:hdfs,代码行数:44,代码来源:client.py


示例20: handleMatch

    def handleMatch(self, m):
        try:
            ref = m.group(9)
        except IndexError:
            ref = None
        shortref = False
        if not ref:
            # if we got something like "[Google][]" or "[Google]"
            # we'll use "google" as the id
            ref = m.group(2)
            shortref = True

        # Clean up linebreaks in ref
        ref = self.NEWLINE_CLEANUP_RE.sub(' ', ref)

        text = m.group(2)
        id = ref.lower()

        if id in self.markdown.references:
            href, title = self.markdown.references[id]
        else:
            anchor = None
            if '#' in ref:
                ref, anchor = ref.split('#', 1)
            this = self.markdown.this
            if not posixpath.isabs(ref):
                # treat empty ref as reference to current page
                if not ref: 
                    ref = this['components'][-1]
                rootrelpath = '/' + '/'.join(this['components'][:-1])
                id = posixpath.normpath(posixpath.join(rootrelpath, ref))
                id = id.lower()
            else:
                id = ref.lower()
            ref = ref.lower()
            if ref in self.markdown.site['reflinks']:
                if (ref != id) and (id in self.markdown.site['reflinks']):
                    raise UrubuError(_error.ambig_ref_md, msg=ref, fn=this['fn'])
                id = ref
            if id in self.markdown.site['reflinks']:
                item = self.markdown.site['reflinks'][id]
                href, title = item['url'], item['title']
                if shortref:
                    text = title
                    if anchor is not None:
                        text = anchor
                if anchor is not None:
                    anchor = toc.slugify(anchor, '-')
                    href = '%s#%s' % (href, anchor)
                    anchorref = '%s#%s' % (id, anchor)
                    self.markdown.this['_anchorrefs'].add(anchorref)
            else:  # ignore undefined refs
                urubu_warn(_warning.undef_ref_md, msg=ref, fn=this['fn'])
                return None

        return self.makeTag(href, title, text)
开发者ID:ayenzky,项目名称:urubu,代码行数:56,代码来源:md_extensions.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python posixpath.isdir函数代码示例发布时间:2022-05-25
下一篇:
Python posixpath.expanduser函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap