

def writexml(self, stream, indent='', addindent='', newl='', strip=0, nsprefixes={
    
}, namespace=''):
    '\n        Serialize this L{Element} to the given stream.\n\n        @param stream: A file-like object to which this L{Element} will be\n            written.\n\n        @param nsprefixes: A C{dict} mapping namespace URIs as C{str} to\n            prefixes as C{str}.  This defines the prefixes which are already in\n            scope in the document at the point at which this L{Element} exists.\n            This is essentially an implementation detail for namespace support.\n            Applications should not try to use it.\n\n        @param namespace: The namespace URI as a C{str} which is the default at\n            the point in the document at which this L{Element} exists.  This is\n            essentially an implementation detail for namespace support.\n            Applications should not try to use it.\n        '
    ALLOWSINGLETON = ('img', 'br', 'hr', 'base', 'meta', 'link', 'param', 'area', 'input', 'col', 'basefont', 'isindex', 'frame')
    BLOCKELEMENTS = ('html', 'head', 'body', 'noscript', 'ins', 'del', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'script', 'ul', 'ol', 'dl', 'pre', 'hr', 'blockquote', 'address', 'p', 'div', 'fieldset', 'table', 'tr', 'form', 'object', 'fieldset', 'applet', 'map')
    FORMATNICELY = ('tr', 'ul', 'ol', 'head')
    if (not self.preserveCase):
        self.endTagName = self.tagName
    w = stream.write
    if self.nsprefixes:
        newprefixes = self.nsprefixes.copy()
        for ns in nsprefixes.keys():
            if (ns in newprefixes):
                del newprefixes[ns]
    else:
        newprefixes = {
            
        }
    begin = ['<']
    if (self.tagName in BLOCKELEMENTS):
        begin = ([newl, indent] + begin)
    bext = begin.extend
    writeattr = (lambda _atr, _val: bext((' ', _atr, '="', escape(_val), '"')))
    endTagName = self.endTagName
    if ((namespace != self.namespace) and (self.namespace is not None)):
        if (self.namespace in nsprefixes):
            prefix = nsprefixes[self.namespace]
            bext(((prefix + ':') + self.tagName))
            endTagName = ((prefix + ':') + self.endTagName)
        else:
            bext(self.tagName)
            writeattr('xmlns', self.namespace)
            namespace = self.namespace
    else:
        bext(self.tagName)
    j = ''.join
    for (attr, val) in self.attributes.iteritems():
        if isinstance(attr, tuple):
            (ns, key) = attr
            if nsprefixes.has_key(ns):
                prefix = nsprefixes[ns]
            else:
                prefix = genprefix()
                newprefixes[ns] = prefix
            assert (val is not None)
            writeattr(((prefix + ':') + key), val)
        else:
            assert (val is not None)
            writeattr(attr, val)
    if newprefixes:
        for (ns, prefix) in newprefixes.iteritems():
            if prefix:
                writeattr(('xmlns:' + prefix), ns)
        newprefixes.update(nsprefixes)
        downprefixes = newprefixes
    else:
        downprefixes = nsprefixes
    w(j(begin))
    if self.childNodes:
        w('>')
        newindent = (indent + addindent)
        for child in self.childNodes:
            if ((self.tagName in BLOCKELEMENTS) and (self.tagName in FORMATNICELY)):
                w(j((newl, newindent)))
            child.writexml(stream, newindent, addindent, newl, strip, downprefixes, namespace)
        if (self.tagName in BLOCKELEMENTS):
            w(j((newl, indent)))
        w(j(('</', endTagName, '>')))
    elif (self.tagName.lower() not in ALLOWSINGLETON):
        w(j(('></', endTagName, '>')))
    else:
        w(' />')

dataset/ETHPy150Open kuri65536/python-for-android/python-modules/twisted/twisted/web/microdom.py Element.writexml/original