本文整理汇总了Python中nturl2path.pathname2url方法的典型用法代码示例。如果您正苦于以下问题:Python nturl2path.pathname2url方法的具体用法?Python nturl2path.pathname2url怎么用?Python nturl2path.pathname2url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类nturl2path
的用法示例。
在下文中一共展示了nturl2path.pathname2url方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pathname2url
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def pathname2url(pathname):
"""OS-specific conversion from a file system path to a relative URL
of the 'file' scheme; not recommended for general use."""
return quote(pathname)
# This really consists of two pieces:
# (1) a class which handles opening of all sorts of URLs
# (plus assorted utilities etc.)
# (2) a set of functions for parsing URLs
# XXX Should these be separated out into different modules?
示例2: pathname2url
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def pathname2url(pathname):
"""OS-specific conversion from a file system path to a relative URL
of the 'file' scheme; not recommended for general use."""
return quote(pathname)
# This really consists of two pieces:
# (1) a class which handles opening of all sorts of URLs
# (plus assorted utilities etc.)
# (2) a set of functions for parsing URLs
# XXX Should these be separated out into different modules?
# Shortcut for basic usage
示例3: test_html_doc
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def test_html_doc(self):
result, doc_loc = get_pydoc_html(pydoc_mod)
mod_file = inspect.getabsfile(pydoc_mod)
if sys.platform == 'win32':
import nturl2path
mod_url = nturl2path.pathname2url(mod_file)
else:
mod_url = mod_file
expected_html = expected_html_pattern % (
(mod_url, mod_file, doc_loc) +
expected_html_data_docstrings)
if result != expected_html:
print_diffs(expected_html, result)
self.fail("outputs are not equal, see diff above")
示例4: constructLocalFileUrl
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def constructLocalFileUrl(self, filePath):
filePath = os.path.abspath(filePath)
try:
filePath.encode("utf-8")
except UnicodeEncodeError:
raise unittest.SkipTest("filePath is not encodable to utf8")
return "file://%s" % urllib_request.pathname2url(filePath)
示例5: test_basic
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [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))
示例6: test_quoting
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [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))
示例7: test_roundtrip_url2pathname
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
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)
示例8: test_converting_when_no_drive_letter
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def test_converting_when_no_drive_letter(self):
self.assertEqual(pathname2url(r"\\\folder\test" "\\"),
'/////folder/test/')
self.assertEqual(pathname2url(r"\\folder\test" "\\"),
'////folder/test/')
self.assertEqual(pathname2url(r"\folder\test" "\\"),
'/folder/test/')
示例9: test_simple_compare
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def test_simple_compare(self):
self.assertEqual(pathname2url(r'C:\foo\bar\spam.foo'),
"///C:/foo/bar/spam.foo" )
示例10: test_long_drive_letter
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def test_long_drive_letter(self):
self.assertRaises(IOError, pathname2url, "XX:\\")
示例11: test_roundtrip_pathname2url
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
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)
示例12: constructLocalFileUrl
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def constructLocalFileUrl(self, filePath):
filePath = os.path.abspath(filePath)
try:
filePath.encode("utf-8")
except UnicodeEncodeError:
raise unittest.SkipTest("filePath is not encodable to utf8")
return "file://%s" % urllib.request.pathname2url(filePath)
示例13: test_basic
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [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))
示例14: test_quoting
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [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))
示例15: test_converting_drive_letter
# 需要导入模块: import nturl2path [as 别名]
# 或者: from nturl2path import pathname2url [as 别名]
def test_converting_drive_letter(self):
self.assertEqual(pathname2url("C:"), '///C:')
self.assertEqual(pathname2url("C:\\"), '///C:')