本文整理汇总了Python中speaklater.make_lazy_string函数的典型用法代码示例。如果您正苦于以下问题:Python make_lazy_string函数的具体用法?Python make_lazy_string怎么用?Python make_lazy_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_lazy_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unicode_subject
def test_unicode_subject(self):
msg = Message(subject=make_lazy_string(lambda a: a, u"sübject"),
sender='[email protected]',
recipients=["[email protected]"])
self.assertIn(b'=?utf-8?q?s=C3=BCbject?=', msg.as_bytes())
msg = Message(subject=make_lazy_string(lambda a: a, u"[Foo Bar] Voici vos paramètres d'accès à"),
sender='[email protected]',
recipients=["[email protected]"])
self.assertIn(b'=?utf-8?b?W0ZvbyBCYXJdIFZvaWNpIHZvcyBwYXJhbcOodHJlcyBkJ2FjY8OocyDDoA==?=', msg.as_bytes())
示例2: lazy_gettext
def lazy_gettext(string, **variables):
if is_lazy_string(string):
return string
translations = TrytonTranslations(module, 'nereid')
return make_lazy_string(
translations.lazy_ugettext, string, **variables
)
示例3: lazy_gettext
def lazy_gettext(string, **variables):
""" Similar to 'gettext' but the string returned is lazy which means
it will be translated when it is used as an actual string."""
try:
from speaklater import make_lazy_string
return make_lazy_string(gettext, string, **variables)
except ImportError:
return string % variables
示例4: tw2_translation_string
def tw2_translation_string(sval):
def lookup_provided_translator(_sval):
mw = core.request_local().get('middleware')
if not mw:
return _sval
return core.request_local()['middleware'].config.translator(_sval)
return make_lazy_string(lambda: lookup_provided_translator(sval))
示例5: lazy_pgettext
def lazy_pgettext(context, string, **variables):
"""Like :func:`pgettext` but the string returned is lazy which means
it will be translated when it is used as an actual string.
.. versionadded:: 0.7
"""
from speaklater import make_lazy_string
return make_lazy_string(pgettext, context, string, **variables)
示例6: test_lazy_bundle
def test_lazy_bundle():
"""Test lazy bundle."""
bundle = LazyNpmBundle(
make_lazy_string(lambda: 'test{0}.js'.format(1)),
'test2.js'
)
expected = ['test1.js', 'test2.js']
assert expected == bundle.contents
示例7: test_unicode_subject
def test_unicode_subject(self):
try:
from speaklater import make_lazy_string
except ImportError:
return
msg = Message(subject=make_lazy_string(lambda a: a, u"sübject"),
sender='[email protected]',
recipients=["[email protected]"])
self.assertIn('=?utf-8?q?s=C3=BCbject?=', msg.as_string())
示例8: dotslash
def dotslash(self, pth):
"""Mimic the unix './' behaviour."""
if hasattr(self, "APP_DIR"):
return self._get_app_dir(pth=pth)
else:
try:
import speaklater
except ImportError:
raise RuntimeError("Configure django, or install speaklater.")
else:
return speaklater.make_lazy_string(self._get_app_dir, pth)
示例9: tw2_translation_string
def tw2_translation_string(sval):
def lookup_provided_translator(_sval):
mw = core.request_local().get('middleware')
if not mw:
return _sval
try:
return core.request_local()['middleware'].config.translator(_sval)
except TypeError as e:
log.warn(traceback.format_exc())
return _sval
return make_lazy_string(lambda: lookup_provided_translator(sval))
示例10: dotslash
def dotslash(self, pth):
if hasattr(self, "APP_DIR"):
return os.path.join(self.APP_DIR, pth)
else:
try:
import speaklater
except ImportError:
raise RuntimeError(
"configure django first, or install speaklater"
)
else:
return speaklater.make_lazy_string(
self._get_app_dir, pth
)
示例11: lazy_gettext
def lazy_gettext(string, **variables):
"""Like :func:`gettext` but the string returned is lazy which means
it will be translated when it is used as an actual string.
Example::
hello = lazy_gettext(u'Hello World')
@app.route('/')
def index():
return unicode(hello)
"""
from speaklater import make_lazy_string
return make_lazy_string(gettext, string, **variables)
示例12: test_jsonencoder
def test_jsonencoder(self):
"""Test JSON encoder."""
from pybossa.extensions import JSONEncoder
from speaklater import make_lazy_string
encoder = JSONEncoder()
sval = "Hello world"
string = make_lazy_string(lambda: sval)
encoder = JSONEncoder()
data = encoder.encode(dict(foo=string))
data = json.loads(data)
err_msg = "The encoder should manage lazystrings"
assert data.get('foo') == sval, err_msg
示例13: test_lazystring
def test_lazystring(self):
# Skip this test if speaklater is not installed.
try:
from speaklater import make_lazy_string, _LazyString
except ImportError:
return
# test_nospeaklater() overrides this import so we have to revert it
# otherwise the test may fail because flask_json._LazyString
# will be None
flask_json._LazyString = _LazyString
r = json_response(text=make_lazy_string(lambda: u'Привет'))
assert_equals(r.status_code, 200)
assert_equals(r.json['text'], u'Привет')
示例14: lazy_gettext
def lazy_gettext(string):
'''
Like flask_babel's lazy_gettext, but doesn't interpolate strings. This
is required for integration with flask_security, which does its
own string interpolation but doesn't support i18n.
For more information, see: https://github.com/GovLab/noi2/issues/41
'''
def gettext_no_interpolate(string):
t = flask_babel.get_translations()
if t is None:
return string
return t.ugettext(string)
return make_lazy_string(gettext_no_interpolate, string)
示例15: test_column_label_translation
def test_column_label_translation():
app, db, admin = setup()
Model1, _ = create_models(db)
translated = Translator()
label = make_lazy_string(translated, 'Column1')
view = CustomModelView(Model1, db.session,
column_list=['test1', 'test3'],
column_labels=dict(test1=label),
column_filters=('test1',))
translated.translate = True
non_lazy_groups = view._get_filter_groups()
json.dumps(non_lazy_groups) # Filter dict is JSON serializable.
ok_(translated('Column1') in non_lazy_groups) # Label was translated.