~ubuntu-branches/ubuntu/utopic/gozerbot/utopic

« back to all changes in this revision

Viewing changes to build/lib/gozerbot/utils/xmpp.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Malcolm
  • Date: 2012-04-03 21:58:28 UTC
  • mfrom: (3.1.11 sid)
  • Revision ID: package-import@ubuntu.com-20120403215828-6mik0tzug5na93la
Tags: 0.99.1-2
* Removes logfiles on purge (Closes: #668767)
* Reverted location of installed files back to /usr/lib/gozerbot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# gozerbot/utils/xmpp.py
 
2
#
 
3
#
 
4
 
 
5
from xml.etree import cElementTree as ET
 
6
import types
 
7
 
 
8
def make_presence(xml):
 
9
    pres = {'subject': '', 'to': '', 'message': '', 'name': '', 'resource': '', 'jid': ''}
 
10
    if type(xml) == types.DictType:
 
11
        pres.update(xml)
 
12
        return pres
 
13
    et = ET.XMLID(xml)
 
14
    pres.update(et[0].items())
 
15
    xml = ET.XML(xml)
 
16
    try:
 
17
        pres['name'] = pres['from'].split('@')[0]
 
18
        pres['resource'] = pres['from'].split('/')[1]
 
19
        pres['jid'] = pres['from'].split('/')[0]
 
20
    except KeyError:
 
21
        pass
 
22
    return pres
 
23
 
 
24
def make_message(xml):
 
25
    msg = {'subject': '', 'to': '', 'txt': '', 'message': '', 'from': '', 'jid': '', 'name': '', 'resource': ''}
 
26
    if type(xml) == types.DictType:
 
27
        msg.update(xml)
 
28
        return msg
 
29
    et = ET.XMLID(xml)
 
30
    msg.update(et[0].items())
 
31
    xml = ET.XML(xml)
 
32
    msg['message'] = unicode(xml.findtext('body'))
 
33
    msg['name'] = msg['from'].split('@')[0]
 
34
    msg['resource'] = msg['from'].split('/')[1]
 
35
    msg['jid'] = msg['from'].split('/')[0]
 
36
    return msg