示例#1
0
    def gotTagStart(self, name, attributes):
        # logger.debug('%s<%s>', ' ' * self.indentlevel, name)
        self.indentlevel += 2
        parent = self._getparent()
        parent = self._check_parent(parent, name)

        unesc_attributes = unescape_dict(attributes)
        namespaces = self.nsstack[-1][0]
        newspaces = dict(self._gen_newspaces(unesc_attributes))
        new_unesc_attributes = dict(self._gen_new_attrs(unesc_attributes))
        new_namespaces = merge([namespaces, newspaces])
        gen_attr_args = (new_unesc_attributes, new_namespaces)
        new_attributes = dict(self._gen_attrs(*gen_attr_args))
        el_args = (name, new_attributes, parent, self.filename, self.saveMark())

        kwargs = {
            'case_insensitive': self.case_insensitive,
            'namespace': new_namespaces.get('')}

        el = Element(*el_args, **kwargs)
        revspaces = invert_dict(newspaces)
        el.addPrefixes(revspaces)

        if newspaces:
            rscopy = merge([self.nsstack[-1][2], revspaces])
            self.nsstack.append((new_namespaces, el, rscopy))

        self.elementstack.append(el)

        if parent:
            parent.appendChild(el)

        if (self.lenient and el.tagName in self.soonClosers):
            self.gotTagEnd(name)
示例#2
0
 def __init__(self, case_insensitive=True, **kwargs):
     # Protocol is an old style class so we can't use super
     XMLParser.__init__(self, **kwargs)
     self.elementstack = []
     d = {'xmlns': 'xmlns', '': None}
     dr = invert_dict(d)
     self.nsstack = [(d, None, dr)]
     self.documents = []
     self._mddoctype = None
     self.case_insensitive = case_insensitive
     self.preserve_case = case_insensitive
     self.soonClosers = kwargs.get('soonClosers', self.def_soon_closers)
     self.laterClosers = kwargs.get('laterClosers', self.def_later_closers)
     self.indentlevel = 0
示例#3
0
文件: microdom.py 项目: nerevu/riko
 def __init__(self, case_insensitive=True, **kwargs):
     # Protocol is an old style class so we can't use super
     XMLParser.__init__(self, **kwargs)
     self.elementstack = []
     d = {'xmlns': 'xmlns', '': None}
     dr = invert_dict(d)
     self.nsstack = [(d, None, dr)]
     self.documents = []
     self._mddoctype = None
     self.case_insensitive = case_insensitive
     self.preserve_case = case_insensitive
     self.soonClosers = kwargs.get('soonClosers', self.def_soon_closers)
     self.laterClosers = kwargs.get('laterClosers', self.def_later_closers)
     self.indentlevel = 0