Example #1
0
def make_message(xml):
    msg = {'subject': '', 'to': '', 'txt': '', 'message': '', 'from': '', 'jid': '', 'name': '', 'resource': ''}
    if type(xml) == types.DictType:
        msg.update(xml)
        return msg
    et = ET.XMLID(xml)
    msg.update(et[0].items())
    xml = ET.XML(xml)
    msg['message'] = unicode(xml.findtext('body'))
    msg['name'] = msg['from'].split('@')[0]
    msg['resource'] = msg['from'].split('/')[1]
    msg['jid'] = msg['from'].split('/')[0]
    return msg
Example #2
0
def make_presence(xml):
    pres = {'subject': '', 'to': '', 'message': '', 'name': '', 'resource': '', 'jid': ''}
    if type(xml) == types.DictType:
        pres.update(xml)
        return pres
    et = ET.XMLID(xml)
    pres.update(et[0].items())
    xml = ET.XML(xml)
    try:
        pres['name'] = pres['from'].split('@')[0]
        pres['resource'] = pres['from'].split('/')[1]
        pres['jid'] = pres['from'].split('/')[0]
    except KeyError:
        pass
    return pres
Example #3
0
    <filter id='MyFilter' filterUnits='objectBoundingBox' x='0' y='0' width='1' height='1'>
      <feGaussianBlur in='SourceAlpha' stdDeviation='4%' result='blur'/>
      <feOffset in='blur' dx='4%' dy='4%' result='offsetBlur'/>
      <feSpecularLighting in='blur' surfaceScale='5' specularConstant='.75' 
           specularExponent='20' lighting-color='#bbbbbb' result='specOut'>
        <fePointLight x='-5000%' y='-10000%' z='20000%'/>
      </feSpecularLighting>
      <feComposite in='specOut' in2='SourceAlpha' operator='in' result='specOut'/>
      <feComposite in='SourceGraphic' in2='specOut' operator='arithmetic' 
    k1='0' k2='1' k3='1' k4='0'/>
    </filter>
  </defs>
"""


tree, xmlid = ET.XMLID(f.getvalue())

# insert the filter definition in the svg dom tree.
tree.insert(0, ET.XML(filter_def))

for i, pie_name in enumerate(labels):
    pie = xmlid[pie_name]
    pie.set("filter", 'url(#MyFilter)')

    shadow = xmlid[pie_name + "_shadow"]
    shadow.set("filter",'url(#dropshadow)')

fn = "svg_filter_pie.svg"
print("Saving '%s'" % fn)
ET.ElementTree(tree).write(fn)
Example #4
0
def plot_mix_method():
    '''
    这种方法是混合方法,使用外部的SVG。
    '''
    import matplotlib
    matplotlib.use("Svg")
    import matplotlib.pyplot as plt
    from matplotlib.patches import Shadow
    fig1 = plt.figure(1, figsize=(6, 6))
    ax = fig1.add_axes([0.1, 0.1, 0.8, 0.8])
    labels = ['Frogs', 'Hogs', 'Dogs', 'Logs']
    fracs = [15, 30, 45, 10]  # 百分比
    explode = (0, 0.05, 0, 0)
    pies = ax.pie(fracs, explode=explode, labels=labels, autopct='%1.1f%%')
    for w in pies[0]:
        # set the id with the label.
        w.set_gid(w.get_label())
        # we don't want to draw the edge of the pie
        w.set_ec("none")
    for w in pies[0]:
        # create shadow patch
        s = Shadow(w, -0.01, -0.01)
        s.set_gid(w.get_gid() + "_shadow")
        s.set_zorder(w.get_zorder() - 0.1)
        ax.add_patch(s)
    # save
    from io import BytesIO
    f = BytesIO()
    plt.savefig(f, format="svg")
    import xml.etree.cElementTree as ET
    # filter definition for shadow using a gaussian blur
    # and lightening effect.
    # The lightening filter is copied from http://www.w3.org/TR/SVG/filters.html
    # I tested it with Inkscape and Firefox3. "Gaussian blur" is supported
    # in both, but the lightening effect only in the Inkscape. Also note
    # that, Inkscape's exporting also may not support it.
    filter_def = """
      <defs  xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink'>
        <filter id='dropshadow' height='1.2' width='1.2'>
          <feGaussianBlur result='blur' stdDeviation='2'/>
        </filter>

        <filter id='MyFilter' filterUnits='objectBoundingBox' x='0' y='0' width='1' height='1'>
          <feGaussianBlur in='SourceAlpha' stdDeviation='4%' result='blur'/>
          <feOffset in='blur' dx='4%' dy='4%' result='offsetBlur'/>
          <feSpecularLighting in='blur' surfaceScale='5' specularConstant='.75'
               specularExponent='20' lighting-color='#bbbbbb' result='specOut'>
            <fePointLight x='-5000%' y='-10000%' z='20000%'/>
          </feSpecularLighting>
          <feComposite in='specOut' in2='SourceAlpha' operator='in' result='specOut'/>
          <feComposite in='SourceGraphic' in2='specOut' operator='arithmetic'
        k1='0' k2='1' k3='1' k4='0'/>
        </filter>
      </defs>
    """
    tree, xmlid = ET.XMLID(f.getvalue())
    # insert the filter definition in the svg dom tree.
    tree.insert(0, ET.XML(filter_def))
    for i, pie_name in enumerate(labels):
        pie = xmlid[pie_name]
        pie.set("filter", 'url(#MyFilter)')
        shadow = xmlid[pie_name + "_shadow"]
        shadow.set("filter", 'url(#dropshadow)')
    fn = "svg_filter_pie.svg"
    print("Saving '%s'" % fn)
    ET.ElementTree(tree).write(fn)
Example #5
0
#! /usr/bin/env python

import pprint
import sys
import xml.etree.cElementTree as xmlet
'''
e is an element instance
'''

e = xmlet.Comment('Hello World')
ea = xmlet.Element('sampletag', {'a': 'hello'}, b='world')
es = xmlet.fromstring('<this ought="to" be="parsed" by="this">call</this>')
ex = xmlet.XML('<this ought="to" be="parsed" by="this">call</this>')
ei, ed = xmlet.XMLID('<this ought="to" be="parsed" by="this">call</this>')
if xmlet.iselement(es):
    print "fromstring() successfully created the element"
xmlet.dump(e)
xmlet.dump(ea)
xmlet.dump(es)
xmlet.dump(ex)
xmlet.dump(ei)

ET = xmlet.parse('wav.xml')
et = ET.getroot()

if e:
    xmlet.dump(e)