当前位置: 首页>>代码示例>>Python>>正文


Python speaklater.is_lazy_string函数代码示例

本文整理汇总了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()
开发者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


注:本文中的speaklater.is_lazy_string函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。