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


Python fields.ObjectField方法代码示例

本文整理汇总了Python中oslo_versionedobjects.fields.ObjectField方法的典型用法代码示例。如果您正苦于以下问题:Python fields.ObjectField方法的具体用法?Python fields.ObjectField怎么用?Python fields.ObjectField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_versionedobjects.fields的用法示例。


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

示例1: test_from_primitive

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_from_primitive(self):
        @obj_base.VersionedObjectRegistry.register
        class TestFakeObject(obj_base.VersionedObject):
            OBJ_PROJECT_NAMESPACE = 'fake-project'

        @obj_base.VersionedObjectRegistry.register
        class TestBar(TestFakeObject, obj_base.ComparableVersionedObject):
            fields = {
                'name': fields.StringField(),
            }

        @obj_base.VersionedObjectRegistry.register
        class TestFoo(TestFakeObject, obj_base.ComparableVersionedObject):
            fields = {
                'name': fields.StringField(),
                'bar': fields.ObjectField('TestBar', nullable=True)
            }

        bar = TestBar(name='bar')
        foo = TestFoo(name='foo', bar=bar)
        from_primitive_values = [(foo.obj_to_primitive(), foo), (foo, foo)]

        for prim_val, out_val in from_primitive_values:
            self.assertEqual(out_val, self.field.from_primitive(
                foo, 'attr', prim_val)) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:27,代码来源:test_fields.py

示例2: test_changed_with_sub_object

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_changed_with_sub_object(self):
        @base.VersionedObjectRegistry.register
        class ParentObject(base.VersionedObject):
            fields = {'foo': fields.IntegerField(),
                      'bar': fields.ObjectField('MyObj'),
                      }
        obj = ParentObject()
        self.assertEqual(set(), obj.obj_what_changed())
        obj.foo = 1
        self.assertEqual(set(['foo']), obj.obj_what_changed())
        bar = MyObj()
        obj.bar = bar
        self.assertEqual(set(['foo', 'bar']), obj.obj_what_changed())
        obj.obj_reset_changes()
        self.assertEqual(set(), obj.obj_what_changed())
        bar.foo = 1
        self.assertEqual(set(['bar']), obj.obj_what_changed()) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:19,代码来源:test_objects.py

示例3: test_parent_child

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_parent_child(self):
        @base.VersionedObjectRegistry.register
        class TestChild(base.VersionedObject):
            VERSION = '2.34'

        @base.VersionedObjectRegistry.register
        class TestObject(base.VersionedObject):
            VERSION = '1.23'
            fields = {
                'child': fields.ObjectField('TestChild'),
            }

        tree = base.obj_tree_get_versions('TestObject')
        self.assertEqual({'TestObject': '1.23',
                          'TestChild': '2.34'},
                         tree) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:18,代码来源:test_objects.py

示例4: test_complex

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_complex(self):
        @base.VersionedObjectRegistry.register
        class TestChild(base.VersionedObject):
            VERSION = '2.34'

        @base.VersionedObjectRegistry.register
        class TestChildTwo(base.VersionedObject):
            VERSION = '4.56'
            fields = {
                'sibling': fields.ObjectField('TestChild'),
            }

        @base.VersionedObjectRegistry.register
        class TestObject(base.VersionedObject):
            VERSION = '1.23'
            fields = {
                'child': fields.ObjectField('TestChild'),
                'childtwo': fields.ListOfObjectsField('TestChildTwo'),
            }

        tree = base.obj_tree_get_versions('TestObject')
        self.assertEqual({'TestObject': '1.23',
                          'TestChild': '2.34',
                          'TestChildTwo': '4.56'},
                         tree) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:27,代码来源:test_objects.py

示例5: obj_make_compatible

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def obj_make_compatible(self, primitive, target_version):
        """Make an object representation compatible with a target version.

        This is responsible for taking the primitive representation of
        an object and making it suitable for the given target_version.
        This may mean converting the format of object attributes, removing
        attributes that have been added since the target version, etc. In
        general:

        - If a new version of an object adds a field, this routine
          should remove it for older versions.
        - If a new version changed or restricted the format of a field, this
          should convert it back to something a client knowing only of the
          older version will tolerate.
        - If an object that this object depends on is bumped, then this
          object should also take a version bump. Then, this routine should
          backlevel the dependent object (by calling its obj_make_compatible())
          if the requested version of this object is older than the version
          where the new dependent object was added.

        :param primitive: The result of :meth:`obj_to_primitive`
        :param target_version: The version string requested by the recipient
                               of the object
        :raises: :exc:`oslo_versionedobjects.exception.UnsupportedObjectError`
                 if conversion is not possible for some reason
        """
        for key, field in self.fields.items():
            if not isinstance(field, (obj_fields.ObjectField,
                                      obj_fields.ListOfObjectsField)):
                continue
            if not self.obj_attr_is_set(key):
                continue
            self._obj_make_obj_compatible(primitive, target_version, key) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:35,代码来源:base.py

示例6: obj_tree_get_versions

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def obj_tree_get_versions(objname, tree=None):
    """Construct a mapping of dependent object versions.

    This method builds a list of dependent object versions given a top-
    level object with other objects as fields. It walks the tree recursively
    to determine all the objects (by symbolic name) that could be contained
    within the top-level object, and the maximum versions of each. The result
    is a dict like::

      {'MyObject': '1.23', ... }

    :param objname: The top-level object at which to start
    :param tree: Used internally, pass None here.
    :returns: A dictionary of object names and versions
    """
    if tree is None:
        tree = {}
    if objname in tree:
        return tree
    objclass = VersionedObjectRegistry.obj_classes()[objname][0]
    tree[objname] = objclass.VERSION
    for field_name in objclass.fields:
        field = objclass.fields[field_name]
        if isinstance(field, obj_fields.ObjectField):
            child_cls = field._type._obj_name
        elif isinstance(field, obj_fields.ListOfObjectsField):
            child_cls = field._type._element_type._type._obj_name
        else:
            continue

        try:
            obj_tree_get_versions(child_cls, tree=tree)
        except IndexError:
            raise exception.UnregisteredSubobject(
                child_objname=child_cls, parent_objname=objname)
    return tree 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:38,代码来源:base.py

示例7: test_get_dependencies

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_get_dependencies(self):
        # Make sure _get_dependencies() generates a correct tree when parsing
        # an object
        self._add_class(self.obj_classes, MyExtraObject)
        MyObject.fields['subob'] = fields.ObjectField('MyExtraObject')
        MyExtraObject.VERSION = '1.0'
        tree = {}

        self.ovc._get_dependencies(tree, MyObject)

        expected_tree = {'MyObject': {'MyExtraObject': '1.0'}}

        self.assertEqual(expected_tree, tree, "_get_dependencies() did "
                         "not generate a correct dependency tree.") 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:16,代码来源:test_fixture.py

示例8: _test_test_relationships_in_order_bad

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def _test_test_relationships_in_order_bad(self, fake_rels):
        fake = mock.MagicMock()
        fake.VERSION = '1.5'
        fake.fields = {'foo': fields.ObjectField('bar')}
        fake.obj_relationships = fake_rels
        checker = fixture.ObjectVersionChecker()
        self.assertRaises(AssertionError,
                          checker._test_relationships_in_order, fake) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:10,代码来源:test_objects.py

示例9: _test_nested_backport

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def _test_nested_backport(self, old):
        @base.VersionedObjectRegistry.register
        class Parent(base.VersionedObject):
            VERSION = '1.0'

            fields = {
                'child': fields.ObjectField('MyObj'),
            }

        @base.VersionedObjectRegistry.register  # noqa
        class Parent(base.VersionedObject):
            VERSION = '1.1'

            fields = {
                'child': fields.ObjectField('MyObj'),
            }

        child = MyObj(foo=1)
        parent = Parent(child=child)
        prim = parent.obj_to_primitive()
        child_prim = prim['versioned_object.data']['child']
        child_prim['versioned_object.version'] = '1.10'
        ser = base.VersionedObjectSerializer()
        with mock.patch.object(base.VersionedObject, 'indirection_api') as a:
            if old:
                a.object_backport_versions.side_effect = NotImplementedError
            ser.deserialize_entity(self.context, prim)
            a.object_backport_versions.assert_called_once_with(
                self.context, prim, {'Parent': '1.1',
                                     'MyObj': '1.6',
                                     'MyOwnedObject': '1.0'})
            if old:
                # NOTE(danms): This should be the version of the parent object,
                # not the child. If wrong, this will be '1.6', which is the max
                # child version in our registry.
                a.object_backport.assert_called_once_with(
                    self.context, prim, '1.1') 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:39,代码来源:test_objects.py

示例10: test_missing_referenced

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def test_missing_referenced(self):
        """Ensure a missing child object is highlighted."""
        @base.VersionedObjectRegistry.register
        class TestObjectFoo(base.VersionedObject):
            VERSION = '1.23'
            fields = {
                # note that this object does not exist
                'child': fields.ObjectField('TestChildBar'),
            }

        exc = self.assertRaises(exception.UnregisteredSubobject,
                                base.obj_tree_get_versions,
                                'TestObjectFoo')
        self.assertIn('TestChildBar is referenced by TestObjectFoo',
                      exc.format_message()) 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:17,代码来源:test_objects.py

示例11: obj_reset_changes

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def obj_reset_changes(self, fields=None, recursive=False):
        """Reset the list of fields that have been changed.

        :param fields: List of fields to reset, or "all" if None.
        :param recursive: Call obj_reset_changes(recursive=True) on
                          any sub-objects within the list of fields
                          being reset.

        This is NOT "revert to previous values".

        Specifying fields on recursive resets will only be honored at the top
        level. Everything below the top will reset all.
        """
        if recursive:
            for field in self.obj_get_changes():

                # Ignore fields not in requested set (if applicable)
                if fields and field not in fields:
                    continue

                # Skip any fields that are unset
                if not self.obj_attr_is_set(field):
                    continue

                value = getattr(self, field)

                # Don't reset nulled fields
                if value is None:
                    continue

                # Reset straight Object and ListOfObjects fields
                if isinstance(self.fields[field], ovoo_fields.ObjectField):
                    value.obj_reset_changes(recursive=True)
                elif isinstance(self.fields[field],
                                ovoo_fields.ListOfObjectsField):
                    for thing in value:
                        thing.obj_reset_changes(recursive=True)

        if fields:
            self._changed_fields -= set(fields)
            for field in fields:
                self._obj_original_values.pop(field, None)
        else:
            self._changed_fields.clear()
            self._obj_original_values = dict() 
开发者ID:openstack,项目名称:designate,代码行数:47,代码来源:base.py

示例12: obj_reset_changes

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def obj_reset_changes(self, fields=None, recursive=False):
        """Reset the list of fields that have been changed.

        :param fields: List of fields to reset, or "all" if None.
        :param recursive: Call obj_reset_changes(recursive=True) on
                          any sub-objects within the list of fields
                          being reset.

        This is NOT "revert to previous values".

        Specifying fields on recursive resets will only be honored at the top
        level. Everything below the top will reset all.
        """
        if recursive:
            for field in self.obj_get_changes():

                # Ignore fields not in requested set (if applicable)
                if fields and field not in fields:
                    continue

                # Skip any fields that are unset
                if not self.obj_attr_is_set(field):
                    continue

                value = getattr(self, field)

                # Don't reset nulled fields
                if value is None:
                    continue

                # Reset straight Object and ListOfObjects fields
                if isinstance(self.fields[field], obj_fields.ObjectField):
                    value.obj_reset_changes(recursive=True)
                elif isinstance(self.fields[field],
                                obj_fields.ListOfObjectsField):
                    for thing in value:
                        thing.obj_reset_changes(recursive=True)

        if fields:
            self._changed_fields -= set(fields)
        else:
            self._changed_fields.clear() 
开发者ID:openstack,项目名称:oslo.versionedobjects,代码行数:44,代码来源:base.py

示例13: obj_reset_changes

# 需要导入模块: from oslo_versionedobjects import fields [as 别名]
# 或者: from oslo_versionedobjects.fields import ObjectField [as 别名]
def obj_reset_changes(self, fields=None, recursive=False):
        """Reset the list of fields that have been changed.

        .. note::

          - This is NOT "revert to previous values"
          - Specifying fields on recursive resets will only be honored at the
            top level. Everything below the top will reset all.

        :param fields: List of fields to reset, or "all" if None.
        :param recursive: Call obj_reset_changes(recursive=True) on
                          any sub-objects within the list of fields
                          being reset.
        """
        if recursive:
            for field in self.obj_get_changes():

                # Ignore fields not in requested set (if applicable)
                if fields and field not in fields:
                    continue

                # Skip any fields that are unset
                if not self.obj_attr_is_set(field):
                    continue

                value = getattr(self, field)

                # Don't reset nulled fields
                if value is None:
                    continue

                # Reset straight Object and ListOfObjects fields
                if isinstance(self.fields[field], obj_fields.ObjectField):
                    value.obj_reset_changes(recursive=True)
                elif isinstance(self.fields[field],
                                obj_fields.ListOfObjectsField):
                    for thing in value:
                        thing.obj_reset_changes(recursive=True)

        if fields:
            self._changed_fields -= set(fields)
        else:
            self._changed_fields.clear() 
开发者ID:openstack,项目名称:masakari,代码行数:45,代码来源:base.py


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