本文整理汇总了Python中speaklater.is_lazy_string函数的典型用法代码示例。如果您正苦于以下问题:Python is_lazy_string函数的具体用法?Python is_lazy_string怎么用?Python is_lazy_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_lazy_string函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: group
def group(self):
if isinstance(self._group, basestring):
return self._group
elif speaklater.is_lazy_string(self._group):
return self._group.value
else:
return self._group()
示例2: default
def default(self, obj):
if is_lazy_string(obj):
try:
return unicode(obj) #python 2
except NameError:
return str(obj) #python 3
return super(CustomJSONEncoder, self).default(obj)
示例3: serialize
def serialize(obj, additional_attrs=(), ignore_error=False):
"""Converts some kinds of object to serilized object. (In fact, it does
not serialize object, but converts to generally serializable object.)
"""
if obj is None:
return None
elif isinstance(obj, tuple(_user_model_map.keys())):
for type in _user_model_map.iterkeys():
if isinstance(obj, type):
return _user_model_map[type](obj, additional_attrs,
ignore_error)
elif callable(getattr(obj, 'serialize', None)):
d = obj.serialize()
d.update(_serialize_addtional(obj, additional_attrs, ignore_error))
return d
elif ismoduleinstance(obj, 'werkzeug.FileStorage'): # Werkzeug filestorage
return _serialize_file_storage(obj, additional_attrs, ignore_error)
elif isinstance(obj, datetime):
return _serialize_date(obj, additional_attrs, ignore_error)
elif isinstance(obj, tuple):
return tuple(map(lambda x:serialize(x, additional_attrs, ignore_error),
obj))
elif isinstance(obj, (numbers.Number, basestring)):
return obj
elif is_lazy_string(obj):
return u(obj)
elif isinstance(obj, collections.Mapping):
d={}
for k, v in dict(obj).iteritems():
d[k] = serialize(v, additional_attrs, ignore_error)
return d
elif is_list_like(obj):
return [serialize(x, additional_attrs, ignore_error) for x in obj]
else:
raise NotSerializable(repr(obj))
示例4: _wrapper
def _wrapper(*args, **kwargs):
rv = f(*args, **kwargs)
if not rv:
return ""
if is_lazy_string(rv):
rv = rv.value
return rv.encode("utf-8") if isinstance(rv, unicode) else str(rv)
示例5: 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
)
示例6: default
def default(self, o):
from speaklater import is_lazy_string
if is_lazy_string(o):
try:
return unicode(o)
except NameError:
return str(o)
return super(CustomJSONEncoder, self).default(o)
示例7: _prepare_excel_data
def _prepare_excel_data(data):
if isinstance(data, (list, tuple)):
data = ', '.join(data)
elif isinstance(data, set):
data = ', '.join(sorted(data, key=unicode.lower))
elif is_lazy_string(data) or isinstance(data, Markup):
data = unicode(data)
return data
示例8: get_message
def get_message(key, **kwargs):
rv = config_value('MSG_' + key)
if is_lazy_string:
if is_lazy_string(rv[0]):
return unicode(rv[0]) % kwargs, rv[1]
return rv[0] % kwargs, rv[1]
示例9: test_title
def test_title(db):
user = User(first_name='Guinea', last_name='Pig')
db.session.add(user)
db.session.flush()
assert user.title == ''
user.title = UserTitle.prof
assert user.title == UserTitle.prof.title
assert is_lazy_string(user.title)
assert User.find_one(title=UserTitle.prof) == user
示例10: fix_xls_value
def fix_xls_value(value):
"""
Perform any data type fixes that must be made
prior to sending a value to be written by the spreadsheet library
"""
if is_lazy_string(value):
return six.text_type(value)
return value
示例11: _prepare_excel_data
def _prepare_excel_data(data, tz=None):
if isinstance(data, (list, tuple)):
data = ', '.join(data)
elif isinstance(data, set):
data = ', '.join(sorted(data, key=unicode.lower))
elif is_lazy_string(data) or isinstance(data, Markup):
data = unicode(data)
elif isinstance(data, datetime):
data = format_datetime(data, timezone=tz).decode('utf-8')
return data
示例12: default
def default(self, obj):
if is_lazy_string(obj):
return unicode(obj)
elif isinstance(obj, bson.objectid.ObjectId):
return str(obj)
elif isinstance(obj, datetime.datetime):
return obj.isoformat()
elif hasattr(obj, 'serialize'):
return obj.serialize()
elif hasattr(obj, '_data'): # Serialize Raw data for Document and EmbeddedDocument
return obj._data
return super(UDataJsonEncoder, self).default(obj)
示例13: encode
def encode(self, obj, *args, **kwargs):
if isinstance(obj, dict):
new_obj = type(obj)()
for key, value in six.iteritems(obj):
if is_lazy_string(key):
try:
key = unicode(key)
except NameError:
key = str(key)
new_obj[key] = value
obj = new_obj
return super(JSONEncoder, self).encode(obj, *args, **kwargs)
示例14: _validate
def _validate(var):
if isinstance(var, (tuple, list)):
for i, v in enumerate(var):
var[i] = _validate(v)
elif isinstance(var, dict):
for k in var:
var[k] = _validate(var[k])
else:
if is_lazy_string(var):
return unicode(var)
return var
return var
示例15: default
def default(self, obj):
if is_lazy_string(obj):
return unicode(obj)
elif isinstance(obj, bson.objectid.ObjectId):
return str(obj)
elif isinstance(obj, datetime.datetime):
return obj.isoformat()
elif hasattr(obj, 'to_dict'):
return obj.to_dict()
elif hasattr(obj, 'serialize'):
return obj.serialize()
# Serialize Raw data for Document and EmbeddedDocument.
elif hasattr(obj, '_data'):
return obj._data
# Serialize raw data from Elasticsearch DSL AttrList
elif hasattr(obj, '_l_'):
return obj._l_
return super(UDataJsonEncoder, self).default(obj)