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)
--------------------

- 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)


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

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

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



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

@@ -116,6 +116,13 @@ class SOAPConfig:
# authorization error.
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
try:
from pyGlobus import io;
@@ -144,6 +151,12 @@ class SOAPConfig:
if d['SSLclient'] or d['SSLserver']:
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():
if k[0] != '_':
setattr(self, k, v)


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

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

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

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

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

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

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()
self.depth += 1

@@ -293,7 +293,7 @@ class SOAPBuilder:
def dumper(self, nsURI, obj_type, obj, tag, typed = 1, ns_map = {},
rootattr = '', id = '',
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:
nsURI = self.config.typesNamespaceURI
@@ -324,12 +324,12 @@ class SOAPBuilder:
"id": id, "attrs": a}

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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

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

if PosInf == obj:
@@ -346,7 +346,7 @@ class SOAPBuilder:
None, "double", obj, tag, typed, ns_map, self.genroot(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)"
if isinstance(obj, LongType):
@@ -358,12 +358,12 @@ class SOAPBuilder:
ns_map, self.genroot(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,
ns_map, self.genroot(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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

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

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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding
ns = self.genns(ns_map, self.config.schemaNamespaceURI)[0]
@@ -392,7 +392,7 @@ class SOAPBuilder:
dump_NoneType = dump_None # For Python 2.2+

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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

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

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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

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

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 = toXMLname(tag) # convert from SOAP 1.2 XML name encoding

@@ -596,7 +596,13 @@ class SOAPBuilder:
else:
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 = (
(Exception, self.dump_exception),
(mapType, self.dump_map),


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

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

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

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

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

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

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

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

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


Loading…
Cancel
Save