本文整理汇总了Python中pyramid.compat.text_函数的典型用法代码示例。如果您正苦于以下问题:Python text_函数的具体用法?Python text_怎么用?Python text_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了text_函数的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}', 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'),
{'traverse':(text_(b'La Pe\xc3\xb1a'), '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:Airwalker1337,项目名称:pyramid,代码行数:25,代码来源:test_urldispatch.py
示例2: test_testing_resources
def test_testing_resources(self):
from pyramid.traversal import find_resource
from pyramid.interfaces import ITraverser
ob1 = object()
ob2 = object()
resources = {'/ob1':ob1, '/ob2':ob2}
config = self._makeOne(autocommit=True)
config.testing_resources(resources)
adapter = config.registry.getAdapter(None, ITraverser)
result = adapter(DummyRequest({'PATH_INFO':'/ob1'}))
self.assertEqual(result['context'], ob1)
self.assertEqual(result['view_name'], '')
self.assertEqual(result['subpath'], ())
self.assertEqual(result['traversed'], (text_('ob1'),))
self.assertEqual(result['virtual_root'], ob1)
self.assertEqual(result['virtual_root_path'], ())
result = adapter(DummyRequest({'PATH_INFO':'/ob2'}))
self.assertEqual(result['context'], ob2)
self.assertEqual(result['view_name'], '')
self.assertEqual(result['subpath'], ())
self.assertEqual(result['traversed'], (text_('ob2'),))
self.assertEqual(result['virtual_root'], ob2)
self.assertEqual(result['virtual_root_path'], ())
self.assertRaises(KeyError, adapter, DummyRequest({'PATH_INFO':'/ob3'}))
try:
config.begin()
self.assertEqual(find_resource(None, '/ob1'), ob1)
finally:
config.end()
开发者ID:7924102,项目名称:pyramid,代码行数:29,代码来源:test_testing.py
示例3: 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
示例4: test_absolute_unicode_found
def test_absolute_unicode_found(self):
# test for bug wiggy found in wild, traceback stack:
# root = u'/%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:ShakataGaNai,项目名称:learning-pyramid,代码行数:29,代码来源:test_traversal.py
示例5: test_it
def test_it(self):
class Dummy:
pass
ob1 = Dummy()
ob2 = Dummy()
resources = {'/ob1':ob1, '/ob2':ob2}
from pyramid import testing
testing.registerResources(resources)
from pyramid.interfaces import ITraverser
adapter = self.registry.getAdapter(None, ITraverser)
result = adapter(DummyRequest({'PATH_INFO':'/ob1'}))
self.assertEqual(result['context'], ob1)
self.assertEqual(result['view_name'], '')
self.assertEqual(result['subpath'], ())
self.assertEqual(result['traversed'], (text_('ob1'),))
self.assertEqual(result['virtual_root'], ob1)
self.assertEqual(result['virtual_root_path'], ())
result = adapter(DummyRequest({'PATH_INFO':'/ob2'}))
self.assertEqual(result['context'], ob2)
self.assertEqual(result['view_name'], '')
self.assertEqual(result['subpath'], ())
self.assertEqual(result['traversed'], (text_('ob2'),))
self.assertEqual(result['virtual_root'], ob2)
self.assertEqual(result['virtual_root_path'], ())
self.assertRaises(KeyError, adapter, DummyRequest({'PATH_INFO':'/ob3'}))
from pyramid.traversal import find_resource
self.assertEqual(find_resource(None, '/ob1'), ob1)
开发者ID:Javex,项目名称:pyramid,代码行数:27,代码来源:test_testing.py
示例6: test_call_with_vh_root_highorder
def test_call_with_vh_root_highorder(self):
bar = DummyContext(None, 'bar')
foo = DummyContext(bar, text_(b'Qu\xc3\xa9bec', 'utf-8'))
root = DummyContext(foo, 'root')
policy = self._makeOne(root)
if PY3: # pragma: no cover
vhm_root = b'/Qu\xc3\xa9bec'.decode('latin-1')
else:
vhm_root = b'/Qu\xc3\xa9bec'
environ = self._getEnviron(HTTP_X_VHM_ROOT=vhm_root,
PATH_INFO='/bar')
request = DummyRequest(environ)
result = policy(request)
self.assertEqual(result['context'], bar)
self.assertEqual(result['view_name'], '')
self.assertEqual(result['subpath'], ())
self.assertEqual(
result['traversed'],
(text_(b'Qu\xc3\xa9bec', 'utf-8'), text_('bar'))
)
self.assertEqual(result['root'], policy.root)
self.assertEqual(result['virtual_root'], foo)
self.assertEqual(
result['virtual_root_path'],
(text_(b'Qu\xc3\xa9bec', 'utf-8'),)
)
开发者ID:ShakataGaNai,项目名称:learning-pyramid,代码行数:26,代码来源:test_traversal.py
示例7: 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:Airwalker1337,项目名称:pyramid,代码行数:7,代码来源:test_urldispatch.py
示例8: response
def response(self):
return Response(
body=self.gf.read(),
content_disposition='attachment; filename={}'.format(
text_(self.gf.filename, encoding='utf8')),
content_type=text_(self.gf.content_type, encoding='utf8') if \
self.gf.content_type else 'binary/octet-stream',
content_length=self.gf.length
)
开发者ID:pombredanne,项目名称:lumin,代码行数:9,代码来源:grid_fs.py
示例9: test___call__traverse_matches_with_highorder_chars
def test___call__traverse_matches_with_highorder_chars(self):
inst = self._makeOne(text_(b"/La Pe\xc3\xb1a/{x}", "utf-8"))
info = {"match": {"x": text_(b"Qu\xc3\xa9bec", "utf-8")}}
request = Dummy()
result = inst(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:B-Rich,项目名称:pyramid,代码行数:9,代码来源:test_predicates.py
示例10: 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:Airwalker1337,项目名称:pyramid,代码行数:9,代码来源:test_urldispatch.py
示例11: test_route_url_with_anchor_unicode
def test_route_url_with_anchor_unicode(self):
from pyramid.interfaces import IRoutesMapper
request = self._makeOne()
mapper = DummyRoutesMapper(route=DummyRoute("/1/2/3"))
request.registry.registerUtility(mapper, IRoutesMapper)
anchor = text_(b"La Pe\xc3\xb1a", "utf-8")
result = request.route_url("flub", _anchor=anchor)
self.assertEqual(result, native_(text_(b"http://example.com:5432/1/2/3#La Pe\xc3\xb1a", "utf-8"), "utf-8"))
开发者ID:pzatrick,项目名称:pyramid,代码行数:10,代码来源:test_url.py
示例12: object_description
def object_description(object):
""" Produce a human-consumable text description of ``object``,
usually involving a Python dotted name. For example:
>>> object_description(None)
u'None'
>>> from xml.dom import minidom
>>> object_description(minidom)
u'module xml.dom.minidom'
>>> object_description(minidom.Attr)
u'class xml.dom.minidom.Attr'
>>> object_description(minidom.Attr.appendChild)
u'method appendChild of class xml.dom.minidom.Attr'
If this method cannot identify the type of the object, a generic
description ala ``object <object.__name__>`` will be returned.
If the object passed is already a string, it is simply returned. If it
is a boolean, an integer, a list, a tuple, a set, or ``None``, a
(possibly shortened) string representation is returned.
"""
if isinstance(object, string_types):
return text_(object)
if isinstance(object, integer_types):
return text_(str(object))
if isinstance(object, (bool, float, type(None))):
return text_(str(object))
if isinstance(object, set):
if PY3: # pragma: no cover
return shortrepr(object, '}')
else:
return shortrepr(object, ')')
if isinstance(object, tuple):
return shortrepr(object, ')')
if isinstance(object, list):
return shortrepr(object, ']')
if isinstance(object, dict):
return shortrepr(object, '}')
module = inspect.getmodule(object)
if module is None:
return text_('object %s' % str(object))
modulename = module.__name__
if inspect.ismodule(object):
return text_('module %s' % modulename)
if inspect.ismethod(object):
oself = getattr(object, '__self__', None)
if oself is None: # pragma: no cover
oself = getattr(object, 'im_self', None)
return text_('method %s of class %s.%s' %
(object.__name__, modulename,
oself.__class__.__name__))
if inspect.isclass(object):
dottedname = '%s.%s' % (modulename, object.__name__)
return text_('class %s' % dottedname)
if inspect.isfunction(object):
dottedname = '%s.%s' % (modulename, object.__name__)
return text_('function %s' % dottedname)
return text_('object %s' % str(object))
开发者ID:JensRantil,项目名称:pyramid,代码行数:59,代码来源:util.py
示例13: test___call__traverse_matches_with_highorder_chars
def test___call__traverse_matches_with_highorder_chars(self):
inst = self._makeOne(text_(b'/La Pe\xc3\xb1a/{x}', 'utf-8'))
info = {'match':{'x':text_(b'Qu\xc3\xa9bec', 'utf-8')}}
request = Dummy()
result = inst(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:jvanasco,项目名称:pyramid,代码行数:11,代码来源:test_predicates.py
示例14: test_add_mako_renderer
def test_add_mako_renderer(self):
from pyramid.renderers import render
self.config.add_settings({'foo.directories':
'pyramid_mako.tests:fixtures'})
self.config.add_mako_renderer('.foo', settings_prefix='foo.')
result = render('nonminimal.foo',
{'name': '<b>fred</b>'}).replace('\r', '')
self.assertEqual(result, text_('Hello, <b>fred</b>!\n'))
result = render('fixtures/nonminimal.mak',
{'name': '<b>fred</b>'}).replace('\r', '')
self.assertEqual(result, text_('Hello, <b>fred</b>!\n'))
开发者ID:Rafails,项目名称:MyCalc,代码行数:11,代码来源:tests.py
示例15: test_messages_error_msg
def test_messages_error_msg(self):
add_message(self.request, 'error', 'error')
self.assertEqual(
render_messages(self.request).strip(),
text_('<div class="alert alert-error alert-danger">\n <a class="close" data-dismiss="alert">×</a>\n error\n</div>','utf-8'))
add_message(self.request, ValueError('Error'), 'error')
self.assertEqual(
render_messages(self.request).strip(),
text_('<div class="alert alert-error alert-danger">\n <a class="close" data-dismiss="alert">×</a>\n ValueError: Error\n</div>','utf-8'))
开发者ID:fafhrd91,项目名称:player,代码行数:11,代码来源:test_message.py
示例16: pre
def pre(self, command, output_dir, vars):
vars['random_string'] = native_(binascii.hexlify(os.urandom(20)))
# placeholder text values
vars['one'] = text_('one')
vars['two'] = text_('two')
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:slmf,项目名称:pyramid,代码行数:11,代码来源:__init__.py
示例17: 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
示例18: 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:IDSGPlayground,项目名称:pyramid-tutorial-yuxin-aaron,代码行数:12,代码来源:test_routes.py
示例19: test_messages_error_msg
def test_messages_error_msg(self):
from ptah import view
self.init_ptah()
view.add_message(self.request, 'error', 'error')
self.assertEqual(
view.render_messages(self.request),
text_('<div class="alert alert-error">\n <a class="close" data-dismiss="alert">×</a>\n error\n</div>\n','utf-8'))
view.add_message(self.request, ValueError('Error'), 'error')
self.assertEqual(
view.render_messages(self.request),
text_('<div class="alert alert-error">\n <a class="close" data-dismiss="alert">×</a>\n ValueError: Error\n</div>\n','utf-8'))
开发者ID:webmaven,项目名称:ptah,代码行数:13,代码来源:test_view.py
示例20: test_call_with_defname_with_tuple_value_twice
def test_call_with_defname_with_tuple_value_twice(self):
lookup = DummyLookup()
instance1 = self._makeOne('path', 'defname', lookup)
result1 = instance1(('defname1', {}), {'context':1})
self.assertEqual(lookup.deffed, 'defname1')
self.assertEqual(result1, text_('result'))
self.assertEqual(lookup.values, {'_context':1})
instance2 = self._makeOne('path', 'defname', lookup)
result2 = instance2(('defname2', {}), {'context':2})
self.assertNotEqual(lookup.deffed, 'defname1')
self.assertEqual(lookup.deffed, 'defname2')
self.assertEqual(result2, text_('result'))
self.assertEqual(lookup.values, {'_context':2})
开发者ID:Rafails,项目名称:MyCalc,代码行数:13,代码来源:test_mako_templating.py
注:本文中的pyramid.compat.text_函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论