Skip to content

Commit

Permalink
adding more information to the get_simple_type_info
Browse files Browse the repository at this point in the history
  • Loading branch information
plq committed Dec 16, 2011
1 parent bf06f90 commit d15bfa6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
31 changes: 22 additions & 9 deletions src/rpclib/model/complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@
from rpclib.util.odict import odict as TypeInfo
from rpclib.const import xml_ns as namespace


class _SimpleTypeInfoElement(object):
def __init__(self, path, parent, type_):
self.path = path
self.parent = parent
self.type = type_


class XmlAttribute(ModelBase):
"""Items which are marshalled as attributes of the parent element."""

Expand Down Expand Up @@ -232,7 +240,7 @@ def get_flat_type_info(cls, retval=None):
return retval

@staticmethod
def get_simple_type_info(cls, retval=None, prefix=None):
def get_simple_type_info(cls, retval=None, prefix=None, parent=None):
"""Returns a _type_info dict that includes members from all base classes
and whose types are only primitives.
"""
Expand All @@ -241,23 +249,28 @@ def get_simple_type_info(cls, retval=None, prefix=None):

if retval is None:
retval = {}

if prefix:
prefix += "_"
else:
prefix = ""
if prefix is None:
prefix = []

fti = cls.get_flat_type_info(cls)
for k, v in fti.items():
if getattr(v, 'get_flat_type_info', None) is None:
key = prefix + k
new_prefix = list(prefix)
new_prefix.append(k)
key = '_'.join(new_prefix)
value = retval.get(key, None)

if value:
raise ValueError("%r.%s conflicts with %r" % (cls, k, value))

else:
retval[key] = v
retval[key] = _SimpleTypeInfoElement(
path=new_prefix, parent=parent, type_=v)

else:
v.get_simple_type_info(v, retval, k)
new_prefix = list(prefix)
new_prefix.append(k)
v.get_simple_type_info(v, retval, new_prefix, parent=cls)

return retval

Expand Down
17 changes: 12 additions & 5 deletions src/rpclib/test/model/test_complex.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,6 @@ class Parameter(ComplexModel):


class TestXmlAttribute(unittest.TestCase):

def test_add_to_schema(self):
app = FakeApp()
schema = Wsdl11(app)
Expand All @@ -353,14 +352,22 @@ class CCM(ComplexModel):

sti = CCM.get_simple_type_info(CCM)
assert "i" in sti
assert sti["i"] is Integer
assert sti["i"].path == ['i']
assert sti["i"].type is Integer
assert sti["s"].parent is None
assert "s" in sti
assert sti["s"] is String
assert sti["s"].path == ['s']
assert sti["s"].type is String
assert sti["s"].parent is None

assert "c_i" in sti
assert sti["c_i"] is Integer
assert sti["c_i"].path == ['c','i']
assert sti["c_i"].type is Integer
assert sti["c_i"].parent is CCM
assert "c_s" in sti
assert sti["c_s"] is String
assert sti["c_s"].path == ['c','s']
assert sti["c_s"].type is String
assert sti["c_s"].parent is CCM

def test_simple_type_info_conflicts(self):
class CM(ComplexModel):
Expand Down

0 comments on commit d15bfa6

Please sign in to comment.