本文整理汇总了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'})
示例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
])
示例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()
},
)
示例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
])
示例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"))
示例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
示例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)
示例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
示例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)
示例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))))
示例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)
示例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"))
示例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],
'""')
示例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))
示例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)