当前位置: 首页>>代码示例>>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;未经允许,请勿转载。