本文整理汇总了Python中tg._compat.u_函数的典型用法代码示例。如果您正苦于以下问题:Python u_函数的具体用法?Python u_怎么用?Python u_使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了u_函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode
def test_unicode():
"""url() can handle unicode parameters"""
create_request("/")
unicodestring = u_('àèìòù')
eq_(url('/', params=dict(x=unicodestring)),
'/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
)
示例2: test_unicode
def test_unicode():
"""url() can handle unicode parameters"""
with test_context(None, '/'):
unicodestring = u_('àèìòù')
eq_(url('/', params=dict(x=unicodestring)),
'/?x=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
)
示例3: test_custom_failure_message
def test_custom_failure_message(self):
message = u_('This is a custom message whose id is: %(id_number)s')
id_number = 23
p = EqualsFour(msg=message)
try:
p.unmet(message, id_number=id_number)
self.fail('An exception must have been raised')
except predicates.NotAuthorizedError as e:
self.assertEqual(unicode_text(e), message % dict(id_number=id_number))
示例4: test_content_type
def test_content_type(self):
r = Response()
r.content_type = u_('text/html')
# Verify it's a native string, and not unicode.
assert type(r.content_type) == str
assert r.content_type == 'text/html'
del r.content_type
assert r.content_type is None
示例5: test_unauthorized_with_unicode_message
def test_unauthorized_with_unicode_message(self):
# This test is broken on Python 2.4 and 2.5 because the unicode()
# function doesn't work when converting an exception into an unicode
# string (this is, to extract its message).
unicode_msg = u_('请登陆')
environ = {'test_number': 3}
p = EqualsFour(msg=unicode_msg)
try:
p.check_authorization(environ)
self.fail('Authorization must have been rejected')
except predicates.NotAuthorizedError as e:
self.assertEqual(unicode_text(e), unicode_msg)
示例6: test_form_validation_translation
def test_form_validation_translation(self):
if PY3: raise SkipTest()
"""Test translation of form validation error messages"""
form_values = {'title': 'Razer', 'year': "t007"}
# check with language set in request header
resp = self.app.post('/process_form', form_values,
headers={'Accept-Language': 'de,ru,it'})
values = loads(resp.body.decode('utf-8'))
assert "Bitte eine ganze Zahl eingeben" in values['errors']['year'], \
'No German error message: %r' % values['errors']
resp = self.app.post('/process_form', form_values,
headers={'Accept-Language': 'ru,de,it'})
values = loads(resp.body.decode('utf-8'))
assert u_("Введите числовое значение") in values['errors']['year'], \
'No Russian error message: %r' % values['errors']
# check with language set in session
self.app.post('/set_lang/de')
resp = self.app.post('/process_form', form_values,
headers={'Accept-Language': 'ru,it'})
values = loads(resp.body.decode('utf-8'))
assert "Bitte eine ganze Zahl eingeben" in values['errors']['year'], \
'No German error message: %r' % values['errors']
示例7: test_form_validation_translation
def test_form_validation_translation(self):
if PY3:
raise SkipTest()
"""Test translation of form validation error messages"""
form_values = {"title": "Razer", "year": "t007"}
# check with language set in request header
resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "de,ru,it"})
values = loads(resp.body.decode("utf-8"))
assert "Bitte eine ganze Zahl eingeben" in values["errors"]["year"], (
"No German error message: %r" % values["errors"]
)
resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "ru,de,it"})
values = loads(resp.body.decode("utf-8"))
assert u_("Введите числовое значение") in values["errors"]["year"], (
"No Russian error message: %r" % values["errors"]
)
# check with language set in session
self.app.post("/set_lang/de")
resp = self.app.post("/process_form", form_values, headers={"Accept-Language": "ru,it"})
values = loads(resp.body.decode("utf-8"))
assert "Bitte eine ganze Zahl eingeben" in values["errors"]["year"], (
"No German error message: %r" % values["errors"]
)
示例8: test_url_unicode_nonascii
def test_url_unicode_nonascii():
res = url('.', {'p1':u_('àèìòù')})
assert res == '.?p1=%C3%A0%C3%A8%C3%AC%C3%B2%C3%B9'
示例9: flash_unicode
def flash_unicode(self):
tg.flash(u_("Привет, мир!"))
tg.redirect("/flash_after_redirect")
示例10: test_flash_unicode
def test_flash_unicode():
resp = app.get('/flash_unicode').follow()
content = resp.body.decode('utf8')
assert u_('Привет, мир!') in content, content
示例11: test_url_unicode
def test_url_unicode():
res = url('.', {'p1':u_('v1')})
assert res == '.?p1=v1'
示例12: test_list
def test_list():
"""url() can handle list parameters, with unicode too"""
create_request("/")
value = url('/', params=dict(foo=['bar', u_('à')])),
assert '/?foo=bar&foo=%C3%A0' in value, value
示例13: test_jinja_i18n_de
def test_jinja_i18n_de():
app = setup_noDB()
resp = app.get('/jinja_i18n_de')
assert u_("Ihre Anwendung läuft jetzt einwandfrei") in resp
示例14: test_unicode_messages
def test_unicode_messages(self):
unicode_msg = u_('请登陆')
p = EqualsTwo(msg=unicode_msg)
environ = {'test_number': 3}
self.eval_unmet_predicate(p, environ, unicode_msg)
示例15: test_list
def test_list():
"""url() can handle list parameters, with unicode too"""
with test_context(None, '/'):
value = url('/', params=dict(foo=['bar', u_('à')])),
assert '/?foo=bar&foo=%C3%A0' in value, value