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


Python python_support.txt_type函数代码示例

本文整理汇总了Python中mongoengine.python_support.txt_type函数的典型用法代码示例。如果您正苦于以下问题:Python txt_type函数的具体用法?Python txt_type怎么用?Python txt_type使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了txt_type函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __str__

 def __str__(self):
     if hasattr(self, '__unicode__'):
         if PY3:
             return self.__unicode__()
         else:
             return unicode(self).encode('utf-8')
     return txt_type('%s object' % self.__class__.__name__)
开发者ID:haudoing,项目名称:mongoengine,代码行数:7,代码来源:document.py

示例2: __str__

 def __str__(self):
     return txt_type(self.message)
开发者ID:99co,项目名称:mongoengine,代码行数:2,代码来源:errors.py

示例3: _attach_objects

    def _attach_objects(self, items, depth=0, instance=None, name=None):
        """
        Recursively finds all db references to be dereferenced

        :param items: The iterable (dict, list, queryset)
        :param depth: The current depth of recursion
        :param instance: The owning instance used for tracking changes by
            :class:`~mongoengine.base.ComplexBaseField`
        :param name: The name of the field, used for tracking changes by
            :class:`~mongoengine.base.ComplexBaseField`
        """
        if not items:
            if isinstance(items, (BaseDict, BaseList)):
                return items

            if instance:
                if isinstance(items, dict):
                    return BaseDict(items, instance, name)
                else:
                    return BaseList(items, instance, name)

        if isinstance(items, (dict, SON)):
            if '_ref' in items:
                return self.object_map.get(
                    (items['_ref'].collection, items['_ref'].id), items)
            elif '_cls' in items:
                doc = get_document(items['_cls'])._from_son(items)
                _cls = doc._data.pop('_cls', None)
                del items['_cls']
                doc._data = self._attach_objects(doc._data, depth, doc, None)
                if _cls is not None:
                    doc._data['_cls'] = _cls
                return doc

        if not hasattr(items, 'items'):
            is_list = True
            list_type = BaseList
            if isinstance(items, EmbeddedDocumentList):
                list_type = EmbeddedDocumentList
            as_tuple = isinstance(items, tuple)
            iterator = enumerate(items)
            data = []
        else:
            is_list = False
            iterator = items.iteritems()
            data = {}

        depth += 1
        for k, v in iterator:
            if is_list:
                data.append(v)
            else:
                data[k] = v

            if k in self.object_map and not is_list:
                data[k] = self.object_map[k]
            elif isinstance(v, (Document, EmbeddedDocument)):
                for field_name, field in v._fields.iteritems():
                    v = data[k]._data.get(field_name, None)
                    if isinstance(v, DBRef):
                        data[k]._data[field_name] = self.object_map.get(
                            (v.collection, v.id), v)
                    elif isinstance(v, (dict, SON)) and '_ref' in v:
                        data[k]._data[field_name] = self.object_map.get(
                            (v['_ref'].collection, v['_ref'].id), v)
                    elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
                        item_name = txt_type("{0}.{1}.{2}").format(name, k, field_name)
                        data[k]._data[field_name] = self._attach_objects(v, depth, instance=instance, name=item_name)
            elif isinstance(v, (dict, list, tuple)) and depth <= self.max_depth:
                item_name = '%s.%s' % (name, k) if name else name
                data[k] = self._attach_objects(v, depth - 1, instance=instance, name=item_name)
            elif hasattr(v, 'id'):
                data[k] = self.object_map.get((v.collection, v.id), v)

        if instance and name:
            if is_list:
                return tuple(data) if as_tuple else list_type(data, instance, name)
            return BaseDict(data, instance, name)
        depth += 1
        return data
开发者ID:3lnc,项目名称:mongoengine,代码行数:80,代码来源:dereference.py


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