Commits

George Sakkis  committed 86ee4fe

for some types adding base type information and using it for the EWS types Path and SearchExpression.
Ported from https://bitbucket.org/daevaorn/suds-ews/changeset/758db4a0ed0aff6cf36a3f3bc616845d2be61a30

  • Participants
  • Parent commits c7875a5

Comments (0)

Files changed (4)

File suds/builder.py

         """
         self.resolver = resolver
 
-    def build(self, name):
+    def build(self, name_or_resolved_type, base_type):
         """ build a an object for the specified typename as defined in the schema """
-        if isinstance(name, basestring):
-            type = self.resolver.find(name)
+        if isinstance(name_or_resolved_type, basestring):
+            base_type, type = self.resolver.find(name_or_resolved_type)
             if type is None:
                 raise TypeNotFound(name)
         else:
-            type = name
+            type = name_or_resolved_type
         cls = type.name
         if type.mixed():
             data = Factory.property(cls)
         else:
             data = Factory.object(cls)
-        resolved = type.resolve()
         md = data.__metadata__
-        md.sxtype = resolved
-        md.ordering = self.ordering(resolved)
+        md.sxtype = type
+        md.sxbase = base_type
+        md.ordering = self.ordering(type)
         history = []
-        self.add_attributes(data, resolved)
+        self.add_attributes(data, type)
         for child, ancestry in type.children():
             if self.skip_child(child, ancestry):
                 continue

File suds/client.py

         s = ['\n']
         s.append('Suds ( https://fedorahosted.org/suds/ )')
         s.append('  version: %s' % suds.__version__)
-        if ( suds.__build__ ):
+        if (suds.__build__):
             s.append('  build: %s' % suds.__build__)
         for sd in self.sd:
             s.append('\n\n%s' % unicode(sd))
         """
         timer = metrics.Timer()
         timer.start()
-        type = self.resolver.find(name)
-        if type is None:
+        base_type, resolved_type = self.resolver.find(name)
+        if resolved_type is None:
             raise TypeNotFound(name)
-        if type.enum():
+        if resolved_type.enum():
             result = InstFactory.object(name)
-            for e, a in type.children():
+            for e, a in base_type.children():
                 setattr(result, e.name, e.name)
         else:
             try:
-                result = self.builder.build(type)
+                result = self.builder.build(resolved_type, base_type)
             except Exception, e:
                 log.error("create '%s' failed", name, exc_info=True)
                 raise BuildError(name, e)
             else:
                 result = self.succeeded(binding, reply.message)
         except TransportError, e:
-            if e.httpcode in (202,204):
+            if e.httpcode in (202, 204):
                 result = None
             else:
                 log.error(self.last_sent())

File suds/mx/appender.py

 
     def __eq__(self, x):
         if self.cls is None:
-            return ( x is None )
+            return (x is None)
         else:
             return isinstance(x, self.cls)
 
         @param marshaller: A marshaller.
         @type marshaller: L{suds.mx.core.Core}
         """
-        self.marshaller  = marshaller
+        self.marshaller = marshaller
 
     def node(self, content):
         """
 
 class ObjectAppender(Appender):
     """
-    An L{Object} appender.
+    An L{Object} appender. Includes fix for EWS types Path and SearchExpression
     """
 
     def append(self, parent, content):
         child = self.node(content)
         parent.append(child)
         for item in object:
-            cont = Content(tag=item[0], value=item[1])
+            if Matcher(Object) == item[1]:
+                if item[0] in ("Path", "SearchExpression"):
+                    cont = Content(tag=item[1].__metadata__.sxbase.qname[0],
+                                   value=item[1], type=item[1].__metadata__.sxtype)
+                else:
+                    cont = Content(tag=item[0], value=item[1])
+            else:
+                cont = Content(tag=item[0], value=item[1])
             Appender.append(self, child, cont)
 
 

File suds/resolver.py

             return None
         log.debug('found (%s) as (%s)', name, Repr(result))
         if resolved:
-            result = result.resolve()
-        return result
+            return (result, result.resolve())
+        else:
+            return (result, result)
 
 
 class PathResolver(Resolver):
                 result = self.branch(result, parts)
                 result = self.leaf(result, parts)
             if resolved:
-                result = result.resolve(nobuiltin=True)
+                return (result, result.resolve(nobuiltin=True))
+            else:
+                return (result, result)
         except PathResolver.BadPath:
             log.error('path: "%s", not-found' % path)
-        return result
 
     def root(self, parts):
         """
             m = self.splitp.match(s, b)
             if m is None:
                 break
-            b,e = m.span()
+            b, e = m.span()
             parts.append(s[b:e])
-            b = e+1
+            b = e + 1
         return parts
 
     class BadPath(Exception): pass
         @return: The found schema I{type}
         @rtype: L{xsd.sxbase.SchemaObject}
         """
-        name = '@%s'%name
+        name = '@%s' % name
         parent = self.top().resolved
         if parent is None:
             result, ancestry = self.query(name, node)