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

Python compat.native_函数代码示例

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

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



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

示例1: test_matcher_functional_newstyle

 def test_matcher_functional_newstyle(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'
     self.matches('{x}', native_(b'/La Pe\xc3\xb1a'),
                  {'x':text_(b'La Pe\xf1a')})
     # '/La%20Pe%C3%B1a/x'
     self.matches('*traverse', native_(b'/La Pe\xc3\xb1a/x'),
                  {'traverse':(text_(b'La Pe\xf1a'), 'x')})
     self.matches('/foo/{id}.html', '/foo/bar.html', {'id':'bar'})
     self.matches('/{num:[0-9]+}/*traverse', '/555/abc/def',
                  {'num':'555', 'traverse':('abc', 'def')})
     self.matches('/{num:[0-9]*}/*traverse', '/555/abc/def',
                  {'num':'555', 'traverse':('abc', 'def')})
     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:HorizonXP,项目名称:pyramid,代码行数:25,代码来源:test_urldispatch.py


示例2: oauth_response

def oauth_response(result):
    headers, body, status = result
    headerlist = headers.items() if hasattr(headers, 'items') else headers

    return Response(body=body, status=status, charset='utf-8', headerlist=[
        (native_(name, encoding='latin-1'), native_(value, encoding='latin-1'))
        for name, value
        in headerlist
    ])
开发者ID:dokai,项目名称:pyramid-oauthlib,代码行数:9,代码来源:__init__.py


示例3: oauth_response

def oauth_response(result):
    headers, body, status = result
    return Response(
        body=body,
        status=status,
        headers={
            native_(name, encoding="latin-1"): native_(value, encoding="latin-1") for name, value in headers.items()
        },
    )
开发者ID:joepvandijken,项目名称:pyramid-oauthlib,代码行数:9,代码来源:__init__.py


示例4: oauth_response

def oauth_response(result):
    headers, body, status = result

    if isinstance(headers, dict):
        header_iter = headers.items()
    else:
        header_iter = headers

    return Response(body=body, status=status, headerlist=[
        (native_(name, encoding='latin-1'), native_(value, encoding='latin-1'))
        for name, value
        in header_iter
    ])
开发者ID:enquos,项目名称:pyramid-oauthlib,代码行数:13,代码来源:__init__.py


示例5: test_resource_url_anchor_is_encoded_utf8_if_unicode

 def test_resource_url_anchor_is_encoded_utf8_if_unicode(self):
     request = self._makeOne()
     self._registerResourceURL(request.registry)
     context = DummyContext()
     uc = text_(b"La Pe\xc3\xb1a", "utf-8")
     result = request.resource_url(context, anchor=uc)
     self.assertEqual(result, native_(text_(b"http://example.com:5432/context/#La Pe\xc3\xb1a", "utf-8"), "utf-8"))
开发者ID:pzatrick,项目名称:pyramid,代码行数:7,代码来源:test_url.py


示例6: test_post_collection_warning_exception

 def test_post_collection_warning_exception(self):
     # First POST - get back a 307.
     res1 = self.app.post(self.path, params='foo name',
                          status=307)
     body_text = native_(res1.body.rstrip(), encoding='utf-8')
     self.assert_true(body_text.endswith(
                                 UserMessagePostCollectionView.message))
     self.assert_true(res1.body.startswith(b'307 Temporary Redirect'))
     # Second POST to redirection location - get back a 201.
     resubmit_location1 = res1.headers['Location']
     res2 = self.app.post(resubmit_location1,
                          params='foo name',
                          status=201)
     self.assert_true(not res2 is None)
     # Third POST to same redirection location with different warning
     # message triggers a 307 again.
     old_msg = UserMessagePostCollectionView.message
     UserMessagePostCollectionView.message = old_msg[::-1]
     try:
         res3 = self.app.post(resubmit_location1,
                              params='foo name',
                              status=307)
         self.assert_true(res3.body.startswith(b'307 Temporary Redirect'))
         # Fourth POST to new redirection location - get back a 409 (since
         # the second POST from above went through).
         resubmit_location2 = res3.headers['Location']
         res4 = self.app.post(resubmit_location2,
                              params='foo name',
                              status=409)
         self.assert_true(not res4 is None)
     finally:
         UserMessagePostCollectionView.message = old_msg
开发者ID:b8va,项目名称:everest,代码行数:32,代码来源:test_views.py


示例7: test_get_collection_with_refs_options

 def test_get_collection_with_refs_options(self):
     # The links options are not processed by the renderers, so we need
     # a native everest view with a defined response MIME type.
     self.config.add_resource_view(IMyEntity,
                                   default_response_content_type=CsvMime,
                                   request_method=RequestMethods.GET)
     create_collection()
     res1 = self.app.get(self.path, params=dict(refs='parent:OFF'),
                        status=200)
     self.assert_is_not_none(res1)
     self.assert_equal(native_(res1.body).find(',"parent",'), -1)
     self.assert_equal(native_(res1.body).find(',"parent.id",'), -1)
     res2 = self.app.get(self.path, params=dict(refs='parent:INLINE'),
                        status=200)
     self.assert_is_not_none(res2)
     self.assert_equal(native_(res2.body).find(',"parent",'), -1)
     self.assert_not_equal(native_(res2.body).find(',"parent.id",'), -1)
开发者ID:b8va,项目名称:everest,代码行数:17,代码来源:test_views.py


示例8: template_renderer

 def template_renderer(self, content, vars, filename=None):
     content = native_(content, fsenc)
     try:
         return bytes_(
             substitute_double_braces(content, TypeMapper(vars)), fsenc)
     except Exception as e:
         _add_except(e, ' in file %s' % filename)
         raise
开发者ID:HorizonXP,项目名称:pyramid,代码行数:8,代码来源:template.py


示例9: pre

 def pre(self, command, output_dir, vars):
     vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
     package_logger = vars['package']
     if package_logger == 'root':
         # Rename the app logger in the rare case a project is named 'root'
         package_logger = 'app'
     vars['package_logger'] = package_logger
     return Template.pre(self, command, output_dir, vars)
开发者ID:jpcw,项目名称:pyramid,代码行数:8,代码来源:__init__.py


示例10: generate_secret

def generate_secret(length=40):
    """
    Returns a random ascii hash of the specified length (default is 40).

    .. note:: Due to the way the secret is generated, ``length`` should always
              be an even number.
    """
    return native_(binascii.hexlify(os.urandom(int(length / 2))))
开发者ID:seedifferently,项目名称:python-pyramid-starter,代码行数:8,代码来源:helpers.py


示例11: test_non_utf8_path_segment_settings_unicode_path_segments_fails

 def test_non_utf8_path_segment_settings_unicode_path_segments_fails(self):
     from pyramid.exceptions import URLDecodeError
     foo = DummyContext()
     root = DummyContext(foo)
     policy = self._makeOne(root)
     segment = native_(text_(b'LaPe\xc3\xb1a', 'utf-8'), 'utf-16')
     environ = self._getEnviron(PATH_INFO='/%s' % segment)
     request = DummyRequest(environ)
     self.assertRaises(URLDecodeError, policy, request)
开发者ID:ShakataGaNai,项目名称:learning-pyramid,代码行数:9,代码来源:test_traversal.py


示例12: test_route_url_with_anchor_binary

    def test_route_url_with_anchor_binary(self):
        from pyramid.interfaces import IRoutesMapper

        request = self._makeOne()
        mapper = DummyRoutesMapper(route=DummyRoute("/1/2/3"))
        request.registry.registerUtility(mapper, IRoutesMapper)
        result = request.route_url("flub", _anchor=b"La Pe\xc3\xb1a")

        self.assertEqual(result, native_(text_(b"http://example.com:5432/1/2/3#La Pe\xc3\xb1a", "utf-8"), "utf-8"))
开发者ID:pzatrick,项目名称:pyramid,代码行数:9,代码来源:test_url.py


示例13: test_post_collection_no_id

 def test_post_collection_no_id(self):
     req_body = b'"text","number"\n"abc",2\n'
     res = self.app.post("%s" % self.path,
                         params=req_body,
                         content_type=CsvMime.mime_type_string,
                         status=201)
     self.assert_is_not_none(res)
     self.assert_true(res.headers['Location'].endswith(self.path))
     self.assert_not_equal(native_(res.body).split(os.linesep)[1][:2],
                           '""')
开发者ID:fogathmann,项目名称:everest-thelma,代码行数:10,代码来源:test_views.py


示例14: serialize

def serialize(data, secret):
    import hmac
    import base64
    from hashlib import sha1
    from pyramid.compat import bytes_
    from pyramid.compat import native_
    from pyramid.compat import pickle
    pickled = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
    sig = hmac.new(bytes_(secret, 'utf-8'), pickled, sha1).hexdigest()
    return sig + native_(base64.b64encode(pickled))
开发者ID:dylfaust,项目名称:pyramid,代码行数:10,代码来源:test_session.py


示例15: normalize

def normalize(title):
    """
    make an URL resource name ready for use in a URL. Essentially it
    takes a string representing an id or title and makes it character
    safe for use in a URL. In ``lumin`` this is likely to be the
    :term:`_id` or the :term:`__name__` by which we find the resource.
    """
    url_safer = unicodedata.normalize('NFKD', title).encode('ascii', 'ignore')
    url_safe = re.sub('[^\w\s-]', '', native_(url_safer, encoding="utf8")).strip().lower()
    return re.sub('[-\s]+', '-', url_safe)
开发者ID:joshfinnie,项目名称:lumin,代码行数:10,代码来源:util.py


示例16: test_subpath_path_info_and_script_name_have_utf8

 def test_subpath_path_info_and_script_name_have_utf8(self):
     encoded = native_(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:AndreaCrotti,项目名称:pyramid,代码行数:11,代码来源:test_request.py


示例17: test_handler_w_unicode_unauthenticated_userid

 def test_handler_w_unicode_unauthenticated_userid(self):
     from pyramid.compat import native_
     from pyramid_tm.compat import PY3
     USERID = b'phred/\xd1\x80\xd0\xb5\xd1\x81'.decode('utf-8')
     self.config.testing_securitypolicy(userid=USERID)
     self._callFUT()
     if PY3:  # pragma: no cover Py3k
         self.assertEqual(self.txn.username, ' phred/рес')
     else:
         self.assertEqual(self.txn.username,
                          ' ' + native_(USERID, 'utf-8'))
开发者ID:dstufft,项目名称:pyramid_tm,代码行数:11,代码来源:tests.py


示例18: pre

 def pre(self, command, output_dir, vars):
     if vars['package'] == 'site':
         raise ValueError('Sorry, you may not name your package "site". '
                          'The package name "site" has a special meaning in '
                          'Python.  Please name it anything except "site".')
     vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
     package_logger = vars['package']
     if package_logger == 'root':
         # Rename the app logger in the rare case a project is named 'root'
         package_logger = 'app'
     vars['package_logger'] = package_logger
     return Template.pre(self, command, output_dir, vars)
开发者ID:cloudappsetup,项目名称:pyramid,代码行数:12,代码来源:__init__.py


示例19: 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([native_(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:joulez,项目名称:pyramid,代码行数:53,代码来源:request.py


示例20: test_post_collection_no_id

 def test_post_collection_no_id(self,
                                view_app_creator): # pylint:disable=W0621
     # This only works in the memory backend because of the referential
     # constraint of the parent attribute.
     req_body = b'"text","number"\n"abc",2\n'
     res = view_app_creator.post("%s" % self.path,
                                 params=req_body,
                                 content_type=CsvMime.mime_type_string,
                                 status=201)
     assert not res is None
     assert res.headers['Location'].endswith(self.path)
     assert native_(res.body).split(os.linesep)[1][:2] != '""'
开发者ID:helixyte,项目名称:everest,代码行数:12,代码来源:test_views.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python compat.text_函数代码示例发布时间:2022-05-27
下一篇:
Python compat.iteritems_函数代码示例发布时间: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