本文整理汇总了Python中iktomi.web.reverse.URL.from_url方法的典型用法代码示例。如果您正苦于以下问题:Python URL.from_url方法的具体用法?Python URL.from_url怎么用?Python URL.from_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iktomi.web.reverse.URL
的用法示例。
在下文中一共展示了URL.from_url方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_broken_idna
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_broken_idna(self):
src = u'http://xn--.xn--p1ai/'
url = URL.from_url(src.encode('utf-8'))
self.assertEqual(url.get_readable(),
u'http://xn--.рф/')
self.assertEqual(str(url), src)
url = URL.from_url(src)
self.assertEqual(url.get_readable(),
u'http://xn--.рф/')
示例2: test_from_url_idna
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_idna(self):
src = (u'http://xn--80aswg.xn--p1ai'
u'/%D1%83%D1%80%D0%BB/'
u'?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA'
u'#%D1%8F%D0%BA%D0%BE%D1%80%D1%8C')
url = URL.from_url(src.encode('utf-8'))
self.assertEqual(url.get_readable(),
u'http://сайт.рф/урл/?q=поиск#якорь')
url = URL.from_url(src)
self.assertEqual(url.get_readable(),
u'http://сайт.рф/урл/?q=поиск#якорь')
示例3: test_from_url_path
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_path(self):
url = URL.from_url('/url?a=1&b=2&b=3')
self.assertEqual(url.schema, 'http')
self.assertEqual(url.host, '')
self.assertEqual(url.port, '')
self.assertEqual(url.path, '/url')
self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')])
示例4: test_from_url_unicode
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_unicode(self):
url = URL.from_url(u'http://сайт.рф/', show_host=False)
self.assertEqual(url.schema, 'http')
self.assertEqual(url.host, u'сайт.рф')
self.assertEqual(url.port, '')
self.assertEqual(url.path, '/')
self.assertEqual(url.show_host, False)
示例5: test_copy_url
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_copy_url(self):
url_orig = URL.from_url(u"http://test.ru/тест?arg=value#anchor")
url_copy = copy.copy(url_orig)
self.assertEqual(str(url_orig), str(url_copy))
url_deepcopy = copy.deepcopy(url_orig)
self.assertEqual(str(url_orig), str(url_deepcopy))
示例6: test_from_url
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url(self):
url = URL.from_url('http://example.com/url?a=1&b=2&b=3', show_host=False)
self.assertEqual(url.schema, 'http')
self.assertEqual(url.host, 'example.com')
self.assertEqual(url.port, '')
self.assertEqual(url.path, '/url')
self.assertEqual(url.query.items(), [('a' ,'1'), ('b', '2'), ('b', '3')])
self.assertEqual(url.show_host, False)
示例7: test_from_url
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url(self):
url = URL.from_url('http://example.com/url?a=1&b=2&b=3#anchor', show_host=False)
self.assertEqual(url.scheme, 'http')
self.assertEqual(url.host, 'example.com')
self.assertEqual(url.port, '')
self.assertEqual(url.path, '/url')
self.assertEqual(url.fragment, 'anchor')
self.assertEqual(set(url.query.items()), {('a' ,'1'), ('b', '2'), ('b', '3')})
self.assertEqual(url.show_host, False)
示例8: test_cyrillic_path
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_cyrillic_path(self):
url1 = URL.from_url('http://test.ru/тест') # encoded unicode
url2 = URL.from_url(u'http://test.ru/тест') # decoded unicode
# should work both without errors
self.assertEqual(url1.path, '/%D1%82%D0%B5%D1%81%D1%82')
self.assertEqual(url1.path, url2.path)
示例9: test_from_url_broken_unicode
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_broken_unicode(self):
url = URL.from_url('/search?q=hello%E3%81')
self.assertEqual(url.get_readable(),
u'/search?q=hello�')
示例10: test_from_url_idna
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_idna(self):
url = URL.from_url('http://xn--80aswg.xn--p1ai/%D1%83%D1%80%D0%BB/?q=%D0%BF%D0%BE%D0%B8%D1%81%D0%BA')
self.assertEqual(url.get_readable(),
u'http://сайт.рф/урл/?q=поиск')
示例11: test_parse_cp_1251
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_parse_cp_1251(self):
url_string = u"http://test.com/?query=привет".encode('cp1251')
url = URL.from_url(url_string)
self.assertEqual(url.host, 'test.com')
self.assertEqual(url.query['query'], u'\N{REPLACEMENT CHARACTER}'*6)
示例12: test_empty_fragment
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_empty_fragment(self):
self.assertEqual(URL.from_url('/').fragment, None)
self.assertEqual(URL.from_url('/#').fragment, '')
self.assertEqual(URL('/', fragment=None), '/')
self.assertEqual(URL('/', fragment='') ,'/#')
示例13: test_from_url_broken_unicode
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import from_url [as 别名]
def test_from_url_broken_unicode(self):
url = URL.from_url('/search%E3%81?q=hello%E3%81#hash%E3%81')
self.assertEqual(url.get_readable(),
u'/search\N{REPLACEMENT CHARACTER}'
u'?q=hello\N{REPLACEMENT CHARACTER}'
u'#hash\N{REPLACEMENT CHARACTER}')