Back to index

moin  1.9.0~rc2
Functions | Variables
jabberbot.capat Namespace Reference

Functions

def generate_ver
def hash_iq
def create_presence
def create_response

Variables

dictionary HASHALIASES
tuple IDENT
tuple FEAT
string NODE = "http://moinmo.in/#1.7"

Function Documentation

Creates a presence stanza (as described in XEP-0115)

@param jid: bot's jabber ID

Definition at line 94 of file capat.py.

00094 
00095 def create_presence(jid):
00096     """ Creates a presence stanza (as described in XEP-0115)
00097 
00098     @param jid: bot's jabber ID
00099     """
00100     pres = Presence(from_jid=jid)
00101 
00102     c = pres.add_new_content('http://jabber.org/protocol/caps', 'c')
00103     c.setProp('node', NODE)
00104 
00105     ver = generate_ver(IDENT, FEAT)
00106     c.setProp('ver', ver)
00107 
00108     return pres

Here is the call graph for this function:

def jabberbot.capat.create_response (   disco_query)
Creates an <Iq /> tag as a response to a service discovery query

@param disco_query: received query

Definition at line 109 of file capat.py.

00109 
00110 def create_response(disco_query):
00111     """ Creates an <Iq /> tag as a response to a service discovery query
00112 
00113     @param disco_query: received query
00114     """
00115     response = disco_query.make_result_response()
00116     query = response.new_query(ns_uri='http://jabber.org/protocol/disco#info')
00117 
00118     ident = query.newChild(None, 'identity', None)
00119     for item in IDENT:
00120         ident.setProp(item[0], item[1])
00121 
00122     for item in FEAT:
00123         query.newChild(None, 'feature', None).setProp('var', item)
00124 
00125     return response
00126 
def jabberbot.capat.generate_ver (   identities,
  features,
  algo = 'sha-1' 
)
Generate the 'ver' attribute according to XEP-0115.

See http://www.xmpp.org/extensions/xep-0115.html#ver

@param identities: a number of (category, type) identity pairs
@param algo: optional algo attribute with IANA aliasing

@type identities: iterable of 2-tuples of strings
@type features: iterable of strings
@type algo: string (IANA Hash Function Textual Name)

Definition at line 32 of file capat.py.

00032 
00033 def generate_ver(identities, features, algo='sha-1'):
00034     """Generate the 'ver' attribute according to XEP-0115.
00035 
00036     See http://www.xmpp.org/extensions/xep-0115.html#ver
00037 
00038     @param identities: a number of (category, type) identity pairs
00039     @param algo: optional algo attribute with IANA aliasing
00040 
00041     @type identities: iterable of 2-tuples of strings
00042     @type features: iterable of strings
00043     @type algo: string (IANA Hash Function Textual Name)
00044     """
00045 
00046     # only IANA aliases are supported
00047     if algo not in HASHALIASES:
00048         raise ValueError("undefined hash algorithm")
00049     algo = hash_new(HASHALIASES[algo])
00050 
00051     ident = list(identities)
00052     # default sorting already considers both, category and type
00053     ident.sort()
00054     ident = ['%s/%s' % (idcat, idtype) for idcat, idtype in ident]
00055 
00056     feat = list(features)
00057     # strings (byte arrays) are ordered by i;octet by default
00058     feat.sort()
00059 
00060     s = '<'.join(itertools.chain(ident, feat, ('', )))
00061     # the trailing empty string adds a trailing '<' to the result
00062     algo.update(s)
00063     s = base64.b64encode(algo.digest())
00064 
00065     return s

Here is the caller graph for this function:

def jabberbot.capat.hash_iq (   stanza,
  algo = 'sha-1' 
)
Search an <Iq/> entity for features/identities and generate a
'ver' attribute hash.

@type stanza: pyxmpp.iq.Iq

Definition at line 66 of file capat.py.

00066 
00067 def hash_iq(stanza, algo='sha-1'):
00068     """Search an <Iq/> entity for features/identities and generate a
00069     'ver' attribute hash.
00070 
00071     @type stanza: pyxmpp.iq.Iq
00072     """
00073     stanza = iter(stanza.get_query())
00074     stanza.next() # drop first item: whole query
00075 
00076     feat = []
00077     ident = []
00078 
00079     # traverse all child nodes
00080     for item in stanza:
00081         if item.name == 'identity':
00082             ident.append((item.prop('category'), item.prop('type')))
00083         elif item.name == 'feature':
00084             feat.append(item.prop('var'))
00085 
00086     return generate_ver(ident, feat, algo)
00087 
# <identity /> and <feature /> attributes

Here is the call graph for this function:


Variable Documentation

Initial value:
00001 ('http://jabber.org/protocol/disco#info',
00002         'jabber:x:data')

Definition at line 90 of file capat.py.

Initial value:
00001 { # IANA Hash Function Textual Names Registry
00002                 # to `hashlib.new` mapping
00003     'sha-1': 'sha1',
00004     'sha-224': 'sha224',
00005     'sha-256': 'sha256',
00006     'sha-384': 'sha384',
00007     'sha-512': 'sha512',
00008     'md5': 'md5',
00009     'md2': 'md2',
00010 }

Definition at line 20 of file capat.py.

Initial value:
00001 (('category', 'client'),
00002          ('type', 'bot'))

Definition at line 88 of file capat.py.

string jabberbot.capat.NODE = "http://moinmo.in/#1.7"

Definition at line 92 of file capat.py.