diff --git a/pisi/specfilenew.py b/pisi/specfilenew.py index 4a61ca0f..0a96f045 100644 --- a/pisi/specfilenew.py +++ b/pisi/specfilenew.py @@ -31,7 +31,6 @@ from pisi.util import Checks __metaclass__ = xmlfile.autoxml - class Packager: t_Name = [xmlfile.String, xmlfile.mandatory] t_Email = [xmlfile.String, xmlfile.mandatory] @@ -164,14 +163,19 @@ class Package: class SpecFile(XmlFile): + __metaclass__ = xmlfile.autoxml #needed when we specify a superclass + t_Source = [ [Source], xmlfile.mandatory, "Source"] t_Packages = [ [Package], xmlfile.mandatory, "Package"] t_History = [ [Update], xmlfile.mandatory, "Update"] + #def init(self, tag = "PISI"): + #ignore tag + #XmlFile.__init__(self, tag) + def read(self, filename): """Read PSPEC file""" - XmlFile.__init__(self,"PISI") self.readxml(filename) errs = [] diff --git a/pisi/xmlfile.py b/pisi/xmlfile.py index 5205747f..cbb2327c 100644 --- a/pisi/xmlfile.py +++ b/pisi/xmlfile.py @@ -47,6 +47,7 @@ import pisi from pisi.xmlext import * import pisi.context as ctx import pisi.util as util +import pisi.oo as oo class Error(pisi.Error): pass @@ -122,7 +123,7 @@ class LocalText(object): else: errs.append(_("Tag should have at least an English or Turkish version")) -class autoxml(type): +class autoxml(oo.autosuper): """High-level automatic XML transformation interface for xmlfile. The idea is to declare a class for each XML tag. Inside the class the tags and attributes nested in the tag are further @@ -197,7 +198,7 @@ class autoxml(type): """entry point for metaclass code""" #print 'generating class', name - # add XmlFile as one of the superclasses, we're smart + # add XmlFile as one of the superclasses of cls bases = list(bases) if not XmlFile in bases: bases.append(XmlFile) @@ -237,10 +238,17 @@ class autoxml(type): # generate top-level helper functions cls.initializers = inits def initialize(self, tag = None, spec = None): - XmlFile.__init__(self, cls.tag) + #FIXME: what the hell is spec? :( + if not tag: + tag = cls.tag + #self.__super.__init__(tag = tag) #FIXME: doesn't work, why? :( + super(cls, self).__init__(tag = tag) for init in self.__class__.initializers: init(self) - + # init hook + if hasattr(self, 'init'): + self.init(tag) + cls.__init__ = initialize cls.decoders = decoders @@ -614,8 +622,8 @@ class autoxml(type): class XmlFile(object): """A class to help reading and writing an XML file""" - def __init__(self, rootTag): - self.rootTag = rootTag + def __init__(self, tag): + self.rootTag = tag self.newDOM() def newDOM(self): diff --git a/tests/run.py b/tests/run.py index 8ebffd88..856370ee 100755 --- a/tests/run.py +++ b/tests/run.py @@ -29,12 +29,9 @@ def run_all(): testsources = filter(lambda x:x.endswith('tests.py'), files) for testsource in testsources: module = __import__(testsource[:len(testsource)-3]) - #testsuite.add(module.suite) print '\n* Running tests in', testsource run_test_suite(module.suite) - #run_test_suite(unittest.TestSuite(tests)) - if __name__ == "__main__": locale.setlocale(locale.LC_ALL, '') diff --git a/tests/xmlfiletests.py b/tests/xmlfiletests.py index 43bf3a15..b7220825 100644 --- a/tests/xmlfiletests.py +++ b/tests/xmlfiletests.py @@ -28,13 +28,13 @@ class XmlFileTestCase(unittest.TestCase): def testMetaClass(self): - class OtherInfo: + class OtherInfo(object): __metaclass__ = xmlfile.autoxml t_BirthDate = [types.StringType, xmlfile.mandatory] t_Interest = [types.StringType, xmlfile.optional] t_CodesWith = [ [types.StringType], xmlfile.optional, 'Person'] - class A: + class A(xmlfile.XmlFile): __metaclass__ = xmlfile.autoxml t_Name = [types.StringType, xmlfile.mandatory] t_Description = [xmlfile.LocalText, xmlfile.mandatory] @@ -45,6 +45,7 @@ class XmlFileTestCase(unittest.TestCase): t_OtherInfo = [ OtherInfo, xmlfile.optional ] a = A() + print A.__class__ self.assertEqual(a.href, None) dom = mdom.parse('tests/a.xml') node = getNode(dom, 'A')