本文整理汇总了Python中speaklater.make_lazy_string函数的典型用法代码示例。如果您正苦于以下问题:Python make_lazy_string函数的具体用法?Python make_lazy_string怎么用?Python make_lazy_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了make_lazy_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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())
开发者ID:decaz,项目名称:flask-mail,代码行数:10,代码来源:tests.py
示例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
)
开发者ID:fulfilio,项目名称:nereid,代码行数:7,代码来源:locale.py
示例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
开发者ID:1npo,项目名称:Flask-User,代码行数:8,代码来源:translations.py
示例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))
开发者ID:lmacken,项目名称:tw2.core,代码行数:8,代码来源:i18n.py
示例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)
开发者ID:dpgaspar,项目名称:flask-babelPkg,代码行数:8,代码来源:__init__.py
示例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
开发者ID:tiborsimko,项目名称:invenio-assets,代码行数:9,代码来源:test_npm.py
示例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())
开发者ID:nwebs,项目名称:flask-mail,代码行数:9,代码来源:tests.py
示例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)
开发者ID:intiveda,项目名称:importd,代码行数:11,代码来源:__init__.py
示例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))
开发者ID:decause,项目名称:tw2.core,代码行数:13,代码来源:i18n.py
示例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
)
开发者ID:iapilgrim,项目名称:importd,代码行数:14,代码来源:__init__.py
示例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)
开发者ID:dpgaspar,项目名称:flask-babelPkg,代码行数:14,代码来源:__init__.py
示例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
开发者ID:fiorda,项目名称:pybossa,代码行数:14,代码来源:test_util.py
示例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'Привет')
开发者ID:mrevening,项目名称:flask-json,代码行数:15,代码来源:test_encode.py
示例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)
开发者ID:batusayici,项目名称:noi2,代码行数:16,代码来源:l10n.py
示例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.
开发者ID:immon,项目名称:flask-admin,代码行数:17,代码来源:test_translation.py
示例16: 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:
translator = get_translator(mw.config.get_lang())
except AttributeError:
try:
translator = mw.config.translator
except AttributeError:
return _sval
return translator(_sval)
return make_lazy_string(lambda: lookup_provided_translator(sval))
开发者ID:LeResKP,项目名称:tw2.core,代码行数:18,代码来源:i18n.py
示例17: 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',))
admin.add_view(view)
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.
client = app.test_client()
# Render index with active filter.
rv = client.get('/admin/model1/?flt1_0=test')
eq_(rv.status_code, 200)
开发者ID:ProjectMonsoon,项目名称:app,代码行数:23,代码来源:test_translation.py
示例18: ngettext
def ngettext(self, singular, plural, n):
return make_lazy_string(_ngettext, singular, plural, n)
开发者ID:fernandopassoz,项目名称:news,代码行数:2,代码来源:i18n.py
示例19: lazy_gettext
def lazy_gettext(*args, **kwargs):
"""Lazy gettext.
https://github.com/mrjoes/flask-babelex/pull/8
"""
return make_lazy_string(gettext, *args, **kwargs)
开发者ID:tiborsimko,项目名称:invenio-theme,代码行数:6,代码来源:app.py
示例20: lazy_gettext
def lazy_gettext(string, *args, **kwargs):
if is_lazy_string(string):
return string
return make_lazy_string(lookup_func(), string, *args, **kwargs)
开发者ID:realer01,项目名称:aiohttp_babel,代码行数:4,代码来源:middlewares.py
注:本文中的speaklater.make_lazy_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论