diff options
author | jortel <devnull@localhost> | 2008-07-16 21:55:32 +0000 |
---|---|---|
committer | jortel <devnull@localhost> | 2008-07-16 21:55:32 +0000 |
commit | 7cbf415e147a3ba360a6ef8cd831fd3f7e92d8f1 (patch) | |
tree | f9cde18f67a0b68152814e290eda9e5e1103164c /suds/sudsobject.py | |
parent | 70addb36a1137013b8a15449a5fb292ab25b1450 (diff) | |
download | suds-7cbf415e147a3ba360a6ef8cd831fd3f7e92d8f1.tar.gz |
performance updates: add metrics module and instrument key modules; change logging to be sure that args are not being converted into strings when calling log methods; Repr class added as a wrapper so objects being passed as args that need to be converted to strings using repr() instead of str() can be done; simplified sudsobject.Printer; modified sudsobject.Printer to show simple string values enclosed in quotes instead of (); moved creation of ServiceDefinition from Client.__init__() to service_definition() to be created and cached on-demand; added simple checks to reduce overhead of sax.encode() and sax.decode(); updated SchemaObject derived to derived() and override in Element and Complex - value determined on-demand; added counts to methods and types list printouts in ServiceDefinition; update version to 0.2.3; updated sxbasic.Import to only do a urlopen on <xs:import schemaLocation=''/> and only resolve <xs:import namespace=''/> when @namespace references a schema contained in the wsdl; change schema.schemabyns() to locate()
Diffstat (limited to 'suds/sudsobject.py')
-rw-r--r-- | suds/sudsobject.py | 92 |
1 files changed, 59 insertions, 33 deletions
diff --git a/suds/sudsobject.py b/suds/sudsobject.py index 78cbad2..8a93ecd 100644 --- a/suds/sudsobject.py +++ b/suds/sudsobject.py @@ -163,21 +163,26 @@ class Printer: """ print object using the specified indent (n) and newline (nl). """ if object is None: return 'None' - if self.complex(object): - if isinstance(object, (Object, dict)): - return self.print_complex(object, n+2, nl) - if isinstance(object, (list,tuple)): - return self.print_collection(object, n+2) + if isinstance(object, Object): + if len(object) == 0: + return '<empty>' + else: + return self.print_object(object, n+2, nl) if isinstance(object, Property): return self.print_property(object) - if isinstance(object, Object): - object = asdict(object) - if isinstance(object, (dict,list,tuple)): - if len(object) > 0: - return tostr(object) + if isinstance(object, dict): + if len(object) == 0: + return '<empty>' else: + return self.print_dictionary(object, n+2, nl) + if isinstance(object, (list,tuple)): + if len(object) == 0: return '<empty>' - return '(%s)' % tostr(object) + else: + return self.print_collection(object, n+2) + if isinstance(object, basestring): + return '"%s"' % tostr(object) + return '%s' % tostr(object) def print_property(self, d): """ print a property object """ @@ -189,18 +194,40 @@ class Printer: s.append(self.process(d.value)) return ''.join(s) - def print_complex(self, d, n, nl=False): + def print_object(self, d, n, nl=False): + """ print complex using the specified indent (n) and newline (nl). """ + s = [] + if nl: + s.append('\n') + s.append(self.indent(n)) + cls = d.__class__ + if cls != Object: + s.append('(') + s.append(cls.__name__) + s.append(')') + s.append('{') + for item in items(d): + s.append('\n') + s.append(self.indent(n+1)) + if isinstance(item[1], (list,tuple)): + s.append(item[0]) + s.append('[]') + else: + s.append(item[0]) + s.append(' = ') + item = self.unwrap(d, item) + s.append(self.process(item[1], n, True)) + s.append('\n') + s.append(self.indent(n)) + s.append('}') + return ''.join(s) + + def print_dictionary(self, d, n, nl=False): """ print complex using the specified indent (n) and newline (nl). """ s = [] if nl: s.append('\n') s.append(self.indent(n)) - if isinstance(d, Object): - cls = d.__class__ - if cls != Object: - s.append('(') - s.append(cls.__name__) - s.append(')') s.append('{') for item in items(d): s.append('\n') @@ -227,18 +254,17 @@ class Printer: s.append(',') return ''.join(s) - def complex(self, object): - """ get whether the object is a complex type """ - if isinstance(object, (Object, dict)): - if len(object) > 1: - return True - for item in items(object): - if self.complex(item[1]): - return True - if isinstance(object, (list,tuple)): - if len(object) > 1: return True - for c in object: - if self.complex(c): - return True - return False - return False
\ No newline at end of file + def unwrap(self, d, item): + """ translate (unwrap) using an optional wrapper function """ + nopt = ( lambda x: x ) + try: + md = d.__metadata__ + pmd = getattr(md, '__print__', None) + if pmd is None: + return item + wrappers = getattr(pmd, 'wrappers', {}) + fn = wrappers.get(item[0], nopt) + return (item[0], fn(item[1])) + except: + pass + return item
\ No newline at end of file |