• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python util.text_函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pyramid.util.text_函数的典型用法代码示例。如果您正苦于以下问题:Python text_函数的具体用法?Python text_怎么用?Python text_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了text_函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_pattern_with_high_order_literal

 def test_pattern_with_high_order_literal(self):
     pattern = text_(b'/La Pe\xc3\xb1a/{x}', 'utf-8')
     matcher, generator = self._callFUT(pattern)
     self.assertEqual(
         matcher(text_(b'/La Pe\xc3\xb1a/x', 'utf-8')), {'x': 'x'}
     )
     self.assertEqual(generator({'x': '1'}), '/La%20Pe%C3%B1a/1')
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_urldispatch.py


示例2: test_matcher_functional_oldstyle

 def test_matcher_functional_oldstyle(self):
     self.matches('/:x', '', None)
     self.matches('/:x', '/', None)
     self.matches('/abc/:def', '/abc/', None)
     self.matches('/:x', '/a', {'x': 'a'})
     self.matches('zzz/:x', '/zzz/abc', {'x': 'abc'})
     self.matches(
         'zzz/:x*traverse', '/zzz/abc', {'x': 'abc', 'traverse': ()}
     )
     self.matches(
         'zzz/:x*traverse',
         '/zzz/abc/def/g',
         {'x': 'abc', 'traverse': ('def', 'g')},
     )
     self.matches('*traverse', '/zzz/abc', {'traverse': ('zzz', 'abc')})
     self.matches('*traverse', '/zzz/ abc', {'traverse': ('zzz', ' abc')})
     # '/La%20Pe%C3%B1a'
     # pattern, path, expected
     self.matches(
         ':x',
         text_(b'/La Pe\xc3\xb1a', 'utf-8'),
         {'x': text_(b'La Pe\xc3\xb1a', 'utf-8')},
     )
     # '/La%20Pe%C3%B1a/x'
     self.matches(
         '*traverse',
         text_(b'/La Pe\xc3\xb1a/x', 'utf-8'),
         {'traverse': (text_(b'La Pe\xc3\xb1a', 'utf-8'), 'x')},
     )
     self.matches('/foo/:id.html', '/foo/bar.html', {'id': 'bar'})
     self.matches('/foo/:id_html', '/foo/bar_html', {'id_html': 'bar_html'})
     self.matches('zzz/:_', '/zzz/abc', {'_': 'abc'})
     self.matches('zzz/:_abc', '/zzz/abc', {'_abc': 'abc'})
     self.matches('zzz/:abc_def', '/zzz/abc', {'abc_def': 'abc'})
开发者ID:Pylons,项目名称:pyramid,代码行数:34,代码来源:test_urldispatch.py


示例3: test_absolute_unicode_found

    def test_absolute_unicode_found(self):
        # test for bug wiggy found in wild, traceback stack:
        # root = '/%E6%B5%81%E8%A1%8C%E8%B6%8B%E5%8A%BF'
        # wiggy's code: section=find_resource(page, root)
        # find_resource L76: D = traverse(resource, path)
        # traverse L291: return traverser(request)
        # __call__ line 568: vpath_tuple = traversal_path(vpath)
        # lru_cached line 91: f(*arg)
        # traversal_path line 443: path.encode('ascii')
        # UnicodeEncodeError: 'ascii' codec can't encode characters in
        #     position 1-12: ordinal not in range(128)
        #
        # solution: encode string to ascii in pyramid.traversal.traverse
        # before passing it along to webob as path_info
        from pyramid.traversal import ResourceTreeTraverser

        unprintable = DummyContext()
        root = DummyContext(unprintable)
        unprintable.__parent__ = root
        unprintable.__name__ = text_(
            b'/\xe6\xb5\x81\xe8\xa1\x8c\xe8\xb6\x8b\xe5\x8a\xbf', 'utf-8'
        )
        root.__parent__ = None
        root.__name__ = None
        traverser = ResourceTreeTraverser
        self._registerTraverser(traverser)
        result = self._callFUT(
            root, text_(b'/%E6%B5%81%E8%A1%8C%E8%B6%8B%E5%8A%BF')
        )
        self.assertEqual(result, unprintable)
开发者ID:Pylons,项目名称:pyramid,代码行数:30,代码来源:test_traversal.py


示例4: test_generator_functional_oldstyle

 def test_generator_functional_oldstyle(self):
     self.generates('/:x', {'x': ''}, '/')
     self.generates('/:x', {'x': 'a'}, '/a')
     self.generates('zzz/:x', {'x': 'abc'}, '/zzz/abc')
     self.generates(
         'zzz/:x*traverse', {'x': 'abc', 'traverse': ''}, '/zzz/abc'
     )
     self.generates(
         'zzz/:x*traverse',
         {'x': 'abc', 'traverse': '/def/g'},
         '/zzz/abc/def/g',
     )
     self.generates(
         '/:x',
         {'x': text_(b'/La Pe\xc3\xb1a', 'utf-8')},
         '//La%20Pe%C3%B1a',
     )
     self.generates(
         '/:x*y',
         {'x': text_(b'/La Pe\xc3\xb1a', 'utf-8'), 'y': '/rest/of/path'},
         '//La%20Pe%C3%B1a/rest/of/path',
     )
     self.generates(
         '*traverse',
         {'traverse': ('a', text_(b'La Pe\xf1a'))},
         '/a/La%20Pe%C3%B1a',
     )
     self.generates('/foo/:id.html', {'id': 'bar'}, '/foo/bar.html')
     self.generates('/foo/:_', {'_': '20'}, '/foo/20')
     self.generates('/foo/:_abc', {'_abc': '20'}, '/foo/20')
     self.generates('/foo/:abc_def', {'abc_def': '20'}, '/foo/20')
开发者ID:Pylons,项目名称:pyramid,代码行数:31,代码来源:test_urldispatch.py


示例5: test_docs_sample_generate

 def test_docs_sample_generate(self):
     # sample from urldispatch.rst
     pattern = text_(b'/La Pe\xc3\xb1a/{city}', 'utf-8')
     _, generator = self._callFUT(pattern)
     self.assertEqual(
         generator({'city': text_(b'Qu\xc3\xa9bec', 'utf-8')}),
         '/La%20Pe%C3%B1a/Qu%C3%A9bec',
     )
开发者ID:Pylons,项目名称:pyramid,代码行数:8,代码来源:test_urldispatch.py


示例6: test_generate_with_string_remainder_and_unicode_replacement

 def test_generate_with_string_remainder_and_unicode_replacement(self):
     pattern = text_(b'/abc*remainder', 'utf-8')
     _, generator = self._callFUT(pattern)
     result = generator(
         {'remainder': text_(b'/Qu\xc3\xa9bec/La Pe\xc3\xb1a', 'utf-8')}
     )
     self.assertEqual(result, '/abc/Qu%C3%A9bec/La%20Pe%C3%B1a')
     # should be a native string
     self.assertEqual(type(result), str)
开发者ID:Pylons,项目名称:pyramid,代码行数:9,代码来源:test_urldispatch.py


示例7: call_app_with_subpath_as_path_info

def call_app_with_subpath_as_path_info(request, app):
    # Copy the request.  Use the source request's subpath (if it exists) as
    # the new request's PATH_INFO.  Set the request copy's SCRIPT_NAME to the
    # prefix before the subpath.  Call the application with the new request
    # and return a response.
    #
    # Postconditions:
    # - SCRIPT_NAME and PATH_INFO are empty or start with /
    # - At least one of SCRIPT_NAME or PATH_INFO are set.
    # - SCRIPT_NAME is not '/' (it should be '', and PATH_INFO should
    #   be '/').

    environ = request.environ
    script_name = environ.get('SCRIPT_NAME', '')
    path_info = environ.get('PATH_INFO', '/')
    subpath = list(getattr(request, 'subpath', ()))

    new_script_name = ''

    # compute new_path_info
    new_path_info = '/' + '/'.join(
        [text_(x.encode('utf-8'), 'latin-1') for x in subpath]
    )

    if new_path_info != '/':  # don't want a sole double-slash
        if path_info != '/':  # if orig path_info is '/', we're already done
            if path_info.endswith('/'):
                # readd trailing slash stripped by subpath (traversal)
                # conversion
                new_path_info += '/'

    # compute new_script_name
    workback = (script_name + path_info).split('/')

    tmp = []
    while workback:
        if tmp == subpath:
            break
        el = workback.pop()
        if el:
            tmp.insert(0, text_(bytes_(el, 'latin-1'), 'utf-8'))

    # strip all trailing slashes from workback to avoid appending undue slashes
    # to end of script_name
    while workback and (workback[-1] == ''):
        workback = workback[:-1]

    new_script_name = '/'.join(workback)

    new_request = request.copy()
    new_request.environ['SCRIPT_NAME'] = new_script_name
    new_request.environ['PATH_INFO'] = new_path_info

    return new_request.get_response(app)
开发者ID:Pylons,项目名称:pyramid,代码行数:54,代码来源:request.py


示例8: test_subpath_path_info_and_script_name_have_utf8

 def test_subpath_path_info_and_script_name_have_utf8(self):
     encoded = text_(b'La Pe\xc3\xb1a')
     decoded = text_(bytes_(encoded), 'utf-8')
     request = DummyRequest(
         {'PATH_INFO': '/' + encoded, 'SCRIPT_NAME': '/' + encoded}
     )
     request.subpath = (decoded,)
     response = self._callFUT(request, 'app')
     self.assertTrue(request.copied)
     self.assertEqual(response, 'app')
     self.assertEqual(request.environ['SCRIPT_NAME'], '/' + encoded)
     self.assertEqual(request.environ['PATH_INFO'], '/' + encoded)
开发者ID:Pylons,项目名称:pyramid,代码行数:12,代码来源:test_request.py


示例9: test_add_route_with_path_info_regex

 def test_add_route_with_path_info_regex(self):
     config = self._makeOne(autocommit=True)
     config.add_route(
         'name', 'path', path_info=text_(br'/La Pe\w*', 'utf-8')
     )
     route = self._assertRoute(config, 'name', 'path', 1)
     predicate = route.predicates[0]
     request = self._makeRequest(config)
     request.upath_info = text_(b'/La Pe\xc3\xb1a', 'utf-8')
     self.assertEqual(predicate(None, request), True)
     request = self._makeRequest(config)
     request.upath_info = text_('/')
     self.assertEqual(predicate(None, request), False)
开发者ID:Pylons,项目名称:pyramid,代码行数:13,代码来源:test_routes.py


示例10: test_call_withconn_getitem_withpath_withsubpath

 def test_call_withconn_getitem_withpath_withsubpath(self):
     foo = DummyContext()
     root = DummyContext(foo)
     policy = self._makeOne(root)
     environ = self._getEnviron()
     request = DummyRequest(environ, path_info=text_('/foo/bar/baz/buz'))
     result = policy(request)
     self.assertEqual(result['context'], foo)
     self.assertEqual(result['view_name'], 'bar')
     self.assertEqual(result['subpath'], ('baz', 'buz'))
     self.assertEqual(result['traversed'], (text_('foo'),))
     self.assertEqual(result['root'], root)
     self.assertEqual(result['virtual_root'], root)
     self.assertEqual(result['virtual_root_path'], ())
开发者ID:Pylons,项目名称:pyramid,代码行数:14,代码来源:test_traversal.py


示例11: test_utf16

    def test_utf16(self):
        from pyramid.exceptions import URLDecodeError

        la = text_(b'La Pe\xc3\xb1a', 'utf-8').encode('utf-16')
        encoded = quote(la)
        path = '/'.join([encoded, encoded])
        self.assertRaises(URLDecodeError, self._callFUT, path)
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_traversal.py


示例12: test_utf8

 def test_utf8(self):
     la = b'La Pe\xc3\xb1a'
     encoded = quote(la)
     decoded = text_(la, 'utf-8')
     path = '/'.join([encoded, encoded])
     result = self._callFUT(path)
     self.assertEqual(result, (decoded, decoded))
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_traversal.py


示例13: test_unicode

    def test_unicode(self):
        class DummyUnicodeObject(object):
            def __unicode__(self):
                return text_('42')

        duo = DummyUnicodeObject()
        self.assertEqual(self._callFUT(duo), text_('42'))
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_httpexceptions.py


示例14: test_route_url

    def test_route_url(self):
        environ = {
            'PATH_INFO': '/',
            'SERVER_NAME': 'example.com',
            'SERVER_PORT': '5432',
            'QUERY_STRING': 'la=La%20Pe%C3%B1a',
            'wsgi.url_scheme': 'http',
        }
        from pyramid.interfaces import IRoutesMapper

        inst = self._makeOne(environ)
        mapper = DummyRoutesMapper(route=DummyRoute('/1/2/3'))
        self.config.registry.registerUtility(mapper, IRoutesMapper)
        result = inst.route_url(
            'flub',
            'extra1',
            'extra2',
            a=1,
            b=2,
            c=3,
            _query={'a': 1},
            _anchor=text_("foo"),
        )
        self.assertEqual(
            result, 'http://example.com:5432/1/2/3/extra1/extra2?a=1#foo'
        )
开发者ID:Pylons,项目名称:pyramid,代码行数:26,代码来源:test_request.py


示例15: _set_cookie

 def _set_cookie(self, response):
     if not self._cookie_on_exception:
         exception = getattr(self.request, 'exception', None)
         if (
             exception is not None
         ):  # dont set a cookie during exceptions
             return False
     cookieval = text_(
         serializer.dumps((self.accessed, self.created, dict(self)))
     )
     if len(cookieval) > 4064:
         raise ValueError(
             'Cookie value is too long to store (%s bytes)'
             % len(cookieval)
         )
     response.set_cookie(
         self._cookie_name,
         value=cookieval,
         max_age=self._cookie_max_age,
         path=self._cookie_path,
         domain=self._cookie_domain,
         secure=self._cookie_secure,
         httponly=self._cookie_httponly,
         samesite=self._cookie_samesite,
     )
     return True
开发者ID:Pylons,项目名称:pyramid,代码行数:26,代码来源:session.py


示例16: test_generate_with_string_remainder_and_nonstring_replacement

 def test_generate_with_string_remainder_and_nonstring_replacement(self):
     pattern = text_(b'/abc/*remainder', 'utf-8')
     _, generator = self._callFUT(pattern)
     result = generator({'remainder': None})
     self.assertEqual(result, '/abc/None')
     # should be a native string
     self.assertEqual(type(result), str)
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_urldispatch.py


示例17: test_pattern_generate_with_high_order_dynamic

 def test_pattern_generate_with_high_order_dynamic(self):
     pattern = '/{x}'
     _, generator = self._callFUT(pattern)
     self.assertEqual(
         generator({'x': text_(b'La Pe\xc3\xb1a', 'utf-8')}),
         '/La%20Pe%C3%B1a',
     )
开发者ID:Pylons,项目名称:pyramid,代码行数:7,代码来源:test_urldispatch.py


示例18: test_traverse_matches_with_highorder_chars

 def test_traverse_matches_with_highorder_chars(self):
     order, predicates, phash = self._callFUT(
         traverse=text_(b'/La Pe\xc3\xb1a/{x}', 'utf-8')
     )
     self.assertEqual(len(predicates), 1)
     pred = predicates[0]
     info = {'match': {'x': text_(b'Qu\xc3\xa9bec', 'utf-8')}}
     request = DummyRequest()
     result = pred(info, request)
     self.assertEqual(result, True)
     self.assertEqual(
         info['match']['traverse'],
         (
             text_(b'La Pe\xc3\xb1a', 'utf-8'),
             text_(b'Qu\xc3\xa9bec', 'utf-8'),
         ),
     )
开发者ID:Pylons,项目名称:pyramid,代码行数:17,代码来源:test_predicates.py


示例19: test_body_template_unicode

 def test_body_template_unicode(self):
     cls = self._getTargetSubclass()
     la = text_(b'/La Pe\xc3\xb1a', 'utf-8')
     environ = _makeEnviron(unicodeval=la)
     exc = cls(body_template='${unicodeval}')
     start_response = DummyStartResponse()
     body = list(exc(environ, start_response))[0]
     self.assertEqual(body, b'200 OK\n\n/La Pe\xc3\xb1a')
开发者ID:Pylons,项目名称:pyramid,代码行数:8,代码来源:test_httpexceptions.py


示例20: test_call_with_vh_root_highorder

 def test_call_with_vh_root_highorder(self):
     path = text_(b'Qu\xc3\xa9bec', 'utf-8')
     bar = DummyContext(None, 'bar')
     foo = DummyContext(bar, path)
     root = DummyContext(foo, 'root')
     policy = self._makeOne(root)
     vhm_root = b'/Qu\xc3\xa9bec'.decode('latin-1')
     environ = self._getEnviron(HTTP_X_VHM_ROOT=vhm_root)
     request = DummyRequest(environ, path_info=text_('/bar'))
     result = policy(request)
     self.assertEqual(result['context'], bar)
     self.assertEqual(result['view_name'], '')
     self.assertEqual(result['subpath'], ())
     self.assertEqual(result['traversed'], (path, text_('bar')))
     self.assertEqual(result['root'], policy.root)
     self.assertEqual(result['virtual_root'], foo)
     self.assertEqual(result['virtual_root_path'], (path,))
开发者ID:Pylons,项目名称:pyramid,代码行数:17,代码来源:test_traversal.py



注:本文中的pyramid.util.text_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python util.DottedNameResolver类代码示例发布时间:2022-05-27
下一篇:
Python util.strings_differ函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap