* we're in business, use XmlFile as a baseclass

now in a somewhat kludgey way, for testing purposes
  (the automatic addition of XmlFile as a base class
   doesn't work yet)
This commit is contained in:
Eray Özkural
2005-10-26 15:55:56 +00:00
parent 040a1aa28a
commit d97f4e3773
4 changed files with 23 additions and 13 deletions
+6 -2
View File
@@ -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 = []
+14 -6
View File
@@ -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):
-3
View File
@@ -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, '')
+3 -2
View File
@@ -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')