当前位置: 首页>>代码示例>>Python>>正文


Python compat.native_函数代码示例

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


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


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