Browse Source

Merge pull request #12 from dawryn/develop

Using configuration properties of objects
main
Mathieu Le Marec - Pasquet 10 years ago
parent
commit
cce33a20a9
5 changed files with 41 additions and 20 deletions
  1. +3
    -1
      CHANGES.txt
  2. +1
    -1
      src/SOAPpy/Client.py
  3. +13
    -0
      src/SOAPpy/Config.py
  4. +20
    -14
      src/SOAPpy/SOAPBuilder.py
  5. +4
    -4
      src/SOAPpy/Server.py

+ 3
- 1
CHANGES.txt View File

@@ -4,7 +4,9 @@ CHANGELOG
0.12.22 (unreleased) 0.12.22 (unreleased)
-------------------- --------------------


- Nothing changed yet.
- proper usage of config property inside objects. [Davorin Kunstelj]
- dump user defined types with handler functions (can be used to override dump
of built-in types). [Davorin Kunstelj]




0.12.21 (2014-05-27) 0.12.21 (2014-05-27)


+ 1
- 1
src/SOAPpy/Client.py View File

@@ -477,7 +477,7 @@ class SOAPProxy:
throw_struct = 0 throw_struct = 0


if throw_struct: if throw_struct:
if Config.debug:
if self.config.debug:
print p print p
raise p raise p




+ 13
- 0
src/SOAPpy/Config.py View File

@@ -116,6 +116,13 @@ class SOAPConfig:
# authorization error. # authorization error.
self.authMethod = None self.authMethod = None


# The tuple of type and dump handler function pairs for
# SOAPBuilder dump dispatch. Used for handling additional types
# and overriding built-in types. Functions are expected to have
# the same parameters as SOAPBuilder dump_<type> methods
# (including self; possibility to call any SOAPBuilder dump method)
self.dumpmap = tuple()

# Globus Support if pyGlobus.io available # Globus Support if pyGlobus.io available
try: try:
from pyGlobus import io; from pyGlobus import io;
@@ -144,6 +151,12 @@ class SOAPConfig:
if d['SSLclient'] or d['SSLserver']: if d['SSLclient'] or d['SSLserver']:
d['SSL'] = self.SSLconfig() d['SSL'] = self.SSLconfig()


dumpmap = kw.pop("dumpmap", None)
if dumpmap:
if not isinstance(dumpmap, tuple):
raise TypeError("Config dumpmap parameter must be a tuple")
self.dumpmap = dumpmap + self.dumpmap

for k, v in kw.items(): for k, v in kw.items():
if k[0] != '_': if k[0] != '_':
setattr(self, k, v) setattr(self, k, v)


+ 20
- 14
src/SOAPpy/SOAPBuilder.py View File

@@ -100,7 +100,7 @@ class SOAPBuilder:
self.noroot = noroot self.noroot = noroot


def build(self): def build(self):
if Config.debug: print "In build."
if self.config.debug: print "In build."
ns_map = {} ns_map = {}


# Cache whether typing is on or not # Cache whether typing is on or not
@@ -197,7 +197,7 @@ class SOAPBuilder:
return ''.join(self.out) return ''.join(self.out)


def gentag(self): def gentag(self):
if Config.debug: print "In gentag."
if self.config.debug: print "In gentag."
self.tcounter += 1 self.tcounter += 1
return "v%d" % self.tcounter return "v%d" % self.tcounter


@@ -279,7 +279,7 @@ class SOAPBuilder:
# dumpers # dumpers


def dump(self, obj, tag = None, typed = 1, ns_map = {}): def dump(self, obj, tag = None, typed = 1, ns_map = {}):
if Config.debug: print "In dump.", "obj=", obj
if self.config.debug: print "In dump.", "obj=", obj
ns_map = ns_map.copy() ns_map = ns_map.copy()
self.depth += 1 self.depth += 1


@@ -293,7 +293,7 @@ class SOAPBuilder:
def dumper(self, nsURI, obj_type, obj, tag, typed = 1, ns_map = {}, def dumper(self, nsURI, obj_type, obj, tag, typed = 1, ns_map = {},
rootattr = '', id = '', rootattr = '', id = '',
xml = '<%(tag)s%(type)s%(id)s%(attrs)s%(root)s>%(data)s</%(tag)s>\n'): xml = '<%(tag)s%(type)s%(id)s%(attrs)s%(root)s>%(data)s</%(tag)s>\n'):
if Config.debug: print "In dumper."
if self.config.debug: print "In dumper."


if nsURI == None: if nsURI == None:
nsURI = self.config.typesNamespaceURI nsURI = self.config.typesNamespaceURI
@@ -324,12 +324,12 @@ class SOAPBuilder:
"id": id, "attrs": a} "id": id, "attrs": a}


def dump_float(self, obj, tag, typed = 1, ns_map = {}): def dump_float(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_float."
if self.config.debug: print "In dump_float."
tag = tag or self.gentag() tag = tag or self.gentag()


tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding


if Config.strict_range:
if self.config.strict_range:
doubleType(obj) doubleType(obj)


if PosInf == obj: if PosInf == obj:
@@ -346,7 +346,7 @@ class SOAPBuilder:
None, "double", obj, tag, typed, ns_map, self.genroot(ns_map))) None, "double", obj, tag, typed, ns_map, self.genroot(ns_map)))


def dump_int(self, obj, tag, typed = 1, ns_map = {}): def dump_int(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_int."
if self.config.debug: print "In dump_int."
# fix error "Bad types (class java.math.BigInteger -> class java.lang.Integer)" # fix error "Bad types (class java.math.BigInteger -> class java.lang.Integer)"
if isinstance(obj, LongType): if isinstance(obj, LongType):
@@ -358,12 +358,12 @@ class SOAPBuilder:
ns_map, self.genroot(ns_map))) ns_map, self.genroot(ns_map)))


def dump_bool(self, obj, tag, typed = 1, ns_map = {}): def dump_bool(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_bool."
if self.config.debug: print "In dump_bool."
self.out.append(self.dumper(None, 'boolean', obj, tag, typed, self.out.append(self.dumper(None, 'boolean', obj, tag, typed,
ns_map, self.genroot(ns_map))) ns_map, self.genroot(ns_map)))
def dump_string(self, obj, tag, typed = 0, ns_map = {}): def dump_string(self, obj, tag, typed = 0, ns_map = {}):
if Config.debug: print "In dump_string."
if self.config.debug: print "In dump_string."
tag = tag or self.gentag() tag = tag or self.gentag()
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding


@@ -381,7 +381,7 @@ class SOAPBuilder:
dump_unicode = dump_string dump_unicode = dump_string


def dump_None(self, obj, tag, typed = 0, ns_map = {}): def dump_None(self, obj, tag, typed = 0, ns_map = {}):
if Config.debug: print "In dump_None."
if self.config.debug: print "In dump_None."
tag = tag or self.gentag() tag = tag or self.gentag()
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding
ns = self.genns(ns_map, self.config.schemaNamespaceURI)[0] ns = self.genns(ns_map, self.config.schemaNamespaceURI)[0]
@@ -392,7 +392,7 @@ class SOAPBuilder:
dump_NoneType = dump_None # For Python 2.2+ dump_NoneType = dump_None # For Python 2.2+


def dump_list(self, obj, tag, typed = 1, ns_map = {}): def dump_list(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_list.", "obj=", obj
if self.config.debug: print "In dump_list.", "obj=", obj
tag = tag or self.gentag() tag = tag or self.gentag()
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding


@@ -512,7 +512,7 @@ class SOAPBuilder:
dump_tuple = dump_list dump_tuple = dump_list


def dump_map(self, obj, tag, typed = 1, ns_map = {}): def dump_map(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_map.", "obj=", obj
if self.config.debug: print "In dump_map.", "obj=", obj
tag = tag or self.gentag() tag = tag or self.gentag()
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding


@@ -566,7 +566,7 @@ class SOAPBuilder:
self.out.append("</%sFault>\n" % vns) self.out.append("</%sFault>\n" % vns)


def dump_dictionary(self, obj, tag, typed = 1, ns_map = {}): def dump_dictionary(self, obj, tag, typed = 1, ns_map = {}):
if Config.debug: print "In dump_dictionary."
if self.config.debug: print "In dump_dictionary."
tag = tag or self.gentag() tag = tag or self.gentag()
tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding tag = toXMLname(tag) # convert from SOAP 1.2 XML name encoding


@@ -596,7 +596,13 @@ class SOAPBuilder:
else: else:
tag = self.gentag() tag = self.gentag()


# watch out for order!
# Apply additional types, override built-in types
for dtype, func in self.config.dumpmap:
if isinstance(obj, dtype):
func(self, obj, tag, typed, ns_map)
return

# watch out for order!
dumpmap = ( dumpmap = (
(Exception, self.dump_exception), (Exception, self.dump_exception),
(mapType, self.dump_map), (mapType, self.dump_map),


+ 4
- 4
src/SOAPpy/Server.py View File

@@ -233,7 +233,7 @@ class SOAPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
args = r._aslist() args = r._aslist()
kw = r._asdict() kw = r._asdict()


if Config.simplify_objects:
if self.server.config.simplify_objects:
args = simplify(args) args = simplify(args)
kw = simplify(kw) kw = simplify(kw)


@@ -253,7 +253,7 @@ class SOAPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
ordered_args = {} ordered_args = {}
named_args = {} named_args = {}


if Config.specialArgs:
if self.server.config.specialArgs:


for (k,v) in kw.items(): for (k,v) in kw.items():


@@ -383,7 +383,7 @@ class SOAPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
if f.context: # retrieve context object if f.context: # retrieve context object
c = _contexts[thread_id] c = _contexts[thread_id]


if Config.specialArgs:
if self.server.config.specialArgs:
if c: if c:
named_args["_SOAPContext"] = c named_args["_SOAPContext"] = c
fr = apply(f, ordered_args, named_args) fr = apply(f, ordered_args, named_args)
@@ -404,7 +404,7 @@ class SOAPRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler):
fr = apply(f, args, {}) fr = apply(f, args, {})


else: else:
if Config.specialArgs:
if self.server.config.specialArgs:
fr = apply(f, ordered_args, named_args) fr = apply(f, ordered_args, named_args)
else: else:
fr = apply(f, args, {}) fr = apply(f, args, {})


Loading…
Cancel
Save