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


Python url_templates.UrlTemplate類代碼示例

本文整理匯總了Python中iktomi.web.url_templates.UrlTemplate的典型用法代碼示例。如果您正苦於以下問題:Python UrlTemplate類的具體用法?Python UrlTemplate怎麽用?Python UrlTemplate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了UrlTemplate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_match_from_begining_without_params

 def test_match_from_begining_without_params(self):
     'UrlTemplate match method without params (from begining of str)'
     ut = UrlTemplate('simple', match_whole_str=False)
     self.assertEqual(ut.match('simple'), ('simple', {}))
     self.assertEqual(ut.match('simple/sdffds'), ('simple', {}))
     self.assertEqual(ut.match('/simple'), (None, {}))
     self.assertEqual(ut.match('/simple/'), (None, {}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:7,代碼來源:url_template.py

示例2: test_redefine_converters

    def test_redefine_converters(self):
        from iktomi.web.url_converters import Integer

        class DoubleInt(Integer):
            def to_python(self, value, env=None):
                return Integer.to_python(self, value, env) * 2
            def to_url(self, value):
                return str(value / 2)

        ut = UrlTemplate('/simple/<int:id>',
                         converters={'int': DoubleInt})
        self.assertEqual(ut(id=2), '/simple/1')
        self.assertEqual(ut.match('/simple/1'), ('/simple/1', {'id': 2}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:13,代碼來源:url_template.py

示例3: test_converter_with_args

 def test_converter_with_args(self):
     'Converter with args'
     class Conv(Converter):
         def __init__(self, *items):
             self.items = items
         def to_python(self, value, **kw):
             if value not in self.items:
                 raise ConvertError(self, value)
             return value
     t = UrlTemplate(u'/<conv(u"text", u"тест", noquote):name>',
                     converters={'conv': Conv})
     value = quote(u'/имя'.encode('utf-8'))
     self.assertEqual(t.match(value), (None, {}))
     value = quote(u'/text'.encode('utf-8'))
     self.assertEqual(t.match(value), (value, {'name': u'text'}))
     value = quote(u'/тест'.encode('utf-8'))
     self.assertEqual(t.match(value), (value, {'name': u'тест'}))
     value = quote(u'/noquote'.encode('utf-8'))
     self.assertEqual(t.match(value), (value, {'name': u'noquote'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:19,代碼來源:url.py

示例4: test_match_from_begining_with_params

 def test_match_from_begining_with_params(self):
     'UrlTemplate match method with params (from begining of str)'
     ut = UrlTemplate('/simple/<int:id>', match_whole_str=False)
     self.assertEqual(ut.match('/simple/2'), ('/simple/2', {'id':2}))
     self.assertEqual(ut.match('/simple/2/sdfsf'), ('/simple/2', {'id':2}))
     self.assertEqual(ut.match('/simple'), (None, {}))
     self.assertEqual(ut.match('/simple/d'), (None, {}))
     self.assertEqual(ut.match('/simple/d/sdfsdf'), (None, {}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:8,代碼來源:url_template.py

示例5: test_empty_match

 def test_empty_match(self):
     'UrlTemplate match method with empty template'
     ut = UrlTemplate('')
     self.assertEqual(ut.match(''), ('', {}))
     self.assertEqual(ut.match('/'), (None, {}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:5,代碼來源:url_template.py

示例6: test_match_with_params

 def test_match_with_params(self):
     'UrlTemplate match method with params'
     ut = UrlTemplate('/simple/<int:id>')
     self.assertEqual(ut.match('/simple/2'), ('/simple/2', {'id':2}))
     self.assertEqual(ut.match('/simple'), (None, {}))
     self.assertEqual(ut.match('/simple/d'), (None, {}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:6,代碼來源:url_template.py

示例7: test_match_without_params

 def test_match_without_params(self):
     'UrlTemplate match method without params'
     ut = UrlTemplate('simple')
     self.assertEqual(ut.match('simple'), ('simple', {}))
     self.assertEqual(ut.match('/simple'), (None, {}))
開發者ID:Lehych,項目名稱:iktomi,代碼行數:5,代碼來源:url_template.py

示例8: test_incorrect_value

 def test_incorrect_value(self):
     'Incorrect url encoded value'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8'))[:-1]
     self.assertEqual(t.match(value), (value, {'name': u'\u0438\u043c\ufffd%8'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:5,代碼來源:url.py

示例9: test_incorrect_urlencoded_path

 def test_incorrect_urlencoded_path(self):
     'Incorrect url encoded path'
     t = UrlTemplate('/<name>')
     value = quote(u'/имя'.encode('utf-8'))+'%r1'
     self.assertEqual(t.match(value), (value, {'name': u'\u0438\u043c\u044f%r1'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:5,代碼來源:url.py

示例10: test_multiple_converters_postfix

 def test_multiple_converters_postfix(self):
     'Multiple converters with postfix data'
     t = UrlTemplate('/<name>/text/<action>/post')
     self.assertEqual(t.match('/this/text/edit/post'), ('/this/text/edit/post', {'name': 'this', 'action': 'edit'}))
     self.assertEqual(t.match('/this/text/edit'), (None, {}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:5,代碼來源:url.py

示例11: test_unicode

 def test_unicode(self):
     'Unicode values of converters'
     t = UrlTemplate('/<name>/text/<action>')
     url = quote(u'/имя/text/действие'.encode('utf-8'))
     self.assertEqual(t.match(url), (url, {'name': u'имя', 'action': u'действие'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:5,代碼來源:url.py

示例12: test_multiple_converters

 def test_multiple_converters(self):
     'Multiple converters'
     t = UrlTemplate('/<name>/text/<action>')
     self.assertEqual(t.match('/this/text/edit'), ('/this/text/edit', {'name': 'this', 'action': 'edit'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:4,代碼來源:url.py

示例13: test_default_converter

 def test_default_converter(self):
     'Default converter test'
     t = UrlTemplate('/<name>')
     self.assertEqual(t.match('/somevalue'), ('/somevalue', {'name': 'somevalue'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:4,代碼來源:url.py

示例14: test_converter

 def test_converter(self):
     'Simple text match'
     t = UrlTemplate('/<string:name>')
     self.assertEqual(t.match('/somevalue'), ('/somevalue', {'name': 'somevalue'}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:4,代碼來源:url.py

示例15: test_static_text

 def test_static_text(self):
     'Simple text match'
     t = UrlTemplate('/test/url')
     self.assertEqual(t.match('/test/url'), ('/test/url', {}))
開發者ID:oas89,項目名稱:iktomi,代碼行數:4,代碼來源:url.py


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