本文整理汇总了Python中iktomi.web.reverse.URL类的典型用法代码示例。如果您正苦于以下问题:Python URL类的具体用法?Python URL怎么用?Python URL使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了URL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_param_delete
def test_param_delete(self):
'Set new param in url'
u = URL('/path/to/something', query=[('id', 3), ('page', 5), ('page', 6)])
self.assertEqual(u, '/path/to/something?id=3&page=5&page=6')
u = u.qs_delete('page')
self.assertEqual(u, '/path/to/something?id=3')
u = u.qs_delete('offset')
self.assertEqual(u, '/path/to/something?id=3')
示例2: test_params_set_args
def test_params_set_args(self):
'Use multidict to set params in url'
url = URL('/')
self.assertEqual(url.qs_set(a=1, b=2), '/?a=1&b=2')
url = url.qs_set([('a', '1'), ('a', '2'), ('b', '3')])
self.assertEqual(url, '/?a=1&a=2&b=3')
self.assertEqual(url.qs_set([('a', '1'), ('c', '2')]), '/?b=3&a=1&c=2')
self.assertRaises(TypeError, url.qs_set, [('a', 1)], z=0)
示例3: test_param_set
def test_param_set(self):
'Set new param in url'
u = URL('/path/to/something', query=dict(id=3, page=5, title='title'))
self.assertEqual(u, '/path/to/something?title=title&id=3&page=5')
u = u.qs_set(page=6)
self.assertEqual(u, '/path/to/something?title=title&id=3&page=6')
u = u.qs_set(page=7, title='land')
self.assertEqual(u, '/path/to/something?id=3&page=7&title=land')
示例4: test_quotted_path_to_constructor
def test_quotted_path_to_constructor(self):
u = URL(u'/%D1%83/',
host=u'xn--80aswg.xn--p1ai',
query={'q': u'%D0%BF'},
fragment=u"%D1%8F")
# We shold not try to unquote the urlqouted values!
# Otherwise it is impossible to build a consistent interface
self.assertEqual(u, u'http://xn--80aswg.xn--p1ai/%25D1%2583/?q=%25D0%25BF#%25D1%258F')
self.assertEqual(u.get_readable(), u'http://сайт.рф/%25D1%2583/?q=%25D0%25BF#%25D1%258F')
示例5: test_param_get
def test_param_get(self):
'Get param from url'
u = URL('/path/to/something', query=dict(id=3, page=5, title='title'))
page = u.qs_get('page')
self.assertEqual(page, 5)
u = u.qs_set(page=7)
page = u.qs_get('page')
self.assertEqual(page, 7)
not_here = u.qs_get('not_here')
self.assertEqual(not_here, None)
示例6: test_broken_idna
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--.рф/')
示例7: test_param_set
def test_param_set(self):
'Set new param in url'
u = URL('/path/to/something', query=[('title', 'title'), ('id', 3), ('page', 5)])
self.assertEqual(u, '/path/to/something?title=title&id=3&page=5')
if six.PY2:
u = u.qs_set(page=long(2))
self.assertEqual(u, '/path/to/something?title=title&id=3&page=2')
u = u.qs_set(page=6)
self.assertEqual(u, '/path/to/something?title=title&id=3&page=6')
u = u.qs_set(page=7, title='land')
self.assertIn(u, ['/path/to/something?id=3&page=7&title=land',
'/path/to/something?id=3&title=land&page=7'])
示例8: test_from_url_idna
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=поиск#якорь')
示例9: test_iri
def test_iri(self):
u = URL('/', host=u'example.com')
self.assertEqual(u, u'http://example.com/')
u = URL(u'/урл/', host=u'сайт.рф', query={'q': u'поиск'}, fragment=u"якорь")
self.assertEqual(u, 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')
# Note: you should probably not use unicode in fragment part of URL.
# We encode it according to RFC, but different client handle
# it in different ways: Chrome allows unicode and does not
# encode/decode it at all, while Firefox handles it according RFC
self.assertEqual(u.qs_set(a=u'1'), 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&a=1'
u'#%D1%8F%D0%BA%D0%BE%D1%80%D1%8C')
示例10: test_copy_url
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))
示例11: test_from_url_path
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')])
示例12: test_from_url_unicode
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)
示例13: test_from_url
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)
示例14: test_from_url
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)
示例15: test_from_url_broken_unicode
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�')