本文整理汇总了Python中iktomi.web.reverse.URL.qs_set方法的典型用法代码示例。如果您正苦于以下问题:Python URL.qs_set方法的具体用法?Python URL.qs_set怎么用?Python URL.qs_set使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iktomi.web.reverse.URL
的用法示例。
在下文中一共展示了URL.qs_set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_params_set_args
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
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)
示例2: test_param_set
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
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')
示例3: test_param_set
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
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'])
示例4: test_param_get
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
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)
示例5: test_iri
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
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')
示例6: test_quote
# 需要导入模块: from iktomi.web.reverse import URL [as 别名]
# 或者: from iktomi.web.reverse.URL import qs_set [as 别名]
def test_quote(self):
u = URL(quote('/path/to/+'))
self.assertEqual(u, '/path/to/%2B')
u = u.qs_set(page=7)
self.assertEqual(u, '/path/to/%2B?page=7')