本文整理汇总了Python中xml.sax.saxutils.XMLGenerator类的典型用法代码示例。如果您正苦于以下问题:Python XMLGenerator类的具体用法?Python XMLGenerator怎么用?Python XMLGenerator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLGenerator类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, out = sys.stdout, encoding = "utf-8", indent = "", addindent = "", newl = ""):
XMLGenerator.__init__(self, out, encoding)
# XMLGenerator does not export _write()
self.write = self.ignorableWhitespace
self.indents = [indent]
self.addindent = addindent
self.newl = newl
开发者ID:nfvproject,项目名称:Myplc,代码行数:7,代码来源:SliceGetTicket.py
示例2: XmlWriter
class XmlWriter(AbstractXmlWriter):
def __init__(self, path):
self.path = path
self._output = open(path, 'wb')
self._writer = XMLGenerator(self._output, 'UTF-8')
self._writer.startDocument()
self.closed = False
def start(self, name, attributes={}, newline=True):
attrs = AttributesImpl(attributes)
self._writer.startElement(name, attrs)
if newline:
self.content('\n')
def content(self, content):
if content is not None:
self._writer.characters(self._encode(content))
def end(self, name, newline=True):
self._writer.endElement(name)
if newline:
self.content('\n')
def close(self):
self._writer.endDocument()
self._output.close()
self.closed = True
开发者ID:superbaby11,项目名称:autoOMC,代码行数:28,代码来源:pyxmlwriter.py
示例3: test_conditional_formatting_update
def test_conditional_formatting_update(self):
class WS():
conditional_formatting = ConditionalFormatting()
worksheet = WS()
rules = {'A1:A4': [{'type': 'colorScale', 'priority': 13,
'colorScale': {'cfvo': [{'type': 'min'}, {'type': 'max'}], 'color':
[Color('FFFF7128'), Color('FFFFEF9C')]}}]}
worksheet.conditional_formatting.update(rules)
temp_buffer = StringIO()
doc = XMLGenerator(out=temp_buffer, encoding='utf-8')
write_worksheet_conditional_formatting(doc, worksheet)
doc.endDocument()
xml = temp_buffer.getvalue()
temp_buffer.close()
diff = compare_xml(xml, """
<conditionalFormatting sqref="A1:A4">
<cfRule type="colorScale" priority="1">
<colorScale>
<cfvo type="min" />
<cfvo type="max" />
<color rgb="FFFF7128" />
<color rgb="FFFFEF9C" />
</colorScale>
</cfRule>
</conditionalFormatting>
""")
assert diff is None, diff
开发者ID:ericgazoni,项目名称:openpyxl,代码行数:28,代码来源:test_conditional_formatting.py
示例4: _close
def _close(self):
"""close an already opened channel"""
generator = XMLGenerator(self.worker)
generator.endElement('channel')
# XXX
self.worker.write('\n')
self.exit = True
开发者ID:akatrevorjay,项目名称:clustershell,代码行数:7,代码来源:Communication.py
示例5: unparse
def unparse(input_dict, output=None, encoding='utf-8', full_document=True, **kwargs):
"""
dict(json)转xml格式
:param input_dict:
:param output:
:param encoding:
:param full_document:
:param kwargs:
:return:
"""
if full_document and len(input_dict) != 1:
raise ValueError('Document must have exactly one root.')
must_return = False
if output is None:
output = StringIO()
must_return = True
content_handler = XMLGenerator(output, encoding)
if full_document:
content_handler.startDocument()
for k, v in input_dict.items():
_emit(k, v, content_handler, full_document=full_document, **kwargs)
if full_document:
content_handler.endDocument()
if must_return:
rep_value = output.getvalue()
try:
rep_value = rep_value.decode(encoding)
except AttributeError:
pass
return rep_value
开发者ID:caowenbin,项目名称:bwpays,代码行数:30,代码来源:xml_json.py
示例6: __init__
def __init__(self, break_into=None, break_after=1000, out=None, *args, **kwargs):
XMLGenerator.__init__(self, out, *args, **kwargs)
self.out_file = out
self.break_into = break_into
self.break_after = break_after
self.context = []
self.count = 0
开发者ID:jaredleekatzman,项目名称:Wordly,代码行数:7,代码来源:XML_breaker.py
示例7: ExportExtractor
class ExportExtractor(XMLFilterBase):
def __init__(self, file):
XMLFilterBase.__init__(self)
self.generator = XMLGenerator(file, 'UTF-8')
self.generator.startPrefixMapping(u'', u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/')
self.replyData = StringIO()
self.replyGenerator = XMLGenerator( self.replyData, 'UTF-8' )
self.switchTarget( self.replyGenerator )
def startDocument(self):
self.generator.startDocument()
XMLFilterBase.startDocument(self)
def endElementNS(self, name, qname):
XMLFilterBase.endElementNS(self, name, qname)
namespace, element = name
if namespace == u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/' and element == u'Export':
self.switchTarget( self.replyGenerator )
def startElementNS(self, name, qname, attrs):
namespace, element = name
if namespace == u'http://www.eucalyptus.com/ns/reporting/export/2012-08-24/' and element == u'Export':
self.switchTarget( self.generator )
XMLFilterBase.startElementNS(self, name, qname, attrs)
def switchTarget(self, target):
self._cont_handler = target
self._dtd_handler = target
self._ent_handler = target
self._err_handler = target
def getReply(self):
return self.replyData.getvalue()
开发者ID:eucalyptus,项目名称:eucalyptus,代码行数:33,代码来源:exportreportdata.py
示例8: encode
def encode(self, obj, root='root'):
buf = StringIO()
xml = XMLGenerator(buf, encoding='utf-8')
xml.startDocument()
self.encode_obj(xml, root, obj)
xml.endDocument()
return buf.getvalue()
开发者ID:thewanderer41,项目名称:YACS,代码行数:7,代码来源:utils.py
示例9: __init__
def __init__(self, out, enc, reader):
XMLGenerator.__init__(self, GetFile(out, "w"), enc)
self.reader = reader
self.num_read_nodes = 0
self.num_read_ways = 0
self.num_read_relations = 0
开发者ID:jocelynj,项目名称:osm,代码行数:7,代码来源:OsmSax.py
示例10: unparse
def unparse(input_dict, output=None, encoding='utf-8', full_document=True,
**kwargs):
"""Emit an XML document for the given `input_dict` (reverse of `parse`).
The resulting XML document is returned as a string, but if `output` (a
file-like object) is specified, it is written there instead.
Dictionary keys prefixed with `attr_prefix` (default=`'@'`) are interpreted
as XML node attributes, whereas keys equal to `cdata_key`
(default=`'#text'`) are treated as character data.
The `pretty` parameter (default=`False`) enables pretty-printing. In this
mode, lines are terminated with `'\n'` and indented with `'\t'`, but this
can be customized with the `newl` and `indent` parameters.
"""
if full_document and len(input_dict) != 1:
raise ValueError('Document must have exactly one root.')
must_return = False
if output is None:
output = StringIO()
must_return = True
content_handler = XMLGenerator(output, encoding)
if full_document:
content_handler.startDocument()
for key, value in input_dict.items():
_emit(key, value, content_handler, full_document=full_document,
**kwargs)
if full_document:
content_handler.endDocument()
if must_return:
value = output.getvalue()
try: # pragma no cover
value = value.decode(encoding)
except AttributeError: # pragma no cover
pass
return value
开发者ID:HybridCloud-dew,项目名称:hws,代码行数:33,代码来源:xmltodict.py
示例11: __init__
def __init__(self, output, encoding, top_level_tag, attrs):
xml_writer = XMLGenerator(output, encoding, True)
xml_writer.startDocument()
xml_writer.startElement(top_level_tag, attrs)
self._xml_writer = xml_writer
self.top_level_tag = top_level_tag
self.ident=4
self._xml_writer.characters('\n')
开发者ID:hachmeister,项目名称:ogre-xml-exporter,代码行数:8,代码来源:ogre_xml_exporter.py
示例12: startElement
def startElement(self, tag, attrs={}):
attrs_write = {'CREATED': gMF(attrs['created_mindmap']),
'MODIFIED': gMF(max(attrs['modified_mindmap'],
attrs['modified_openerp'])),
'ID': attrs['id_mindmap'] or 'ID_' + str(random.randint(1, 10**10)),
'TEXT': attrs['name'],
}
XMLGenerator.startElement(self, tag, attrs_write)
开发者ID:kossovo,项目名称:Anytracker,代码行数:8,代码来源:mindmap_parse.py
示例13: startElement
def startElement(self, name, attrs, indent = True, newl = True):
if indent:
self.ignorableWhitespace("".join(self.indents))
self.indents.append(self.addindent)
XMLGenerator.startElement(self, name, attrs)
if newl:
self.ignorableWhitespace(self.newl)
开发者ID:nfvproject,项目名称:Myplc,代码行数:9,代码来源:SliceGetTicket.py
示例14: endElement
def endElement(self, name, indent = True, newl = True):
self.indents.pop()
if indent:
self.ignorableWhitespace("".join(self.indents))
XMLGenerator.endElement(self, name)
if newl:
self.ignorableWhitespace(self.newl)
开发者ID:nfvproject,项目名称:Myplc,代码行数:9,代码来源:SliceGetTicket.py
示例15: characters
def characters(self, content):
try:
if content.lstrip().startswith("<"):
etree.fromstring(content)
self._write(content)
else:
XMLGenerator.characters(self, content)
except (AttributeError, Exception):
#TODO could be more specific on errors caught
XMLGenerator.characters(self, content)
开发者ID:drpoggi,项目名称:compysition,代码行数:10,代码来源:event.py
示例16: manifest_xml
def manifest_xml(f, files):
from xml.sax.saxutils import XMLGenerator
xml = XMLGenerator(f, "utf-8")
xml.startDocument()
uri = "urn:oasis:names:tc:opendocument:xmlns:manifest:1.0"
prefix = "manifest"
xml.startPrefixMapping(prefix, uri)
def startElement(name, attrs):
attrs = dict(((uri, n), v) for n, v in attrs.iteritems())
xml.startElementNS((uri, name), prefix + ":" + name, attrs)
def endElement(name):
xml.endElementNS((uri, name), prefix + ":" + name)
def file_entry(full_path, media_type, **kwargs):
attrs = {"media-type": media_type, "full-path": full_path}
attrs.update(dict((n.replace("_", "-"), v) for n, v in kwargs.iteritems()))
startElement("file-entry", attrs)
endElement("file-entry")
startElement("manifest", dict(version="1.2"))
file_entry("/", "application/vnd.oasis.opendocument.text", version="1.2")
for e in files:
e = dict(e)
full_path = e.pop("full_path")
media_type = e.pop("media_type", "application/octet-stream")
file_entry(full_path, media_type)
endElement("manifest")
xml.endPrefixMapping(prefix)
xml.endDocument()
开发者ID:spoon-today,项目名称:pyhwp,代码行数:34,代码来源:hwp5odt.py
示例17: export
def export(self,filename,transport):
vprint( "osm-xml export...",1)
#remember all nodes already exported
unodes = {}
fp = open(filename, "w")
x = XMLGenerator(fp, "UTF-8")
x.startDocument()
x.startElement('osm',{"version":"0.6","generator":"crazy py script"})
for w in self.ways.itervalues():
if not 'highway' in w.tags:
continue
if transport == "all" or transport == "pt":
if not (w.tags['highway']=='bus' or w.tags['highway']=='tram'):
continue
if transport == "all" or transport == "hw":
if (w.tags['highway']=='bus' or w.tags['highway']=='tram'):
continue
w.toOSM(x)
for nid in w.nds:
if nid in unodes:#already used
continue
unodes[nid]=True
if w.nds.index(nid)==0 or w.nds.index(nid)==len(w.nds)-1:
self.nodes[nid].toOSM(x,True)
else:
self.nodes[nid].toOSM(x)
x.endElement('osm')
x.endDocument()
开发者ID:k4r573n,项目名称:OSM2Graph,代码行数:31,代码来源:osm2graph.py
示例18: test_conditional_font
def test_conditional_font(self):
"""Test to verify font style written correctly."""
class WS():
conditional_formatting = ConditionalFormatting()
worksheet = WS()
# Create cf rule
redFill = Fill()
redFill.start_color.index = 'FFEE1111'
redFill.end_color.index = 'FFEE1111'
redFill.fill_type = Fill.FILL_SOLID
whiteFont = Font()
whiteFont.color.index = "FFFFFFFF"
worksheet.conditional_formatting.add('A1:A3', CellIsRule(operator='equal', formula=['"Fail"'], stopIfTrue=False,
font=whiteFont, fill=redFill))
worksheet.conditional_formatting.setDxfStyles(self.workbook)
# First, verify conditional formatting xml
temp_buffer = StringIO()
doc = XMLGenerator(out=temp_buffer, encoding='utf-8')
write_worksheet_conditional_formatting(doc, worksheet)
doc.endDocument()
xml = temp_buffer.getvalue()
temp_buffer.close()
diff = compare_xml(xml, """
<conditionalFormatting sqref="A1:A3">
<cfRule dxfId="0" operator="equal" priority="1" type="cellIs">
<formula>"Fail"</formula>
</cfRule>
</conditionalFormatting>
""")
assert diff is None, diff
# Second, verify conditional formatting dxf styles
w = StyleWriter(self.workbook)
w._write_dxfs()
xml = get_xml(w._root)
diff = compare_xml(xml, """
<styleSheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
<dxfs count="1">
<dxf>
<font>
<color rgb="FFFFFFFF" />
</font>
<fill>
<patternFill patternType="solid">
<fgColor rgb="FFEE1111" />
<bgColor rgb="FFEE1111" />
</patternFill>
</fill>
</dxf>
</dxfs>
</styleSheet>
""")
assert diff is None, diff
开发者ID:ericgazoni,项目名称:openpyxl,代码行数:55,代码来源:test_conditional_formatting.py
示例19: manifest_xml
def manifest_xml(f, files):
from xml.sax.saxutils import XMLGenerator
xml = XMLGenerator(f, 'utf-8')
xml.startDocument()
uri = 'urn:oasis:names:tc:opendocument:xmlns:manifest:1.0'
prefix = 'manifest'
xml.startPrefixMapping(prefix, uri)
def startElement(name, attrs):
attrs = dict( ((uri, n), v) for n, v in attrs.iteritems() )
xml.startElementNS( (uri, name), prefix+':'+name, attrs)
def endElement(name):
xml.endElementNS( (uri, name), prefix+':'+name)
def file_entry(full_path, media_type, **kwargs):
attrs = {'media-type': media_type, 'full-path': full_path}
attrs.update(dict((n.replace('_', '-'), v) for n, v in kwargs.iteritems()))
startElement('file-entry', attrs)
endElement('file-entry')
startElement( 'manifest', dict(version='1.2') )
file_entry('/', 'application/vnd.oasis.opendocument.text', version='1.2')
for e in files:
e = dict(e)
full_path = e.pop('full_path')
media_type = e.pop('media_type', 'application/octet-stream')
file_entry(full_path, media_type)
endElement( 'manifest' )
xml.endPrefixMapping(prefix)
xml.endDocument()
开发者ID:changwoo,项目名称:pyhwp,代码行数:32,代码来源:hwp5odt.py
示例20: startElement
def startElement(self, name, attrs):
pos = name.find(':')
tag = name if pos == -1 else name[pos+1:]
attr = self.rules.get(tag)
XMLGenerator.startElement(self, name, attrs)
if attr is None:
self.trans = False
elif attr is True:
self.trans = True
else:
self.trans = attrs.get(attr[0]) == attr[1]
开发者ID:wumch,项目名称:saa,代码行数:11,代码来源:xml_handler.py
注:本文中的xml.sax.saxutils.XMLGenerator类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论