Ravi Nori has uploaded a new change for review. Change subject: sdk: Revert Replace decorators before marshal ......................................................................
sdk: Revert Replace decorators before marshal Revert patch Replace decorators before marshal http://gerrit.ovirt.org/#/c/24131 Change-Id: I5da35cbf75b6e29f5c5b4a79bd07d757691d5de1 Bug-Url: https://bugzilla.redhat.com/1122546 Signed-off-by: Ravi Nori <[email protected]> --- M src/codegen/xsd/paramsconf.py M src/ovirtsdk/utils/parsehelper.py 2 files changed, 51 insertions(+), 41 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine-sdk refs/changes/58/31358/1 diff --git a/src/codegen/xsd/paramsconf.py b/src/codegen/xsd/paramsconf.py index 8e12f16..ee1bd9c 100644 --- a/src/codegen/xsd/paramsconf.py +++ b/src/codegen/xsd/paramsconf.py @@ -31,6 +31,54 @@ # attributes of certain class, will be append to this calls in params.py _generatedsSuperAttribute = """ # Begin NOT_GENERATED +def __setattr__(self, item, value): + if (value is not None and + not isinstance(value, list) and + ReflectionHelper.isModuleMember( + sys.modules['ovirtsdk.infrastructure.brokers'], + type(value)) and + not ReflectionHelper.isModuleMember(sys.modules[__name__], + type(value)) and + value.__dict__.has_key('superclass') and + value.superclass is not None and + value.superclass != BaseResource): + if (ReflectionHelper.isModuleMember( + sys.modules['ovirtsdk.infrastructure.brokers'], + type(self)) and + self.__dict__.has_key('superclass') and + self.superclass is not None): + object.__setattr__(self.superclass, item, value.superclass) + else: + object.__setattr__(self, item, value.superclass) + elif (not isinstance(value, list) and + ReflectionHelper.isModuleMember( + sys.modules['ovirtsdk.infrastructure.brokers'], + type(self)) and + self.__dict__.has_key('superclass') and + self.superclass is not None and + not ReflectionHelper.isModuleMember( + sys.modules['ovirtsdk.infrastructure.brokers'], + type(value)) and + item is not 'superclass' and + item is not 'parentclass'): + object.__setattr__(self.superclass, item, value) + elif isinstance(value, list): + parsed_list = [] + for obj in value: + if (ReflectionHelper.isModuleMember( + sys.modules['ovirtsdk.infrastructure.brokers'], + type(obj)) and + obj.__dict__.has_key('superclass') and + obj.superclass is not None and + item is not 'superclass' and + item is not 'parentclass'): + parsed_list.append(obj.superclass) + else: + parsed_list.append(obj) + object.__setattr__(self, item, parsed_list) + else: + object.__setattr__(self, item, value) + def __eq__(self, other): return Comparator.compare(self, other) diff --git a/src/ovirtsdk/utils/parsehelper.py b/src/ovirtsdk/utils/parsehelper.py index 6f70486..1559937 100644 --- a/src/ovirtsdk/utils/parsehelper.py +++ b/src/ovirtsdk/utils/parsehelper.py @@ -24,50 +24,12 @@ '''Provides parsing capabilities''' @staticmethod - def replaceDecorators(obj): - """ - Returns the object that replaces the given one. If the object is a - resource decorator then it will be replaced by the corresponding - parameters object. Collection decorators will be replaced by None, as - then can't be serialized. - """ - - # Parameter objects don't need to be replaced themselves, but its - # attributes do: - if isinstance(obj, params.GeneratedsSuper): - for attr_name, attr_value in obj.__dict__.iteritems(): - obj.__dict__[attr_name] = ParseHelper.replaceDecorators(attr_value) - return obj - - # Resource decorators are replaced by the reference to the parameters - # object that they store in the "superclass" attribute, collections don't - # have this attribute, so they are replaced by None: - if isinstance(obj, common.Base): - try: - replacement = obj.superclass - except AttributeError: - replacement = None - return replacement - - # Lists have to be iterated and the elements replaced: - if isinstance(obj, list): - replacement = [] - for element in obj: - replacement.append(ParseHelper.replaceDecorators(element)) - return replacement - - # Other types of object don't need any replacement: - return obj - - @staticmethod def toXml(entity): '''Parse entity to corresponding XML representation''' - # The entity given may be a decorator, or it may contain a decorator - # deeply nested. Those decorators can't be serialized to XML, so we - # need to replace all references to decorators with the corresponding - # parameter objects: - entity = ParseHelper.replaceDecorators(entity) + if ReflectionHelper.isModuleMember(sys.modules['ovirtsdk.infrastructure.brokers'], + type(entity)) and hasattr(entity, 'superclass'): + entity = entity.superclass type_name = type(entity).__name__.lower() output = StringIO.StringIO() -- To view, visit http://gerrit.ovirt.org/31358 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I5da35cbf75b6e29f5c5b4a79bd07d757691d5de1 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine-sdk Gerrit-Branch: sdk_3.5 Gerrit-Owner: Ravi Nori <[email protected]> _______________________________________________ Engine-patches mailing list [email protected] http://lists.ovirt.org/mailman/listinfo/engine-patches
