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

Python posixpath.realpath函数代码示例

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

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



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

示例1: test_realpath_resolve_before_normalizing

        def test_realpath_resolve_before_normalizing(self):
            # Bug #990669: Symbolic links should be resolved before we
            # normalize the path. E.g.: if we have directories 'a', 'k' and 'y'
            # in the following hierarchy:
            # a/k/y
            #
            # and a symbolic link 'link-y' pointing to 'y' in directory 'a',
            # then realpath("link-y/..") should return 'k', not 'a'.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.mkdir(ABSTFN + "/k/y")
                os.symlink(ABSTFN + "/k/y", ABSTFN + "/link-y")

                # Absolute path.
                self.assertEqual(realpath(ABSTFN + "/link-y/.."), ABSTFN + "/k")
                # Relative path.
                with support.change_cwd(dirname(ABSTFN)):
                    self.assertEqual(realpath(basename(ABSTFN) + "/link-y/.."),
                                     ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "/link-y")
                safe_rmdir(ABSTFN + "/k/y")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:25,代码来源:test_posixpath.py


示例2: __init__

 def __init__(self, src, dst, path = None):
     if path is not None:
         src = posixpath.join(path, src)
         dst = posixpath.join(path, dst)
     self.__src = posixpath.realpath(src)
     self.__dst = posixpath.realpath(dst)
     os.rename(src, dst)
开发者ID:litaoshao,项目名称:python-mirbuild,代码行数:7,代码来源:test_cmake.py


示例3: test_realpath_basic

 def test_realpath_basic(self):
     # Basic operation.
     try:
         os.symlink(ABSTFN+"1", ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         test_support.unlink(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:7,代码来源:test_posixpath.py


示例4: test_realpath_basic

 def test_realpath_basic(self):
     # Basic operation.
     try:
         os.symlink(ABSTFN+"1", ABSTFN)
         self.assertEqual(realpath(ABSTFN), ABSTFN+"1")
     finally:
         self.safe_remove(ABSTFN)
开发者ID:Alex-CS,项目名称:sonify,代码行数:7,代码来源:test_posixpath.py


示例5: test_realpath_resolve_first

        def test_realpath_resolve_first(self):
            # Bug #1213894: The first component of the path, if not absolute,
            # must be resolved too.

            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/k")
                os.symlink(ABSTFN, ABSTFN + "link")
                with support.change_cwd(dirname(ABSTFN)):
                    base = basename(ABSTFN)
                    self.assertEqual(realpath(base + "link"), ABSTFN)
                    self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
            finally:
                test_support.unlink(ABSTFN + "link")
                safe_rmdir(ABSTFN + "/k")
                safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:16,代码来源:test_posixpath.py


示例6: test_realpath_deep_recursion

        def test_realpath_deep_recursion(self):
            depth = 10
            try:
                os.mkdir(ABSTFN)
                for i in range(depth):
                    os.symlink('/'.join(['%d' % i] * 10), ABSTFN + '/%d' % (i + 1))
                os.symlink('.', ABSTFN + '/0')
                self.assertEqual(realpath(ABSTFN + '/%d' % depth), ABSTFN)

                # Test using relative path as well.
                with support.change_cwd(ABSTFN):
                    self.assertEqual(realpath('%d' % depth), ABSTFN)
            finally:
                for i in range(depth + 1):
                    test_support.unlink(ABSTFN + '/%d' % i)
                safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:16,代码来源:test_posixpath.py


示例7: make_path_absolute

 def make_path_absolute(self, path):
     """
     Given a relative url found inside the CSS file we're currently serving,
     return an absolute form of that URL.
     """
     env = self.request.environ
     pinfo = posixpath.dirname(env['PATH_INFO'])
     return posixpath.realpath(env['SCRIPT_NAME'] + pinfo + '/' + path)
开发者ID:btubbs,项目名称:spa,代码行数:8,代码来源:smart.py


示例8: test_realpath_deep_recursion

    def test_realpath_deep_recursion(self):
        depth = 10
        old_path = abspath(".")
        try:
            os.mkdir(ABSTFN)
            for i in range(depth):
                os.symlink("/".join(["%d" % i] * 10), ABSTFN + "/%d" % (i + 1))
            os.symlink(".", ABSTFN + "/0")
            self.assertEqual(realpath(ABSTFN + "/%d" % depth), ABSTFN)

            # Test using relative path as well.
            os.chdir(ABSTFN)
            self.assertEqual(realpath("%d" % depth), ABSTFN)
        finally:
            os.chdir(old_path)
            for i in range(depth + 1):
                support.unlink(ABSTFN + "/%d" % i)
            safe_rmdir(ABSTFN)
开发者ID:pierreorz,项目名称:web_ctp,代码行数:18,代码来源:test_posixpath.py


示例9: test_realpath_resolve_first

    def test_realpath_resolve_first(self) -> None:
        # Bug #1213894: The first component of the path, if not absolute,
        # must be resolved too.

        try:
            old_path = abspath('.')
            os.mkdir(ABSTFN)
            os.mkdir(ABSTFN + "/k")
            os.symlink(ABSTFN, ABSTFN + "link")
            os.chdir(dirname(ABSTFN))

            base = basename(ABSTFN)
            self.assertEqual(realpath(base + "link"), ABSTFN)
            self.assertEqual(realpath(base + "link/k"), ABSTFN + "/k")
        finally:
            os.chdir(old_path)
            support.unlink(ABSTFN + "link")
            safe_rmdir(ABSTFN + "/k")
            safe_rmdir(ABSTFN)
开发者ID:kivipe,项目名称:mypy,代码行数:19,代码来源:test_posixpath.py


示例10: test_realpath_repeated_indirect_symlinks

 def test_realpath_repeated_indirect_symlinks(self):
     # Issue #6975.
     try:
         os.mkdir(ABSTFN)
         os.symlink("../" + basename(ABSTFN), ABSTFN + "/self")
         os.symlink("self/self/self", ABSTFN + "/link")
         self.assertEqual(realpath(ABSTFN + "/link"), ABSTFN)
     finally:
         support.unlink(ABSTFN + "/self")
         support.unlink(ABSTFN + "/link")
         safe_rmdir(ABSTFN)
开发者ID:pierreorz,项目名称:web_ctp,代码行数:11,代码来源:test_posixpath.py


示例11: test_realpath_repeated_indirect_symlinks

 def test_realpath_repeated_indirect_symlinks(self):
     # Issue #6975.
     try:
         os.mkdir(ABSTFN)
         os.symlink('../' + basename(ABSTFN), ABSTFN + '/self')
         os.symlink('self/self/self', ABSTFN + '/link')
         self.assertEqual(realpath(ABSTFN + '/link'), ABSTFN)
     finally:
         test_support.unlink(ABSTFN + '/self')
         test_support.unlink(ABSTFN + '/link')
         safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:11,代码来源:test_posixpath.py


示例12: test_realpath_symlink_loops

        def test_realpath_symlink_loops(self):
            # Bug #930024, return the path unchanged if we get into an infinite
            # symlink loop.
            try:
                old_path = abspath('.')
                os.symlink(ABSTFN, ABSTFN)
                self.assertEqual(realpath(ABSTFN), ABSTFN)

                os.symlink(ABSTFN+"1", ABSTFN+"2")
                os.symlink(ABSTFN+"2", ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"1"), ABSTFN+"1")
                self.assertEqual(realpath(ABSTFN+"2"), ABSTFN+"2")

                # Test using relative path as well.
                os.chdir(dirname(ABSTFN))
                self.assertEqual(realpath(basename(ABSTFN)), ABSTFN)
            finally:
                os.chdir(old_path)
                test_support.unlink(ABSTFN)
                test_support.unlink(ABSTFN+"1")
                test_support.unlink(ABSTFN+"2")
开发者ID:CaoYouXin,项目名称:myfirstapicloudapp,代码行数:21,代码来源:test_posixpath.py


示例13: test_realpath_curdir

    def test_realpath_curdir(self):
        self.assertEqual(realpath('.'), os.getcwd())
        self.assertEqual(realpath('./.'), os.getcwd())
        self.assertEqual(realpath('/'.join(['.'] * 100)), os.getcwd())

        self.assertEqual(realpath(b'.'), os.getcwdb())
        self.assertEqual(realpath(b'./.'), os.getcwdb())
        self.assertEqual(realpath(b'/'.join([b'.'] * 100)), os.getcwdb())
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:8,代码来源:test_posixpath.py


示例14: test_realpath_pardir

    def test_realpath_pardir(self):
        self.assertEqual(realpath('..'), dirname(os.getcwd()))
        self.assertEqual(realpath('../..'), dirname(dirname(os.getcwd())))
        self.assertEqual(realpath('/'.join(['..'] * 100)), '/')

        self.assertEqual(realpath(b'..'), dirname(os.getcwdb()))
        self.assertEqual(realpath(b'../..'), dirname(dirname(os.getcwdb())))
        self.assertEqual(realpath(b'/'.join([b'..'] * 100)), b'/')
开发者ID:chidea,项目名称:GoPythonDLLWrapper,代码行数:8,代码来源:test_posixpath.py


示例15: test_realpath_resolve_parents

        def test_realpath_resolve_parents(self):
            # We also need to resolve any symlinks in the parents of a relative
            # path passed to realpath. E.g.: current working directory is
            # /usr/doc with 'doc' being a symlink to /usr/share/doc. We call
            # realpath("a"). This should return /usr/share/doc/a/.
            try:
                os.mkdir(ABSTFN)
                os.mkdir(ABSTFN + "/y")
                os.symlink(ABSTFN + "/y", ABSTFN + "/k")

                with support.change_cwd(ABSTFN + "/k"):
                    self.assertEqual(realpath("a"), ABSTFN + "/y/a")
            finally:
                test_support.unlink(ABSTFN + "/k")
                safe_rmdir(ABSTFN + "/y")
                safe_rmdir(ABSTFN)
开发者ID:Logotrop,项目名称:trida,代码行数:16,代码来源:test_posixpath.py


示例16: _hadoop_prefix_from_bin

def _hadoop_prefix_from_bin(hadoop_bin):
    """Given a path to the hadoop binary, return the path of the implied
    hadoop home, or None if we don't know.

    Don't return the parent directory of directories in the default
    path (not ``/``, ``/usr``, or ``/usr/local``).
    """
    # resolve unqualified binary name (relative paths are okay)
    if '/' not in hadoop_bin:
        hadoop_bin = which(hadoop_bin)
        if not hadoop_bin:
            return None

    # use parent of hadoop_bin's directory
    hadoop_home = posixpath.abspath(
        posixpath.join(posixpath.realpath(posixpath.dirname(hadoop_bin)), '..')
    )

    if hadoop_home in _BAD_HADOOP_HOMES:
        return None

    return hadoop_home
开发者ID:okomestudio,项目名称:mrjob,代码行数:22,代码来源:hadoop.py


示例17: convert_css_url

    def convert_css_url(self, css_url):
        split_url = urlsplit(css_url)
        url_path = split_url.path
        if not url_path.startswith('/'):
            abs_url_path = self.make_path_absolute(url_path)
        else:
            abs_url_path = posixpath.realpath(url_path)

        prefix = self.get_url_prefix()

        # now make the path as it would be passed in to this handler when
        # requested from the web.  From there we can use existing methods on the
        # class to resolve to a real file.
        _, _, content_filepath = abs_url_path.partition(prefix)
        content_filepath = clean_path(content_filepath)

        content_file_hash = self.hash_cache.get_path_hash(content_filepath)
        if content_file_hash is None:
            content_file = self.get_file(content_filepath)
            if content_file is None:
                return 'NOT FOUND: "%s"' % url_path
            try:
                content_file_hash = get_hash(content_file.handle)
            finally:
                content_file.handle.close()
        parts = list(split_url)
        parts[2] = add_hash_to_filepath(url_path, content_file_hash)

        url = urlunsplit(parts)

        # Special casing for a @font-face hack, like url(myfont.eot?#iefix")
        # http://www.fontspring.com/blog/the-new-bulletproof-font-face-syntax
        if '?#' in css_url:
            parts = list(urlsplit(url))
            if not parts[3]:
                parts[2] += '?'
            url = urlunsplit(parts)
        return url
开发者ID:btubbs,项目名称:spa,代码行数:38,代码来源:smart.py


示例18: testAbsolutifies

 def testAbsolutifies(self):
   self.assertPlatformSpecificLogdirParsing(
       posixpath, 'lol/cat', {posixpath.realpath('lol/cat'): None})
   self.assertPlatformSpecificLogdirParsing(
       ntpath, 'lol\\cat', {ntpath.realpath('lol\\cat'): None})
开发者ID:jtagscherer,项目名称:tensorboard,代码行数:5,代码来源:application_test.py


示例19: render_fish

    def render_fish(self):
        template = TEMPLATES["fish"]

        script_path = posixpath.realpath(self._args.script_name)
        script_name = os.path.basename(script_path)
        aliases = [script_name]
        aliases += self.option("alias")

        function = self._generate_function_name(script_name, script_path)

        global_options = set()
        commands_descriptions = {}
        options_descriptions = {}
        commands_options_descriptions = {}
        commands_options = {}
        for option in self.application.config.options.values():
            options_descriptions["--" + option.long_name] = self.io.remove_format(
                option.description
            )
            global_options.add("--" + option.long_name)

        for command in self.application.commands:
            command_config = command.config
            if not command_config.is_enabled() or command_config.is_hidden():
                continue

            command_options = []
            commands_options_descriptions[command_config.name] = {}
            commands_descriptions[command_config.name] = self._io.remove_format(
                command_config.description
            )

            options = command_config.options
            for name in sorted(options.keys()):
                option = options[name]
                name = "--" + option.long_name
                description = self._io.remove_format(option.description)
                command_options.append(name)
                options_descriptions[name] = description
                commands_options_descriptions[command_config.name][name] = description

            commands_options[command_config.name] = command_options

        opts = []
        for opt in sorted(global_options):
            opts.append(
                "complete -c {} -n '__fish{}_no_subcommand' "
                "-l {} -d '{}'".format(
                    script_name,
                    function,
                    opt[2:],
                    options_descriptions[opt].replace("'", "\\'"),
                )
            )

        cmds_names = sorted(list(commands_options.keys()))

        cmds = []
        cmds_opts = []
        for i, cmd in enumerate(cmds_names):
            cmds.append(
                "complete -c {} -f -n '__fish{}_no_subcommand' "
                "-a {} -d '{}'".format(
                    script_name,
                    function,
                    cmd,
                    commands_descriptions[cmd].replace("'", "\\'"),
                )
            )

            cmds_opts += ["# {}".format(cmd)]
            options = set(commands_options[cmd]).difference(global_options)
            options = sorted(options)

            for opt in options:
                cmds_opts.append(
                    "complete -c {} -A -n '__fish_seen_subcommand_from {}' "
                    "-l {} -d '{}'".format(
                        script_name,
                        cmd,
                        opt[2:],
                        commands_options_descriptions[cmd][opt].replace("'", "\\'"),
                    )
                )

            if i < len(cmds_names) - 1:
                cmds_opts.append("")

        output = template % {
            "script_name": script_name,
            "function": function,
            "cmds_names": " ".join(cmds_names),
            "opts": "\n".join(opts),
            "cmds": "\n".join(cmds),
            "cmds_opts": "\n".join(cmds_opts),
        }

        return output
开发者ID:sdispater,项目名称:cleo,代码行数:98,代码来源:completions_command.py


示例20: have_dpkg

    pass

def have_dpkg():
    try:
        BPY.buildarch()
        return True
    except Exception:
        return False

def tar_ignore_supported():
    output = subprocess.Popen(['dpkg-source', '--version'], stdout=subprocess.PIPE).communicate()[0]
    m = re.search('version\s+(\d+(?:\.\d+)+)', output)
    v = re.split('\.', m.group(1))
    return int(v[0]) > 1 or (int(v[0]) == 1 and int(v[1]) > 14)

LIB_a = posixpath.realpath('cmake/a')
LIB_b = posixpath.realpath('cmake/b')

BPY_std = """import mirbuild
mirbuild.CMakeProject('test').run()
"""

BPY_dep = """import mirbuild
project = mirbuild.CMakeProject('test')
project.depends('foo', 'oh-my')
project.define('HAVE_LIB_A')
project.define('HAVE_LIB_B')
project.run()
"""

BPY_ver = """import mirbuild
开发者ID:litaoshao,项目名称:python-mirbuild,代码行数:31,代码来源:test_cmake.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python posixpath.relpath函数代码示例发布时间:2022-05-25
下一篇:
Python posixpath.pjoin函数代码示例发布时间: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