desc stringlengths 3 26.7k | decl stringlengths 11 7.89k | bodies stringlengths 8 553k |
|---|---|---|
'Return the Roster instance, previously plugging it in and
requesting roster from server if needed.'
| def getRoster(self):
| if (not self.__dict__.has_key('Roster')):
roster.Roster().PlugIn(self)
return self.Roster.getRoster()
|
'Send roster request and initial <presence/>.
You can disable the first by setting requestRoster argument to 0.'
| def sendInitPresence(self, requestRoster=1):
| self.sendPresence(requestRoster=requestRoster)
|
'Send some specific presence state.
Can also request roster from server if according agrument is set.'
| def sendPresence(self, jid=None, typ=None, requestRoster=0):
| if requestRoster:
roster.Roster().PlugIn(self)
self.send(dispatcher.Presence(to=jid, typ=typ))
|
'Init function for Components.
As components use a different auth mechanism which includes the namespace of the component.
Jabberd1.4 and Ejabberd use the default namespace then for all client messages.
Jabberd2 uses jabber:client.
\'transport\' argument is a transport name that you are going to serve (f.e. "irc.localh... | def __init__(self, transport, port=5347, typ=None, debug=['always', 'nodebuilder'], domains=None, sasl=0, bind=0, route=0, xcp=0):
| CommonClient.__init__(self, transport, port=port, debug=debug)
self.typ = typ
self.sasl = sasl
self.bind = bind
self.route = route
self.xcp = xcp
if domains:
self.domains = domains
else:
self.domains = [transport]
|
'This will connect to the server, and if the features tag is found then set
the namespace to be jabber:client as that is required for jabberd2.
\'server\' and \'proxy\' arguments have the same meaning as in xmpp.Client.connect()'
| def connect(self, server=None, proxy=None):
| if self.sasl:
self.Namespace = auth.NS_COMPONENT_1
self.Server = server[0]
CommonClient.connect(self, server=server, proxy=proxy)
if (self.connected and ((self.typ == 'jabberd2') or ((not self.typ) and (self.Dispatcher.Stream.features != None))) and (not self.xcp)):
self.defaultNames... |
'Authenticate component "name" with password "password".'
| def auth(self, name, password, dup=None):
| (self._User, self._Password, self._Resource) = (name, password, '')
try:
if self.sasl:
auth.SASL(name, password).PlugIn(self)
if ((not self.sasl) or (self.SASL.startsasl == 'not-supported')):
if auth.NonSASL(name, password, '').PlugIn(self):
self.dobind(sa... |
'Constructor. JID can be specified as string (jid argument) or as separate parts.
Examples:
JID(\'node@domain/resource\')
JID(node=\'node\',domain=\'domain.org\')'
| def __init__(self, jid=None, node='', domain='', resource=''):
| if ((not jid) and (not domain)):
raise ValueError('JID must contain at least domain name')
elif (type(jid) == type(self)):
(self.node, self.domain, self.resource) = (jid.node, jid.domain, jid.resource)
elif domain:
(self.node, self.domain, self.resource) = (node, do... |
'Return the node part of the JID'
| def getNode(self):
| return self.node
|
'Set the node part of the JID to new value. Specify None to remove the node part.'
| def setNode(self, node):
| self.node = node.lower()
|
'Return the domain part of the JID'
| def getDomain(self):
| return self.domain
|
'Set the domain part of the JID to new value.'
| def setDomain(self, domain):
| self.domain = domain.lower()
|
'Return the resource part of the JID'
| def getResource(self):
| return self.resource
|
'Set the resource part of the JID to new value. Specify None to remove the resource part.'
| def setResource(self, resource):
| self.resource = resource
|
'Return the bare representation of JID. I.e. string value w/o resource.'
| def getStripped(self):
| return self.__str__(0)
|
'Compare the JID to another instance or to string for equality.'
| def __eq__(self, other):
| try:
other = JID(other)
except ValueError:
return 0
return ((self.resource == other.resource) and (self.__str__(0) == other.__str__(0)))
|
'Compare the JID to another instance or to string for non-equality.'
| def __ne__(self, other):
| return (not self.__eq__(other))
|
'Compare the node and domain parts of the JID\'s for equality.'
| def bareMatch(self, other):
| return (self.__str__(0) == JID(other).__str__(0))
|
'Serialise JID into string.'
| def __str__(self, wresource=1):
| if self.node:
jid = ((self.node + '@') + self.domain)
else:
jid = self.domain
if (wresource and self.resource):
return ((jid + '/') + self.resource)
return jid
|
'Produce hash of the JID, Allows to use JID objects as keys of the dictionary.'
| def __hash__(self):
| return hash(self.__str__())
|
'Constructor, name is the name of the stanza i.e. \'message\' or \'presence\' or \'iq\'.
to is the value of \'to\' attribure, \'typ\' - \'type\' attribute
frn - from attribure, attrs - other attributes mapping, payload - same meaning as for simplexml payload definition
timestamp - the time value that needs to be stampe... | def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns=None, node=None):
| if (not attrs):
attrs = {}
if to:
attrs['to'] = to
if frm:
attrs['from'] = frm
if typ:
attrs['type'] = typ
Node.__init__(self, tag=name, attrs=attrs, payload=payload, node=node)
if ((not node) and xmlns):
self.setNamespace(xmlns)
if self['to']:
... |
'Return value of the \'to\' attribute.'
| def getTo(self):
| try:
return self['to']
except:
return None
|
'Return value of the \'from\' attribute.'
| def getFrom(self):
| try:
return self['from']
except:
return None
|
'Return the timestamp in the \'yyyymmddThhmmss\' format.'
| def getTimestamp(self):
| return self.timestamp
|
'Return the value of the \'id\' attribute.'
| def getID(self):
| return self.getAttr('id')
|
'Set the value of the \'to\' attribute.'
| def setTo(self, val):
| self.setAttr('to', JID(val))
|
'Return the value of the \'type\' attribute.'
| def getType(self):
| return self.getAttr('type')
|
'Set the value of the \'from\' attribute.'
| def setFrom(self, val):
| self.setAttr('from', JID(val))
|
'Set the value of the \'type\' attribute.'
| def setType(self, val):
| self.setAttr('type', val)
|
'Set the value of the \'id\' attribute.'
| def setID(self, val):
| self.setAttr('id', val)
|
'Return the error-condition (if present) or the textual description of the error (otherwise).'
| def getError(self):
| errtag = self.getTag('error')
if errtag:
for tag in errtag.getChildren():
if (tag.getName() != 'text'):
return tag.getName()
return errtag.getData()
|
'Return the error code. Obsolette.'
| def getErrorCode(self):
| return self.getTagAttr('error', 'code')
|
'Set the error code. Obsolette. Use error-conditions instead.'
| def setError(self, error, code=None):
| if code:
if (str(code) in _errorcodes.keys()):
error = ErrorNode(_errorcodes[str(code)], text=error)
else:
error = ErrorNode(ERR_UNDEFINED_CONDITION, code=code, typ='cancel', text=error)
elif (type(error) in [type(''), type(u'')]):
error = ErrorNode(error)
sel... |
'Set the timestamp. timestamp should be the yyyymmddThhmmss string.'
| def setTimestamp(self, val=None):
| if (not val):
val = time.strftime('%Y%m%dT%H:%M:%S', time.gmtime())
self.timestamp = val
self.setTag('x', {'stamp': self.timestamp}, namespace=NS_DELAY)
|
'Return the list of namespaces to which belongs the direct childs of element'
| def getProperties(self):
| props = []
for child in self.getChildren():
prop = child.getNamespace()
if (prop not in props):
props.append(prop)
return props
|
'Set the item \'item\' to the value \'val\'.'
| def __setitem__(self, item, val):
| if (item in ['to', 'from']):
val = JID(val)
return self.setAttr(item, val)
|
'Create message object. You can specify recipient, text of message, type of message
any additional attributes, sender of the message, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
Alternatively you can pass in the other XML object as the \'node\' parameted to replicate it as message.'
| def __init__(self, to=None, body=None, typ=None, subject=None, attrs={}, frm=None, payload=[], timestamp=None, xmlns=NS_CLIENT, node=None):
| Protocol.__init__(self, 'message', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
if body:
self.setBody(body)
if subject:
self.setSubject(subject)
|
'Returns text of the message.'
| def getBody(self):
| return self.getTagData('body')
|
'Returns subject of the message.'
| def getSubject(self):
| return self.getTagData('subject')
|
'Returns thread of the message.'
| def getThread(self):
| return self.getTagData('thread')
|
'Sets the text of the message.'
| def setBody(self, val):
| self.setTagData('body', val)
|
'Sets the subject of the message.'
| def setSubject(self, val):
| self.setTagData('subject', val)
|
'Sets the thread of the message.'
| def setThread(self, val):
| self.setTagData('thread', val)
|
'Builds and returns another message object with specified text.
The to, from and thread properties of new message are pre-set as reply to this message.'
| def buildReply(self, text=None):
| m = Message(to=self.getFrom(), frm=self.getTo(), body=text)
th = self.getThread()
if th:
m.setThread(th)
return m
|
'Create presence object. You can specify recipient, type of message, priority, show and status values
any additional attributes, sender of the presence, timestamp, any additional payload (f.e. jabber:x:delay element) and namespace in one go.
Alternatively you can pass in the other XML object as the \'node\' parameted t... | def __init__(self, to=None, typ=None, priority=None, show=None, status=None, attrs={}, frm=None, timestamp=None, payload=[], xmlns=NS_CLIENT, node=None):
| Protocol.__init__(self, 'presence', to=to, typ=typ, attrs=attrs, frm=frm, payload=payload, timestamp=timestamp, xmlns=xmlns, node=node)
if priority:
self.setPriority(priority)
if show:
self.setShow(show)
if status:
self.setStatus(status)
|
'Returns the priority of the message.'
| def getPriority(self):
| return self.getTagData('priority')
|
'Returns the show value of the message.'
| def getShow(self):
| return self.getTagData('show')
|
'Returns the status string of the message.'
| def getStatus(self):
| return self.getTagData('status')
|
'Sets the priority of the message.'
| def setPriority(self, val):
| self.setTagData('priority', val)
|
'Sets the show value of the message.'
| def setShow(self, val):
| self.setTagData('show', val)
|
'Sets the status string of the message.'
| def setStatus(self, val):
| self.setTagData('status', val)
|
'Returns the presence role (for groupchat)'
| def getRole(self):
| return self._muc_getItemAttr('item', 'role')
|
'Returns the presence affiliation (for groupchat)'
| def getAffiliation(self):
| return self._muc_getItemAttr('item', 'affiliation')
|
'Returns the nick value (for nick change in groupchat)'
| def getNick(self):
| return self._muc_getItemAttr('item', 'nick')
|
'Returns the presence jid (for groupchat)'
| def getJid(self):
| return self._muc_getItemAttr('item', 'jid')
|
'Returns the reason of the presence (for groupchat)'
| def getReason(self):
| return self._muc_getSubTagDataAttr('reason', '')[0]
|
'Returns the reason of the presence (for groupchat)'
| def getActor(self):
| return self._muc_getSubTagDataAttr('actor', 'jid')[1]
|
'Returns the status code of the presence (for groupchat)'
| def getStatusCode(self):
| return self._muc_getItemAttr('status', 'code')
|
'Create Iq object. You can specify type, query namespace
any additional attributes, recipient of the iq, sender of the iq, any additional payload (f.e. jabber:x:data node) and namespace in one go.
Alternatively you can pass in the other XML object as the \'node\' parameted to replicate it as an iq.'
| def __init__(self, typ=None, queryNS=None, attrs={}, to=None, frm=None, payload=[], xmlns=NS_CLIENT, node=None):
| Protocol.__init__(self, 'iq', to=to, typ=typ, attrs=attrs, frm=frm, xmlns=xmlns, node=node)
if payload:
self.setQueryPayload(payload)
if queryNS:
self.setQueryNS(queryNS)
|
'Return the namespace of the \'query\' child element.'
| def getQueryNS(self):
| tag = self.getTag('query')
if tag:
return tag.getNamespace()
|
'Return the \'node\' attribute value of the \'query\' child element.'
| def getQuerynode(self):
| return self.getTagAttr('query', 'node')
|
'Return the \'query\' child element payload.'
| def getQueryPayload(self):
| tag = self.getTag('query')
if tag:
return tag.getPayload()
|
'Return the \'query\' child element child nodes.'
| def getQueryChildren(self):
| tag = self.getTag('query')
if tag:
return tag.getChildren()
|
'Set the namespace of the \'query\' child element.'
| def setQueryNS(self, namespace):
| self.setTag('query').setNamespace(namespace)
|
'Set the \'query\' child element payload.'
| def setQueryPayload(self, payload):
| self.setTag('query').setPayload(payload)
|
'Set the \'node\' attribute value of the \'query\' child element.'
| def setQuerynode(self, node):
| self.setTagAttr('query', 'node', node)
|
'Builds and returns another Iq object of specified type.
The to, from and query child node of new Iq are pre-set as reply to this Iq.'
| def buildReply(self, typ):
| iq = Iq(typ, to=self.getFrom(), frm=self.getTo(), attrs={'id': self.getID()})
if self.getTag('query'):
iq.setQueryNS(self.getQueryNS())
return iq
|
'Create new error node object.
Mandatory parameter: name - name of error condition.
Optional parameters: code, typ, text. Used for backwards compartibility with older jabber protocol.'
| def __init__(self, name, code=None, typ=None, text=None):
| if ERRORS.has_key(name):
(cod, type, txt) = ERRORS[name]
ns = name.split()[0]
else:
(cod, ns, type, txt) = ('500', NS_STANZAS, 'cancel', '')
if typ:
type = typ
if code:
cod = code
if text:
txt = text
Node.__init__(self, 'error', {}, [Node(name)])
... |
'Create error reply basing on the received \'node\' stanza and the \'error\' error condition.
If the \'node\' is not the received stanza but locally created (\'to\' and \'from\' fields needs not swapping)
specify the \'reply\' argument as false.'
| def __init__(self, node, error, reply=1):
| if reply:
Protocol.__init__(self, to=node.getFrom(), frm=node.getTo(), node=node)
else:
Protocol.__init__(self, node=node)
self.setError(error)
if (node.getType() == 'error'):
self.__str__ = self.__dupstr__
|
'Dummy function used as preventor of creating error node in reply to error node.
I.e. you will not be able to serialise "double" error into string.'
| def __dupstr__(self, dup1=None, dup2=None):
| return ''
|
'Create new data field of specified name,value and type.
Also \'required\',\'desc\' and \'options\' fields can be set.
Alternatively other XML object can be passed in as the \'node\' parameted to replicate it as a new datafiled.'
| def __init__(self, name=None, value=None, typ=None, required=0, label=None, desc=None, options=[], node=None):
| Node.__init__(self, 'field', node=node)
if name:
self.setVar(name)
if (type(value) in [list, tuple]):
self.setValues(value)
elif value:
self.setValue(value)
if typ:
self.setType(typ)
elif ((not typ) and (not node)):
self.setType('text-single')
if requi... |
'Change the state of the \'required\' flag.'
| def setRequired(self, req=1):
| if req:
self.setTag('required')
else:
try:
self.delChild('required')
except ValueError:
return
|
'Returns in this field a required one.'
| def isRequired(self):
| return self.getTag('required')
|
'Set the label of this field.'
| def setLabel(self, label):
| self.setAttr('label', label)
|
'Return the label of this field.'
| def getLabel(self):
| return self.getAttr('label')
|
'Set the description of this field.'
| def setDesc(self, desc):
| self.setTagData('desc', desc)
|
'Return the description of this field.'
| def getDesc(self):
| return self.getTagData('desc')
|
'Set the value of this field.'
| def setValue(self, val):
| self.setTagData('value', val)
|
'Set the values of this field as values-list.
Replaces all previous filed values! If you need to just add a value - use addValue method.'
| def setValues(self, lst):
| while self.getTag('value'):
self.delChild('value')
for val in lst:
self.addValue(val)
|
'Add one more value to this field. Used in \'get\' iq\'s or such.'
| def addValue(self, val):
| self.addChild('value', {}, [val])
|
'Return the list of values associated with this field.'
| def getValues(self):
| ret = []
for tag in self.getTags('value'):
ret.append(tag.getData())
return ret
|
'Return label-option pairs list associated with this field.'
| def getOptions(self):
| ret = []
for tag in self.getTags('option'):
ret.append([tag.getAttr('label'), tag.getTagData('value')])
return ret
|
'Set label-option pairs list associated with this field.'
| def setOptions(self, lst):
| while self.getTag('option'):
self.delChild('option')
for opt in lst:
self.addOption(opt)
|
'Add one more label-option pair to this field.'
| def addOption(self, opt):
| if (type(opt) in [str, unicode]):
self.addChild('option').setTagData('value', opt)
else:
self.addChild('option', {'label': opt[0]}).setTagData('value', opt[1])
|
'Get type of this field.'
| def getType(self):
| return self.getAttr('type')
|
'Set type of this field.'
| def setType(self, val):
| return self.setAttr('type', val)
|
'Get \'var\' attribute value of this field.'
| def getVar(self):
| return self.getAttr('var')
|
'Set \'var\' attribute value of this field.'
| def setVar(self, val):
| return self.setAttr('var', val)
|
'Create new empty \'reported data\' field. However, note that, according XEP-0004:
* It MUST contain one or more DataFields.
* Contained DataFields SHOULD possess a \'type\' and \'label\' attribute in addition to \'var\' attribute
* Contained DataFields SHOULD NOT contain a <value/> element.
Alternatively other XML obj... | def __init__(self, node=None):
| Node.__init__(self, 'reported', node=node)
if node:
newkids = []
for n in self.getChildren():
if (n.getName() == 'field'):
newkids.append(DataField(node=n))
else:
newkids.append(n)
self.kids = newkids
|
'Return the datafield object with name \'name\' (if exists).'
| def getField(self, name):
| return self.getTag('field', attrs={'var': name})
|
'Create if nessessary or get the existing datafield object with name \'name\' and return it.
If created, attributes \'type\' and \'label\' are applied to new datafield.'
| def setField(self, name, typ=None, label=None):
| f = self.getField(name)
if f:
return f
return self.addChild(node=DataField(name, None, typ, 0, label))
|
'Represent dataitem as simple dictionary mapping of datafield names to their values.'
| def asDict(self):
| ret = {}
for field in self.getTags('field'):
name = field.getAttr('var')
typ = field.getType()
if (isinstance(typ, (str, unicode)) and (typ[(-6):] == '-multi')):
val = []
for i in field.getTags('value'):
val.append(i.getData())
else:
... |
'Simple dictionary interface for getting datafields values by their names.'
| def __getitem__(self, name):
| item = self.getField(name)
if item:
return item.getValue()
raise IndexError('No such field')
|
'Simple dictionary interface for setting datafields values by their names.'
| def __setitem__(self, name, val):
| return self.setField(name).setValue(val)
|
'Create new empty data item. However, note that, according XEP-0004, DataItem MUST contain ALL
DataFields described in DataReported.
Alternatively other XML object can be passed in as the \'node\' parameted to replicate it as a new
dataitem.'
| def __init__(self, node=None):
| Node.__init__(self, 'item', node=node)
if node:
newkids = []
for n in self.getChildren():
if (n.getName() == 'field'):
newkids.append(DataField(node=n))
else:
newkids.append(n)
self.kids = newkids
|
'Return the datafield object with name \'name\' (if exists).'
| def getField(self, name):
| return self.getTag('field', attrs={'var': name})
|
'Create if nessessary or get the existing datafield object with name \'name\' and return it.'
| def setField(self, name):
| f = self.getField(name)
if f:
return f
return self.addChild(node=DataField(name))
|
'Represent dataitem as simple dictionary mapping of datafield names to their values.'
| def asDict(self):
| ret = {}
for field in self.getTags('field'):
name = field.getAttr('var')
typ = field.getType()
if (isinstance(typ, (str, unicode)) and (typ[(-6):] == '-multi')):
val = []
for i in field.getTags('value'):
val.append(i.getData())
else:
... |
'Simple dictionary interface for getting datafields values by their names.'
| def __getitem__(self, name):
| item = self.getField(name)
if item:
return item.getValue()
raise IndexError('No such field')
|
'Simple dictionary interface for setting datafields values by their names.'
| def __setitem__(self, name, val):
| return self.setField(name).setValue(val)
|
'Create new dataform of type \'typ\'; \'data\' is the list of DataReported,
DataItem and DataField instances that this dataform contains; \'title\'
is the title string.
You can specify the \'node\' argument as the other node to be used as
base for constructing this dataform.
title and instructions is optional and SHOUL... | def __init__(self, typ=None, data=[], title=None, node=None):
| Node.__init__(self, 'x', node=node)
if node:
newkids = []
for n in self.getChildren():
if (n.getName() == 'field'):
newkids.append(DataField(node=n))
elif (n.getName() == 'item'):
newkids.append(DataItem(node=n))
elif (n.getName... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.