python类url2pathname()的实例源码

client.py 文件源码 项目:drastic-cli 作者: UMD-DRASTIC 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def normalize_cdmi_url(self, path):
        """Normalize URL path relative to current path and return.

        :arg path: path relative to current path
        :returns: absolute CDMI URL

        """
        # Turn URL path into OS path for manipulation
        mypath = url2pathname(path)
        if not os.path.isabs(mypath):
            mypath = os.path.join(url2pathname(self.pwd()), mypath)
        # normalize path
        mypath = os.path.normpath(mypath)
        if path.endswith(os.path.sep) and not mypath.endswith(os.path.sep):
            mypath += os.path.sep
        # if isinstance(mypath, str):
        #    mypath = mypath.encode('utf8')
        url = self.cdmi_url + pathname2url(mypath)
        return url
content_helpers.py 文件源码 项目:djangocms-spa 作者: dreipol 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def get_partial_names_for_template(template=None, get_all=True, requested_partials=None):
    template = template or settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE

    if requested_partials:
        # Transform the requested partials into a list
        requested_partials = url2pathname(requested_partials).split(',')
    else:
        requested_partials = []

    try:
        partials = settings.DJANGOCMS_SPA_TEMPLATES[template]['partials']
    except KeyError:
        try:
            default_template_path = settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE
            partials = settings.DJANGOCMS_SPA_TEMPLATES[default_template_path]['partials']
        except KeyError:
            partials = []

    if get_all:
        return partials
    else:
        return [partial for partial in partials if partial in requested_partials]
py3compat.py 文件源码 项目:MIT-Thesis 作者: alec-heif 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def url2path(url):
        return url2pathname(urlparse(url).path)
py3compat.py 文件源码 项目:MIT-Thesis 作者: alec-heif 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def url2path(url):
        return urllib.url2pathname(urlparse(url).path)
util.py 文件源码 项目:DXMate 作者: jtowers 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def uri_to_filename(self, uri: str) -> str:
        return url2pathname(urlparse(uri).path)
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_basic(self):
        # Make sure simple tests pass
        expected_path = os.path.join("parts", "of", "a", "path")
        expected_url = "parts/of/a/path"
        result = urllib_request.pathname2url(expected_path)
        self.assertEqual(expected_url, result,
                         "pathname2url() failed; %s != %s" %
                         (result, expected_url))
        result = urllib_request.url2pathname(expected_url)
        self.assertEqual(expected_path, result,
                         "url2pathame() failed; %s != %s" %
                         (result, expected_path))
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_quoting(self):
        # Test automatic quoting and unquoting works for pathnam2url() and
        # url2pathname() respectively
        given = os.path.join("needs", "quot=ing", "here")
        expect = "needs/%s/here" % urllib_parse.quote("quot=ing")
        result = urllib_request.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        expect = given
        result = urllib_request.url2pathname(result)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result))
        given = os.path.join("make sure", "using_quote")
        expect = "%s/using_quote" % urllib_parse.quote("make sure")
        result = urllib_request.pathname2url(given)
        self.assertEqual(expect, result,
                         "pathname2url() failed; %s != %s" %
                         (expect, result))
        given = "make+sure/using_unquote"
        expect = os.path.join("make+sure", "using_unquote")
        result = urllib_request.url2pathname(given)
        self.assertEqual(expect, result,
                         "url2pathname() failed; %s != %s" %
                         (expect, result))
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_ntpath(self):
        given = ('/C:/', '///C:/', '/C|//')
        expect = 'C:\\'
        for url in given:
            result = urllib_request.url2pathname(url)
            self.assertEqual(expect, result,
                             'urllib_request..url2pathname() failed; %s != %s' %
                             (expect, result))
        given = '///C|/path'
        expect = 'C:\\path'
        result = urllib_request.url2pathname(given)
        self.assertEqual(expect, result,
                         'urllib_request.url2pathname() failed; %s != %s' %
                         (expect, result))
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def test_converting_drive_letter(self):
        self.assertEqual(url2pathname("///C|"), 'C:')
        self.assertEqual(url2pathname("///C:"), 'C:')
        self.assertEqual(url2pathname("///C|/"), 'C:\\')
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_converting_when_no_drive_letter(self):
        # cannot end a raw string in \
        self.assertEqual(url2pathname("///C/test/"), r'\\\C\test' '\\')
        self.assertEqual(url2pathname("////C/test/"), r'\\C\test' '\\')
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_non_ascii_drive_letter(self):
        self.assertRaises(IOError, url2pathname, "///\u00e8|/")
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_roundtrip_url2pathname(self):
        list_of_paths = ['C:',
                         r'\\\C\test\\',
                         r'C:\foo\bar\spam.foo'
                         ]
        for path in list_of_paths:
            self.assertEqual(url2pathname(pathname2url(path)), path)
test_urllib_toplevel.py 文件源码 项目:packaging 作者: blockstack 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_roundtrip_pathname2url(self):
        list_of_paths = ['///C:',
                         '/////folder/test/',
                         '///C:/foo/bar/spam.foo']
        for path in list_of_paths:
            self.assertEqual(pathname2url(url2pathname(path)), path)
client.py 文件源码 项目:drastic-cli 作者: UMD-DRASTIC 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def normalize_admin_url(self, path):
        """Normalize URL path.

        :arg path: path relative to current path
        :returns: absolute Admin URL

        """
        # Turn URL path into OS path for manipulation
        mypath = url2pathname(path)
        if not os.path.isabs(mypath):
            mypath = '/' + mypath
        url = self.admin_url + mypath
        return url
url.py 文件源码 项目:LSP 作者: tomv564 项目源码 文件源码 阅读 53 收藏 0 点赞 0 评论 0
def uri_to_filename(uri: str) -> str:
    return url2pathname(urlparse(uri).path)
__init__.py 文件源码 项目:pycam 作者: SebKuzminsky 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def get_path(self):
        encoded_path = self._uri.path
        if get_platform() == OSPlatform.WINDOWS:
            # prepend "netloc" (the drive letter - e.g. "c:")
            encoded_path = self._uri.netloc + encoded_path
        # decode all special characters like "%20" and replace "/" with "\\" (Windows)
        return url2pathname(encoded_path)
urlpath.py 文件源码 项目:WhatTheHack 作者: Sylphias 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def nativejoin(base, path):
    """
    Joins two paths - returning a native file path.

    Given a base path and a relative location, (in posix format)
    return a file path in a (relatively) OS native way.
    """
    return url2pathname(pathjoin(base, path))
GDebiGtk.py 文件源码 项目:gdebi 作者: linuxmint 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_file_path_from_dnd_dropped_uri(self, uri):
        """ helper to get a useful path from a drop uri"""
        path = url2pathname(uri) # escape special chars
        path = path.strip('\r\n\x00') # remove \r\n and NULL
        # get the path to file
        if path.startswith('file:\\\\\\'): # windows
            path = path[8:] # 8 is len('file:///')
        elif path.startswith('file://'): # nautilus, rox
            path = path[7:] # 7 is len('file://')
        elif path.startswith('file:'): # xffm
            path = path[5:] # 5 is len('file:')
        return path


问题


面经


文章

微信
公众号

扫码关注公众号