本文整理匯總了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)