python类deserialize()的实例源码

test_django.py 文件源码 项目:deb-python-semantic-version 作者: openstack 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_serialization(self):
        o1 = models.VersionModel(version=Version('0.1.1'), spec=Spec('==0.1.1,!=0.1.1-alpha'))
        o2 = models.VersionModel(version=Version('0.4.3-rc3+build3'),
            spec=Spec('<=0.1.1-rc2,!=0.1.1-rc1'))

        data = serializers.serialize('json', [o1, o2])

        obj1, obj2 = serializers.deserialize('json', data)
        self.assertEqual(o1.version, obj1.object.version)
        self.assertEqual(o1.spec, obj1.object.spec)
        self.assertEqual(o2.version, obj2.object.version)
        self.assertEqual(o2.spec, obj2.object.spec)
test_bitmask_field.py 文件源码 项目:django-bitmask-field 作者: renskiy 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def test_bitmaskfield_serialization_deserialization(self):
        cases = dict(
            none=None,
            regualar=42,
        )
        for case, expected_value in cases.items():
            with self.subTest(case=case):
                model = TestModel(bitmask=expected_value)
                serialized_data = serializers.serialize("xml", [model])
                deserialized_data = list(serializers.deserialize('xml', serialized_data))
                deserialized_model = deserialized_data[0].object
                self.assertEqual(expected_value, deserialized_model.bitmask)
__init__.py 文件源码 项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:travlr 作者: gauravkulkarni96 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:logo-gen 作者: jellene4eva 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
creation.py 文件源码 项目:liberator 作者: libscie 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def deserialize_db_from_string(self, data):
        """
        Reloads the database with data from a string generated by
        the serialize_db_to_string method.
        """
        data = StringIO(data)
        for obj in serializers.deserialize("json", data, using=self.connection.alias):
            obj.save()
__init__.py 文件源码 项目:gmail_scanner 作者: brandonhub 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
creation.py 文件源码 项目:djanoDoc 作者: JustinChavez 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def deserialize_db_from_string(self, data):
        """
        Reloads the database with data from a string generated by
        the serialize_db_to_string method.
        """
        data = StringIO(data)
        for obj in serializers.deserialize("json", data, using=self.connection.alias):
            obj.save()
__init__.py 文件源码 项目:CSCE482-WordcloudPlus 作者: ggaytan00 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:tissuelab 作者: VirtualPlants 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is a instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
db_utils.py 文件源码 项目:issue-reporting 作者: 6aika 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def execute_fixture(name):
    filename = os.path.join(FIXTURE_DIR, name + '.json')
    connection = connections["default"]
    with connection.constraint_checks_disabled():
        with open(filename, "r") as stream:
            objects = serializers.deserialize("json", stream)
            for obj in objects:
                if hasattr(obj.object, "_cache_data"):
                    obj.object._cache_data()
                obj.save()
__init__.py 文件源码 项目:producthunt 作者: davidgengler 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
__init__.py 文件源码 项目:django-rtc 作者: scifiswapnil 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
models.py 文件源码 项目:mes 作者: osess 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def object_version(self):
        """The stored version of the model."""
        data = self.serialized_data
        data = force_text(data.encode("utf8"))
        return list(serializers.deserialize(self.format, data, ignorenonexistent=True))[0]
__init__.py 文件源码 项目:geekpoint 作者: Lujinghu 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
backup.py 文件源码 项目:Sentry 作者: NetEaseGame 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def import_(src):
    "Imports data from a Sentry export."

    from django.core import serializers
    for obj in serializers.deserialize("json", src, stream=True, use_natural_keys=True):
        obj.save()
__init__.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
def deserialize(format, stream_or_string, **options):
    """
    Deserialize a stream or a string. Returns an iterator that yields ``(obj,
    m2m_relation_dict)``, where ``obj`` is an instantiated -- but *unsaved* --
    object, and ``m2m_relation_dict`` is a dictionary of ``{m2m_field_name :
    list_of_related_objects}``.
    """
    d = get_deserializer(format)
    return d(stream_or_string, **options)
creation.py 文件源码 项目:django-next-train 作者: bitpixdigital 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def deserialize_db_from_string(self, data):
        """
        Reloads the database with data from a string generated by
        the serialize_db_to_string method.
        """
        data = StringIO(data)
        for obj in serializers.deserialize("json", data, using=self.connection.alias):
            obj.save()


问题


面经


文章

微信
公众号

扫码关注公众号