当前位置: 首页>>代码示例>>Python>>正文


Python ElementTree.Comment方法代码示例

本文整理汇总了Python中xml.etree.ElementTree.Comment方法的典型用法代码示例。如果您正苦于以下问题:Python ElementTree.Comment方法的具体用法?Python ElementTree.Comment怎么用?Python ElementTree.Comment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.etree.ElementTree的用法示例。


在下文中一共展示了ElementTree.Comment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: writefile

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def writefile():
    """
    >>> elem = ET.Element("tag")
    >>> elem.text = "text"
    >>> serialize(elem)
    '<tag>text</tag>'
    >>> ET.SubElement(elem, "subtag").text = "subtext"
    >>> serialize(elem)
    '<tag>text<subtag>subtext</subtag></tag>'

    Test tag suppression
    >>> elem.tag = None
    >>> serialize(elem)
    'text<subtag>subtext</subtag>'
    >>> elem.insert(0, ET.Comment("comment"))
    >>> serialize(elem)     # assumes 1.3
    'text<!--comment--><subtag>subtext</subtag>'
    >>> elem[0] = ET.PI("key", "value")
    >>> serialize(elem)
    'text<?key value?><subtag>subtext</subtag>'
    """ 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:23,代码来源:test_xml_etree.py

示例2: bug_200709_element_comment

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def bug_200709_element_comment():
    """

    Not sure if this can be fixed, really (since the serializer needs
    ET.Comment, not cET.comment).

    >>> a = ET.Element('a')
    >>> a.append(ET.Comment('foo'))
    >>> a[0].tag == ET.Comment
    True

    >>> a = ET.Element('a')
    >>> a.append(ET.PI('foo'))
    >>> a[0].tag == ET.PI
    True

    """ 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:19,代码来源:test_xml_etree.py

示例3: add_output_metadata

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def add_output_metadata(root):
    """Build the main metadata and tags for an XML report.

    Args:
        root: Element to be used as the root for the report.
    """
    jss_connection = JSSConnection.get()
    report_date = ET.SubElement(root, "ReportDate")
    report_date.text = datetime.datetime.strftime(datetime.datetime.now(),
                                                  "%Y%m%d-%H%M%S")
    report_server = ET.SubElement(root, "Server")
    report_server.text = jss_connection.base_url
    api_user = ET.SubElement(root, "APIUser")
    api_user.text = jss_connection.user
    report_user = ET.SubElement(root, "LocalUser")
    report_user.text = os.getenv("USER")
    spruce_version = ET.SubElement(root, "SpruceVersion")
    spruce_version.text = __version__
    python_jss_version = ET.SubElement(root, "python-jssVersion")
    python_jss_version.text = jss.__version__
    removals = ET.SubElement(root, "Removals")
    removals.insert(0, ET.Comment("Move items to be removed here")) 
开发者ID:jssimporter,项目名称:Spruce,代码行数:24,代码来源:spruce.py

示例4: export_xml

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def export_xml(self, filename=XML_FILE_NAME):
		"""
		Exports an XML file that can be reimported with the parseXMLFiles
		function.
		"""
		eapeakXML = ElementTree.Element('detection-run')
		eapeakXML.set('eapeak-version', __version__)
		eapeakXML.append(ElementTree.Comment(' Summary: Found ' + str(len(self.KnownNetworks)) + ' Network(s) '))
		eapeakXML.append(ElementTree.Comment(datetime.datetime.now().strftime(' Created %A %m/%d/%Y %H:%M:%S ')))
		networks = self.KnownNetworks.keys()
		if not networks:
			return
		networks.sort()
		for network in networks:
			eapeakXML.append(self.KnownNetworks[network].get_xml())
		xmldata = minidom.parseString(ElementTree.tostring(eapeakXML)).toprettyxml()
		if xmldata:
			tmpfile = open(filename, 'w')
			tmpfile.write(xmldata)
			tmpfile.close() 
开发者ID:rsmusllp,项目名称:eapeak,代码行数:22,代码来源:parse.py

示例5: summarize

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def summarize(elem):
    if elem.tag == ET.Comment:
        return "<Comment>"
    return elem.tag 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:6,代码来源:test_xml_etree.py

示例6: bug_200709_iter_comment

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def bug_200709_iter_comment():
    """

    >>> a = ET.Element('a')
    >>> b = ET.SubElement(a, 'b')
    >>> comment_b = ET.Comment("TEST-b")
    >>> b.append(comment_b)
    >>> summarize_list(a.iter(ET.Comment))
    ['<Comment>']

    """

# --------------------------------------------------------------------
# reported on bugs.python.org 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:16,代码来源:test_xml_etree.py

示例7: bug_200709_iter_comment

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def bug_200709_iter_comment():
    """

    >>> a = ET.Element('a')
    >>> b = ET.SubElement(a, 'b')
    >>> comment_b = ET.Comment("TEST-b")
    >>> b.append(comment_b)
    >>> summarize_list(a.iter(ET.Comment))
    ['<Comment>']

    """ 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:13,代码来源:test_xml_etree.py

示例8: toxml

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def toxml(
    data,
    xml_root_tag,
    xml_schemas=None,
    root_list_path="iati-activity",
    xml_comment=None,
):
    nsmap = {
        # This is "bound by definition" - see https://www.w3.org/XML/1998/namespace
        "xml": "http://www.w3.org/XML/1998/namespace"
    }
    root = dict_to_xml(data, xml_root_tag, nsmap=nsmap)
    if xml_schemas is not None:
        schema_dict = XMLSchemaWalker(xml_schemas).create_schema_dict(root_list_path)
        for element in root:
            sort_element(element, schema_dict)
    if xml_comment is None:
        xml_comment = "XML generated by flatten-tool"
    comment = ET.Comment(xml_comment)
    root.insert(0, comment)
    if USING_LXML:
        return ET.tostring(
            root, pretty_print=True, xml_declaration=True, encoding="utf-8"
        )
    else:
        return ET.tostring(root) 
开发者ID:OpenDataServices,项目名称:flatten-tool,代码行数:28,代码来源:xml_output.py

示例9: comment

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def comment(self, data):
        self.start(ET.Comment, {})
        self.data(data)
        self.end(ET.Comment) 
开发者ID:rmrector,项目名称:script.artwork.beef,代码行数:6,代码来源:advancedsettings.py

示例10: save_structure_map

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def save_structure_map():
    pat_id = 'TPL_045_DAPD'
    m_logs_dir = os.path.join(log_dir, pat_id)
    filename = pat_id+'structure_map.xml'

    import xml.etree.ElementTree as ET
    # from xml.etree.ElementTree import ElementTree, Element, SubElement, Comment
    from datetime import datetime, date
    from xml.dom import minidom


    top = ET.Element('StructureMap')

    d = datetime.now()
    comment = ET.Comment(d.isoformat())
    top.append(comment)

    protocol = ET.SubElement(top, 'protocol_structure')
    protocol.text = 'OTV4_4000'

    local_name = ET.SubElement(top, 'local_name')
    local_name.text = 'PTV1_MD'

    local_dose = ET.SubElement(top, 'local_dose')#, units='Gy')
    local_dose.text = '40'
    local_dose.set('units','Gy')

    print prettify(top)
    xmlstr = minidom.parseString(ET.tostring(top)).toprettyxml(indent="   ")
    full_path_filename = os.path.normpath('{}/{}'.format(m_logs_dir, filename))
    with open(full_path_filename, "w") as f:
        f.write(xmlstr)
    # ElementTree(top).write(os.path.normpath('{}/{}'.format(m_logs_dir, filename))) 
开发者ID:wrssc,项目名称:ray_scripts,代码行数:35,代码来源:Xml_Out.py

示例11: comment

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def comment(self, data):
       self.start(ET.Comment, {})
       self.data(data)
       self.end(ET.Comment)

# WTF?! ElementTree overrides the Python declaration of XMLParser with some optimized-C version.
# Putting overriding methods on a class derived from that simply doesn't work.
# So we need to copy the whole fucking implementation of XMLParser where overriding ONE method would have sufficed! 
开发者ID:harag-on-steam,项目名称:se-blender,代码行数:10,代码来源:merge_xml.py

示例12: element_set_text

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def element_set_text(element, content):
    # retain html tags in content
    content = escape(content, entities={'\r\n': '<br />'})
    # replace new line for *nix system
    content = content.replace('\n', '<br />')
    # add the line break in source to make it readable
    content = content.replace('<br />', '<br />\n')

    # add CDATA for a element
    element.append(Comment(' --><![CDATA[' + content.replace(']]>', ']]]]><![CDATA[>') + ']]> <!-- ')) 
开发者ID:zhuifengshen,项目名称:xmind2testcase,代码行数:12,代码来源:testlink.py

示例13: _serialize_html

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def _serialize_html(write, elem, format):
    tag = elem.tag
    text = elem.text
    if tag is Comment:
        write("<!--%s-->" % _escape_cdata(text))
    elif tag is ProcessingInstruction:
        write("<?%s?>" % _escape_cdata(text))
    elif tag is None:
        if text:
            write(_escape_cdata(text))
        for e in elem:
            _serialize_html(write, e, format)
    else:
        namespace_uri = None
        if isinstance(tag, QName):
            # QNAME objects store their data as a string: `{uri}tag`
            if tag.text[:1] == "{":
                namespace_uri, tag = tag.text[1:].split("}", 1)
            else:
                raise ValueError('QName objects must define a tag.')
        write("<" + tag)
        items = elem.items()
        if items:
            items = sorted(items)  # lexical order
            for k, v in items:
                if isinstance(k, QName):
                    # Assume a text only QName
                    k = k.text
                if isinstance(v, QName):
                    # Assume a text only QName
                    v = v.text
                else:
                    v = _escape_attrib_html(v)
                if k == v and format == 'html':
                    # handle boolean attributes
                    write(" %s" % v)
                else:
                    write(' {}="{}"'.format(k, v))
        if namespace_uri:
            write(' xmlns="%s"' % (_escape_attrib(namespace_uri)))
        if format == "xhtml" and tag.lower() in HTML_EMPTY:
            write(" />")
        else:
            write(">")
            if text:
                if tag.lower() in ["script", "style"]:
                    write(text)
                else:
                    write(_escape_cdata(text))
            for e in elem:
                _serialize_html(write, e, format)
            if tag.lower() not in HTML_EMPTY:
                write("</" + tag + ">")
    if elem.tail:
        write(_escape_cdata(elem.tail)) 
开发者ID:V1EngineeringInc,项目名称:V1EngineeringInc-Docs,代码行数:57,代码来源:serializers.py

示例14: _serialize_xml

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def _serialize_xml(write, elem, qnames, namespaces,
                   short_empty_elements, **kwargs):
    tag = elem.tag
    text = elem.text
    if tag is Comment:
        write("<!--%s-->" % text)
    elif tag is ProcessingInstruction:
        write("<?%s?>" % text)
    else:
        tag = qnames[tag]
        if tag is None:
            if text:
                write(_escape_cdata(text))
            for e in elem:
                _serialize_xml(write, e, qnames, None,
                               short_empty_elements=short_empty_elements)
        else:
            write("<" + tag)
            items = list(elem.items())
            if items or namespaces:
                if namespaces:
                    for v, k in sorted(namespaces.items(),
                                       key=lambda x: x[1]):  # sort on prefix
                        if k:
                            k = ":" + k
                        write(" xmlns%s=\"%s\"" % (
                            k,
                            _escape_attrib(v)
                            ))

                # below is the changed line. assuming attrib is an OrderedDict this will preserve attribute order
                for k, v in elem.attrib.items():
                    if isinstance(k, QName):
                        k = k.text
                    if isinstance(v, QName):
                        v = qnames[v.text]
                    else:
                        v = _escape_attrib(v)
                    write(" %s=\"%s\"" % (qnames[k], v))
            if text or len(elem) or not short_empty_elements:
                write(">")
                if text:
                    write(_escape_cdata(text))
                for e in elem:
                    _serialize_xml(write, e, qnames, None,
                                   short_empty_elements=short_empty_elements)
                write("</" + tag + ">")
            else:
                write(" />")
    if elem.tail:
        write(_escape_cdata(elem.tail)) 
开发者ID:harag-on-steam,项目名称:se-blender,代码行数:53,代码来源:merge_xml.py

示例15: material_xml

# 需要导入模块: from xml.etree import ElementTree [as 别名]
# 或者: from xml.etree.ElementTree import Comment [as 别名]
def material_xml(settings, mat, file=None, node=None):
    d = data(mat)
    e = ElementTree.Element("Material", Name=mat.name)
    m = SEMaterialInfo(mat)

    def param(name, value):
        se = ElementTree.SubElement(e, 'Parameter', Name=name)
        if value:
            se.text = value

    param("Technique", _material_technique(d.technique))
    param("SpecularIntensity", _floatstr(m.specularIntensity))
    param("SpecularPower", _floatstr(m.specularPower))

    if 'GLASS' == d.technique:
        param("DiffuseColorX", '255')
        param("DiffuseColorY", '255')
        param("DiffuseColorZ", '255')
        param("GlassMaterialCCW", d.glass_material_ccw)
        param("GlassMaterialCW", d.glass_material_cw)
        param("GlassSmooth", str(d.glass_smooth))
    else:
        r, g, b = rgb(m.diffuseColor)
        param("DiffuseColorX", str(int(255 * r)))
        param("DiffuseColorY", str(int(255 * g)))
        param("DiffuseColorZ", str(int(255 * b)))

    # only for legacy materials
    if m.couldDefaultNormalTexture and not TextureType.Normal in m.images:
        m.images[TextureType.Normal] = ''

    for texType in TextureType:
        filepath = m.images.get(texType, None)
        if not filepath is None:
            derivedPath = derive_texture_path(settings, filepath)
            if (BAD_PATH.search(derivedPath)):
                settings.error("The %s texture of material '%s' exports with the non-portable path: '%s'. "
                               "Consult the documentation on texture-paths."
                               % (texType.name, mat.name, derivedPath), file=file, node=node)
            param(texType.name + "Texture", derivedPath)
        else:
            e.append(ElementTree.Comment("material has no %sTexture" % texType.name))

    return e 
开发者ID:harag-on-steam,项目名称:se-blender,代码行数:46,代码来源:mwmbuilder.py


注:本文中的xml.etree.ElementTree.Comment方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。