Ejemplo n.º 1
0
 def __repr__(self):
     attrs = [
         ('%s=%r' % (keyword_identifier(normalize_unicode(t[0])), t[1]))
         for t in self._attribs.items()
     ]
     cl = self.__class__
     return "%s.%s(%s)" % (cl.__module__, cl.__name__, ", ".join(attrs))
Ejemplo n.º 2
0
 def startElement(self, name, atts):
     "Handle an event for the beginning of an element."
     try:
         klass = self._get_class(name)
     except AttributeError:
         raise POM.ValidationError("Undefined element tag: " + name)
     attr = {}
     for name, value in atts.items():
         attr[keyword_identifier(POM.normalize_unicode(name))] = POM.unescape(value)
     obj = klass(**attr)
     self.stack.append(obj)
Ejemplo n.º 3
0
 def _add_element_attlist(self, element, xmlattribute, ident):
     try:
         attrmap = element.get_attribute("ATTRIBUTES")
         kwattrmap = element.get_attribute("KWATTRIBUTES")
     except KeyError:
         element.add_attribute("ATTRIBUTES", AttributeMap())
         element.add_attribute("KWATTRIBUTES", AttributeMap())
         attrmap = element.get_attribute("ATTRIBUTES")
         kwattrmap = element.get_attribute("KWATTRIBUTES")
     attrmap[xmlattribute.name] = ident
     keywordname = keyword_identifier(normalize_unicode(xmlattribute.name))
     kwattrmap[keywordname] = ident
Ejemplo n.º 4
0
 def _add_element_attlist(self, element, xmlattribute, ident):
     try:
         attrmap = element.get_attribute("ATTRIBUTES")
         kwattrmap = element.get_attribute("KWATTRIBUTES")
     except KeyError:
         element.add_attribute("ATTRIBUTES", AttributeMap())
         element.add_attribute("KWATTRIBUTES", AttributeMap())
         attrmap = element.get_attribute("ATTRIBUTES")
         kwattrmap = element.get_attribute("KWATTRIBUTES")
     attrmap[xmlattribute.name] = ident
     keywordname = keyword_identifier(normalize_unicode(xmlattribute.name))
     kwattrmap[keywordname] = ident
Ejemplo n.º 5
0
 def startElement(self, name, atts):
     "Handle an event for the beginning of an element."
     try:
         klass = self._get_class(name)
     except AttributeError:
         raise POM.ValidationError("Undefined element tag: " + name)
     attr = {}
     for name, value in atts.items():
         attr[keyword_identifier(
             POM.normalize_unicode(name))] = POM.unescape(value)
     obj = klass(**attr)
     self.stack.append(obj)
Ejemplo n.º 6
0
 def new_attribute(self, elem, a_name, a_type, a_decl, a_def):
     "Receives the declaration of a new attribute."
     attr = XMLAttribute(a_name, a_type, a_decl, a_def)
     ident = attr.get_identifier()
     self._allattributes[ident] = attr
     try:
         element = self.elements[elem]
     except KeyError:
         # Got a forward attribute definition (defined before element)
         try:
             fwdattribs, fwdkwattribs = self._forwardattributes[elem]
         except KeyError:
             fwdattribs = AttributeMap()
             fwdkwattribs = AttributeMap()
             self._forwardattributes[elem] = (fwdattribs, fwdkwattribs)
         fwdattribs[a_name] = ident
         keywordname = keyword_identifier(normalize_unicode(a_name))
         fwdkwattribs[keywordname] = ident
     else:
         self._add_element_attlist(element, attr, ident)
Ejemplo n.º 7
0
 def new_attribute(self, elem, a_name, a_type, a_decl, a_def):
     "Receives the declaration of a new attribute."
     attr = XMLAttribute(a_name, a_type, a_decl, a_def)
     ident = attr.get_identifier()
     self._allattributes[ident] = attr
     try:
         element = self.elements[elem]
     except KeyError:
         # Got a forward attribute definition (defined before element)
         try:
             fwdattribs, fwdkwattribs = self._forwardattributes[elem]
         except KeyError:
             fwdattribs = AttributeMap()
             fwdkwattribs = AttributeMap()
             self._forwardattributes[elem] = (fwdattribs, fwdkwattribs)
         fwdattribs[a_name] = ident
         keywordname = keyword_identifier(normalize_unicode(a_name))
         fwdkwattribs[keywordname] = ident
     else:
         self._add_element_attlist(element, attr, ident)