當前位置: 首頁>>代碼示例>>Python>>正文


Python reverse.URL類代碼示例

本文整理匯總了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')
開發者ID:oas89,項目名稱:iktomi,代碼行數:8,代碼來源:url.py

示例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)
開發者ID:oas89,項目名稱:iktomi,代碼行數:8,代碼來源:url.py

示例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')
開發者ID:oas89,項目名稱:iktomi,代碼行數:8,代碼來源:url.py

示例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')
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:9,代碼來源:url.py

示例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)
開發者ID:oas89,項目名稱:iktomi,代碼行數:10,代碼來源:url.py

示例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--.рф/')
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:11,代碼來源:url.py

示例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'])
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:12,代碼來源:url.py

示例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=поиск#якорь')
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:13,代碼來源:url.py

示例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')
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:16,代碼來源:url.py

示例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))
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:7,代碼來源:url.py

示例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')])
開發者ID:oas89,項目名稱:iktomi,代碼行數:7,代碼來源:url.py

示例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)
開發者ID:oas89,項目名稱:iktomi,代碼行數:7,代碼來源:url.py

示例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)
開發者ID:oas89,項目名稱:iktomi,代碼行數:8,代碼來源:url.py

示例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)
開發者ID:SmartTeleMax,項目名稱:iktomi,代碼行數:9,代碼來源:url.py

示例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�')
開發者ID:oas89,項目名稱:iktomi,代碼行數:4,代碼來源:url.py


注:本文中的iktomi.web.reverse.URL類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。