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


Python nturl2path.url2pathname方法代码示例

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


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

示例1: open_local_file

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
def open_local_file(self, req):
        import future.backports.email.utils as email_utils
        import mimetypes
        host = req.host
        filename = req.selector
        localfile = url2pathname(filename)
        try:
            stats = os.stat(localfile)
            size = stats.st_size
            modified = email_utils.formatdate(stats.st_mtime, usegmt=True)
            mtype = mimetypes.guess_type(filename)[0]
            headers = email.message_from_string(
                'Content-type: %s\nContent-length: %d\nLast-modified: %s\n' %
                (mtype or 'text/plain', size, modified))
            if host:
                host, port = splitport(host)
            if not host or \
                (not port and _safe_gethostbyname(host) in self.get_names()):
                if host:
                    origurl = 'file://' + host + filename
                else:
                    origurl = 'file://' + filename
                return addinfourl(open(localfile, 'rb'), headers, origurl)
        except OSError as exp:
            # users shouldn't expect OSErrors coming from urlopen()
            raise URLError(exp)
        raise URLError('file not on local host') 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:29,代码来源:request.py

示例2: url2pathname

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
def url2pathname(pathname):
        """OS-specific conversion from a relative URL of the 'file' scheme
        to a file system path; not recommended for general use."""
        return unquote(pathname) 
开发者ID:Soft8Soft,项目名称:verge3d-blender-addon,代码行数:6,代码来源:request.py

示例3: open_local_file

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
def open_local_file(self, url):
        """Use local file."""
        import mimetypes, mimetools, email.utils
        try:
            from cStringIO import StringIO
        except ImportError:
            from StringIO import StringIO
        host, file = splithost(url)
        localname = url2pathname(file)
        try:
            stats = os.stat(localname)
        except OSError, e:
            raise IOError(e.errno, e.strerror, e.filename) 
开发者ID:glmcdona,项目名称:meddle,代码行数:15,代码来源:urllib.py

示例4: test_basic

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
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)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:14,代码来源:test_urllib.py

示例5: test_quoting

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
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)) 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:28,代码来源:test_urllib.py

示例6: test_converting_drive_letter

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
def test_converting_drive_letter(self):
        self.assertEqual(url2pathname("///C|"), 'C:')
        self.assertEqual(url2pathname("///C:"), 'C:')
        self.assertEqual(url2pathname("///C|/"), 'C:\\') 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:6,代码来源:test_urllib.py

示例7: test_converting_when_no_drive_letter

# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import url2pathname [as 别名]
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' '\\') 
开发者ID:hughperkins,项目名称:kgsgo-dataset-preprocessor,代码行数:6,代码来源:test_urllib.py


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