* local text'i implement etmek icin __init__ interface'ini genislet
* localtext class'inin metodlarini yaz * nedir kardesim ne bakiyorsun
This commit is contained in:
+27
-13
@@ -55,15 +55,23 @@ mandatory, optional = range(2) # poor man's enum
|
|||||||
Text = types.StringType
|
Text = types.StringType
|
||||||
Integer = types.IntType
|
Integer = types.IntType
|
||||||
|
|
||||||
|
#class datatype(type):
|
||||||
|
# def __init__(cls, name, bases, dict):
|
||||||
|
# """entry point for metaclass code"""
|
||||||
|
# # standard initialization
|
||||||
|
# super(autoxml, cls).__init__(name, bases, dict)
|
||||||
|
|
||||||
class LocalText(object):
|
class LocalText(object):
|
||||||
"""Handles XML tags/attributes with localized text"""
|
"""Handles XML tags with localized text"""
|
||||||
|
|
||||||
def __init__():
|
def __init__(self, tag, spec):
|
||||||
locs = {}
|
self.tag = tag
|
||||||
|
self.req = spec[1]
|
||||||
|
self.locs = {}
|
||||||
|
|
||||||
def decode(nodes, req):
|
def decode(self, node):
|
||||||
# flags, tag name, instance attribute
|
# flags, tag name, instance attribute
|
||||||
|
nodes = getAllNodes(node, tag)
|
||||||
if not nodes:
|
if not nodes:
|
||||||
if req == mandatory:
|
if req == mandatory:
|
||||||
pass
|
pass
|
||||||
@@ -80,14 +88,20 @@ class LocalText(object):
|
|||||||
lang = 'en'
|
lang = 'en'
|
||||||
self.locs[lang] = c
|
self.locs[lang] = c
|
||||||
# FIXME: return full list too
|
# FIXME: return full list too
|
||||||
L = language
|
#L = language
|
||||||
if not locs.has_key(L):
|
#if not self.locs.has_key(L):
|
||||||
L = 'en'
|
# L = 'en'
|
||||||
if not locs.has_key(L):
|
#if not self.locs.has_key(L):
|
||||||
#errs.append("Tag '%s' should have an English version\n" % d[2])
|
# #errs.append("Tag '%s' should have an English version\n" % d[2])
|
||||||
return ""
|
# return ""
|
||||||
return locs[L]
|
#retur
|
||||||
|
|
||||||
|
def encode(self, xml, node):
|
||||||
|
for key in self.locs.iterkeys():
|
||||||
|
lang = addTextNode(node, key, self.locs[key])
|
||||||
|
|
||||||
|
def format(self):
|
||||||
|
return ''
|
||||||
|
|
||||||
class autoxml(type):
|
class autoxml(type):
|
||||||
"""High-level automatic XML transformation interface for xmlfile.
|
"""High-level automatic XML transformation interface for xmlfile.
|
||||||
@@ -198,7 +212,7 @@ class autoxml(type):
|
|||||||
|
|
||||||
# generate top-level helper functions
|
# generate top-level helper functions
|
||||||
cls.initializers = inits
|
cls.initializers = inits
|
||||||
def initialize(self):
|
def initialize(self, tag = None, spec = None):
|
||||||
# XmlFile.__init__(self, cls.tag)
|
# XmlFile.__init__(self, cls.tag)
|
||||||
for init in self.__class__.initializers:
|
for init in self.__class__.initializers:
|
||||||
init(self)
|
init(self)
|
||||||
@@ -382,7 +396,7 @@ 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)
|
return tag_type.__new__(tag_type, tag, spec)
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
return make_object()
|
return make_object()
|
||||||
|
|||||||
@@ -58,9 +58,8 @@ class XmlFileTestCase(unittest.TestCase):
|
|||||||
xml = xmlfile.XmlFile('A')
|
xml = xmlfile.XmlFile('A')
|
||||||
xml.newDOM()
|
xml.newDOM()
|
||||||
a.encode(xml, xml.rootNode())
|
a.encode(xml, xml.rootNode())
|
||||||
xml.rootNode().appendChild(node)
|
|
||||||
xml.writexml('/tmp/a.xml')
|
xml.writexml('/tmp/a.xml')
|
||||||
#print '/tmp/a.xml written'
|
print '/tmp/a.xml written'
|
||||||
xml = xmlfile.XmlFile('A')
|
xml = xmlfile.XmlFile('A')
|
||||||
a2 = A()
|
a2 = A()
|
||||||
a2.name = "Baris Metin"
|
a2.name = "Baris Metin"
|
||||||
|
|||||||
Reference in New Issue
Block a user