本文整理汇总了Python中macurl2path.url2pathname方法的典型用法代码示例。如果您正苦于以下问题:Python macurl2path.url2pathname方法的具体用法?Python macurl2path.url2pathname怎么用?Python macurl2path.url2pathname使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类macurl2path
的用法示例。
在下文中一共展示了macurl2path.url2pathname方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_url2pathname
# 需要导入模块: import macurl2path [as 别名]
# 或者: from macurl2path import url2pathname [as 别名]
def test_url2pathname(self):
self.assertEqual(":index.html", macurl2path.url2pathname("index.html"))
self.assertEqual(":bar:index.html", macurl2path.url2pathname("bar/index.html"))
self.assertEqual("foo:bar:index.html", macurl2path.url2pathname("/foo/bar/index.html"))
self.assertEqual("foo:bar", macurl2path.url2pathname("/foo/bar/"))
self.assertEqual("", macurl2path.url2pathname("/"))
self.assertRaises(RuntimeError, macurl2path.url2pathname, "http://foo.com")
self.assertEqual("index.html", macurl2path.url2pathname("///index.html"))
self.assertRaises(RuntimeError, macurl2path.url2pathname, "//index.html")
self.assertEqual(":index.html", macurl2path.url2pathname("./index.html"))
self.assertEqual(":index.html", macurl2path.url2pathname("foo/../index.html"))
self.assertEqual("::index.html", macurl2path.url2pathname("../index.html"))
示例2: url2pathname
# 需要导入模块: import macurl2path [as 别名]
# 或者: from macurl2path 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)
示例3: retrieve
# 需要导入模块: import macurl2path [as 别名]
# 或者: from macurl2path import url2pathname [as 别名]
def retrieve(self, url, filename=None, reporthook=None, data=None):
"""retrieve(url) returns (filename, headers) for a local object
or (tempfilename, headers) for a remote object."""
url = unwrap(toBytes(url))
if self.tempcache and url in self.tempcache:
return self.tempcache[url]
type, url1 = splittype(url)
if filename is None and (not type or type == 'file'):
try:
fp = self.open_local_file(url1)
hdrs = fp.info()
fp.close()
return url2pathname(splithost(url1)[1]), hdrs
except IOError, msg:
pass
示例4: open_local_file
# 需要导入模块: import macurl2path [as 别名]
# 或者: from macurl2path 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)