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


Python ElementTree.tostring方法代码示例

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


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

示例1: conflict

# 需要导入模块: from etree import ElementTree [as 别名]
# 或者: from etree.ElementTree import tostring [as 别名]
def conflict(request, exception):
    #'Conflict'
    builder = ET.TreeBuilder()
    
    builder.start('response', {'status':'409'})
    
    builder.start('message', {})
    builder.data('conflict: ' + str(exception))
    builder.end('message')
    
    xml = builder.end('response')
    
    xml_str = ET.tostring(xml, encoding="utf8")
    response = Response(xml_str, status=409, content_type='text/xml')
    return response.send(request._start_response)
开发者ID:nikolaijivkov,项目名称:Cndep_Rest_Service__iDigi_Dia,代码行数:17,代码来源:cndep_rest.py

示例2: app_error

# 需要导入模块: from etree import ElementTree [as 别名]
# 或者: from etree.ElementTree import tostring [as 别名]
def app_error(request, exception):
    #'Application Error'
    builder = ET.TreeBuilder()
    
    builder.start('response', {'status':'500'})
    
    builder.start('message', {})
    builder.data('application error: ' + str(exception))
    builder.end('message')
    
    xml = builder.end('response')
    
    xml_str = ET.tostring(xml, encoding="utf8")
    response = Response(xml_str, status=500, content_type='text/xml')
    return response.send(request._start_response)
开发者ID:nikolaijivkov,项目名称:Cndep_Rest_Service__iDigi_Dia,代码行数:17,代码来源:cndep_rest.py

示例3: image2svg

# 需要导入模块: from etree import ElementTree [as 别名]
# 或者: from etree.ElementTree import tostring [as 别名]
def image2svg(im_path, embed_image=True):
    ### Only part of the code that uses PIL ######
    im = Image.open(im_path)
    width, height = im.size
    fmt = im.format.lower()
    ### End of PIL ###############################

    if embed_image:
        f = open(im_path, 'rb')
        im_contents = f.read()
        f.close()
        b64 = base64.b64encode(im_contents)
        #im_href = "data:image/" + fmt + ";base64," + base64.b64encode(im_contents)
        im_href = "data:image/{0};base64,{1}".format(fmt, b64)
    else:
        im_href = "file:" + urllib.pathname2url(im_path)

    ### SVG ###
    doc = etree.parse(blank_svg_path)
    svg = doc.getroot()
    svg.set('width', str(width))
    svg.set('height', str(height))
    svg.set('xmlns:xlink', "http://www.w3.org/1999/xlink")
    ### Use descriptive variables for the layers
    image_layer = svg[image_layer_index]
    shapes_layer = svg[shapes_layer_index]
    ### Create the 'image' element
    image = etree.SubElement(image_layer, 'image')
    image.set('x', '0')
    image.set('y', '0')
    image.set('height', str(height))
    image.set('width', str(width))
    image.set('xlink:href', im_href)  # encode base64
    ###
    svg_content = etree.tostring(svg)  # remove
    #### Very Ugly Hack Ahead !!!
    hack_head, hack_body = svg_content.split('\n', 1)
    hack_head = hack_head[:-1]
    hack_head = ''.join([hack_head, ' xmlns="http://www.w3.org/2000/svg">'])
    svg_content = '\n'.join([hack_head, hack_body])
    #### END HACK

    svg_b64 = "data:image/svg+xml;base64," + base64.b64encode(svg_content)

    return {'svg': svg_content,
            'svg_b64': svg_b64,
            'height': height,
            'width': width}
开发者ID:KuDeTa,项目名称:image-occlusion-2,代码行数:50,代码来源:svgutils.py


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