本文整理汇总了Python中speaklater.is_lazy_string函数的典型用法代码示例。如果您正苦于以下问题:Python is_lazy_string函数的具体用法?Python is_lazy_string怎么用?Python is_lazy_string使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了is_lazy_string函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:xiechao06,项目名称:Flask-NavBar,代码行数:7,代码来源:flask_nav_bar.py
示例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)
开发者ID:metaregress,项目名称:flaskBlog,代码行数:7,代码来源:__init__.py
示例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))
开发者ID:Hardtack,项目名称:Issue-Server,代码行数:35,代码来源:serializer.py
示例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)
开发者ID:OmeGak,项目名称:indico,代码行数:7,代码来源:string.py
示例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
)
开发者ID:fulfilio,项目名称:nereid,代码行数:7,代码来源:locale.py
示例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)
开发者ID:djsolar,项目名称:microblog,代码行数:8,代码来源:__init__.py
示例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
开发者ID:OmeGak,项目名称:indico,代码行数:8,代码来源:spreadsheets.py
示例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]
开发者ID:kiik,项目名称:flask-security,代码行数:8,代码来源:utils.py
示例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
开发者ID:DirkHoffmann,项目名称:indico,代码行数:9,代码来源:users_test.py
示例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
开发者ID:level12,项目名称:webgrid,代码行数:9,代码来源:renderers.py
示例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
开发者ID:DirkHoffmann,项目名称:indico,代码行数:10,代码来源:spreadsheets.py
示例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)
开发者ID:pombredanne,项目名称:udata,代码行数:12,代码来源:app.py
示例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)
开发者ID:Kiolali,项目名称:weblabdeusto,代码行数:12,代码来源:app.py
示例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
开发者ID:ObjNotFound,项目名称:kaca,代码行数:12,代码来源:helper.py
示例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)
开发者ID:opendatateam,项目名称:udata,代码行数:18,代码来源:app.py
示例16: flash
def flash(message, category='message'):
"""
Lazy strings are no real strings so pickling them results in strange issues.
Pickling cannot be avoided because of the way sessions work. Hence, this
special flash function converts lazy strings to unicode content.
.. versionadded:: 3.0.4.1
:param message: the message to be flashed.
:param category: the category for the message. The following values
are recommended: ``'message'`` for any kind of message,
``'error'`` for errors, ``'info'`` for information
messages and ``'warning'`` for warnings. However any
kind of string can be used as category.
"""
if is_lazy_string(message):
message = unicode(message)
return _flash(message, category)
开发者ID:fulfilio,项目名称:nereid,代码行数:18,代码来源:helpers.py
示例17: prepare
def prepare(self):
super(CookieConsentWidget, self).prepare()
if self.options:
cfg = self.options
else:
cfg = self.default_options
# always use full URLs for themes
theme = cfg.get('theme', 'light-floating')
rl = request_local()
cfg['theme'] = (
rl['middleware'].config.res_prefix + 'tw2.cookieconsent/static/'
+ theme + ".css")
# evaluate any lazy strings
for key, value in cfg.items():
if is_lazy_string(value):
cfg[key] = str(value)
self.add_call(js_function(
"(function(window,cfg){window.cookieconsent_options=cfg;})"
)(js_symbol("window"), cfg), location='head')
inject_resources()
开发者ID:nphilipp,项目名称:tw2.cookieconsent,代码行数:24,代码来源:widgets.py
示例18: 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
示例19: default
def default(self, obj):
from speaklater import is_lazy_string
if is_lazy_string(obj):
return str(obj) # python 3
return super(CustomJSONEncoder, self).default(obj)
开发者ID:JMourisca,项目名称:Tutorial,代码行数:5,代码来源:__init__.py
示例20: scaffold_filters
def scaffold_filters(self, name):
"""
Return list of enabled filters
"""
attr, joins = tools.get_field_with_path(self.model, name)
if attr is None:
raise Exception('Failed to find field for filter: %s' % name)
# Figure out filters for related column
if is_relationship(attr):
filters = []
for p in self._get_model_iterator(attr.property.mapper.class_):
if hasattr(p, 'columns'):
# TODO: Check for multiple columns
column = p.columns[0]
if column.foreign_keys or column.primary_key:
continue
visible_name = '%s / %s' % (self.get_column_name(attr.prop.table.name),
self.get_column_name(p.key))
type_name = type(column.type).__name__
flt = self.filter_converter.convert(type_name,
column,
visible_name)
if flt:
table = column.table
if joins:
self._filter_joins[column] = joins
elif tools.need_join(self.model, table):
self._filter_joins[column] = [table]
filters.extend(flt)
return filters
else:
is_hybrid_property = tools.is_hybrid_property(self.model, name)
if is_hybrid_property:
column = attr
if isinstance(name, string_types):
column.key = name.split('.')[-1]
else:
columns = tools.get_columns_for_field(attr)
if len(columns) > 1:
raise Exception('Can not filter more than on one column for %s' % name)
column = columns[0]
# If filter related to relation column (represented by
# relation_name.target_column) we collect here relation name
joined_column_name = None
if '.' in name:
joined_column_name = name.split('.')[0]
# Join not needed for hybrid properties
if (not is_hybrid_property and tools.need_join(self.model, column.table) and
name not in self.column_labels):
if joined_column_name:
visible_name = '%s / %s / %s' % (
joined_column_name,
self.get_column_name(column.table.name),
self.get_column_name(column.name)
)
else:
visible_name = '%s / %s' % (
self.get_column_name(column.table.name),
self.get_column_name(column.name)
)
else:
if not isinstance(name, string_types):
visible_name = self.get_column_name(name.property.key)
else:
column_name = self.get_column_name(name)
def prettify():
return column_name.replace('.', ' / ')
if is_lazy_string(column_name):
visible_name = make_lazy_string(prettify)
else:
visible_name = prettify()
type_name = type(column.type).__name__
flt = self.filter_converter.convert(
type_name,
column,
visible_name,
options=self.column_choices.get(name),
)
key_name = column
# In case of filter related to relation column filter key
# must be named with relation name (to prevent following same
#.........这里部分代码省略.........
开发者ID:gordol,项目名称:flask-admin,代码行数:101,代码来源:view.py
注:本文中的speaklater.is_lazy_string函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论