* fix: type selector so that we recognize custom xml classes
including LocalText * fix constructor to class types so that tag and spec are passed using init
This commit is contained in:
+11
-5
@@ -71,9 +71,9 @@ class LocalText(object):
|
|||||||
|
|
||||||
def decode(self, node):
|
def decode(self, node):
|
||||||
# flags, tag name, instance attribute
|
# flags, tag name, instance attribute
|
||||||
nodes = getAllNodes(node, tag)
|
nodes = getAllNodes(node, self.tag)
|
||||||
if not nodes:
|
if not nodes:
|
||||||
if req == mandatory:
|
if self.req == mandatory:
|
||||||
pass
|
pass
|
||||||
#errs.append("Tag '%s' should have at least one '%s' tag\n" % (parent.tagName, d[2]))
|
#errs.append("Tag '%s' should have at least one '%s' tag\n" % (parent.tagName, d[2]))
|
||||||
else:
|
else:
|
||||||
@@ -264,7 +264,8 @@ class autoxml(type):
|
|||||||
def gen_tag(cls, tag, spec):
|
def gen_tag(cls, tag, spec):
|
||||||
"""generate readers and writers for the tag"""
|
"""generate readers and writers for the tag"""
|
||||||
tag_type = spec[0]
|
tag_type = spec[0]
|
||||||
if type(tag_type) is types.TypeType:
|
if type(tag_type) is types.TypeType and \
|
||||||
|
autoxml.basic_cons_map.has_key(tag_type):
|
||||||
def readtext(node, tagpath):
|
def readtext(node, tagpath):
|
||||||
#print 'read tag', node, tagpath
|
#print 'read tag', node, tagpath
|
||||||
return getNodeText(node, tagpath)
|
return getNodeText(node, tagpath)
|
||||||
@@ -274,8 +275,11 @@ class autoxml(type):
|
|||||||
return cls.gen_anon_basic(tag, spec, readtext, writetext)
|
return cls.gen_anon_basic(tag, spec, readtext, writetext)
|
||||||
elif type(tag_type) is types.ListType:
|
elif type(tag_type) is types.ListType:
|
||||||
return cls.gen_list_tag(tag, spec)
|
return cls.gen_list_tag(tag, spec)
|
||||||
elif type(tag_type) is autoxml or type(tag_type) is types.ClassType:
|
elif type(tag_type) is autoxml or type(tag_type) is types.TypeType:
|
||||||
return cls.gen_class_tag(tag, spec)
|
return cls.gen_class_tag(tag, spec)
|
||||||
|
else:
|
||||||
|
raise Error('gen_tag: unrecognized tag type %s in spec' %
|
||||||
|
str(tag_type))
|
||||||
|
|
||||||
def gen_named_comp(cls, token, spec, anonfuns):
|
def gen_named_comp(cls, token, spec, anonfuns):
|
||||||
"""generate a named component tag/attr. a decoration of
|
"""generate a named component tag/attr. a decoration of
|
||||||
@@ -396,7 +400,9 @@ class autoxml(type):
|
|||||||
name, tag_type, req, path = cls.parse_spec(tag, spec)
|
name, tag_type, req, path = cls.parse_spec(tag, spec)
|
||||||
|
|
||||||
def make_object():
|
def make_object():
|
||||||
return tag_type.__new__(tag_type, tag, spec)
|
obj = tag_type.__new__(tag_type)
|
||||||
|
obj.__init__(tag, spec)
|
||||||
|
return obj
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
return make_object()
|
return make_object()
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ class XmlFileTestCase(unittest.TestCase):
|
|||||||
class A:
|
class A:
|
||||||
__metaclass__ = xmlfile.autoxml
|
__metaclass__ = xmlfile.autoxml
|
||||||
t_Name = [types.StringType, xmlfile.mandatory]
|
t_Name = [types.StringType, xmlfile.mandatory]
|
||||||
|
t_Description = [xmlfile.LocalText, xmlfile.mandatory]
|
||||||
t_Number = [types.IntType, xmlfile.optional]
|
t_Number = [types.IntType, xmlfile.optional]
|
||||||
t_Email = [types.StringType, xmlfile.optional]
|
t_Email = [types.StringType, xmlfile.optional]
|
||||||
a_href = [types.StringType, xmlfile.mandatory]
|
a_href = [types.StringType, xmlfile.mandatory]
|
||||||
|
|||||||
Reference in New Issue
Block a user