def __init__( self, name=None, to=None, typ=None, frm=None, attrs=None, payload=None, timestamp=None, xmlns=None, node=None ): """ 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 stamped over stanza xmlns - namespace of top stanza node node - parsed or unparsed stana to be taken as prototype. """ if attrs is None: 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) to = self.getAttr("to") if to: self.setTo(to) frm = self.getAttr("from") if frm: self.setFrom(frm) if timestamp is not None: self.setTimestamp(timestamp)
def __init__(self, typ=None, data=[], title=None, node=None): """ Create new dataform of type 'typ'. 'data' is the list of DataField instances that this dataform contains, 'title' - 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 SHOULD NOT contain newlines. Several instructions MAY be present. 'typ' can be one of ('form' | 'submit' | 'cancel' | 'result' ) 'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' ) respectively. 'cancel' form can not contain any fields. All other forms contains AT LEAST one field. 'title' MAY be included in forms of type "form" and "result" """ Node.__init__(self,'x',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 if typ: self.setType(typ) self.setNamespace(NS_DATA) if title: self.setTitle(title) if type(data)==type({}): newdata=[] for name in data.keys(): newdata.append(DataField(name,data[name])) data=newdata for child in data: if type(child) in [type(''),type(u'')]: self.addInstructions(child) elif child.__class__.__name__=='DataField': self.kids.append(child) else: self.kids.append(DataField(node=child))
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns=NS_CLIENT, 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: self.setNamespace(xmlns) if self['to']: self.setTo(self['to']) if self['from']: self.setFrom(self['from']) if node and type(self) == type( node ) and self.__class__ == node.__class__ and self.attrs.has_key('id'): del self.attrs['id'] self.timestamp = None for x in self.getTags('x', namespace=NS_DELAY): try: if x.getAttr('stamp') > self.getTimestamp(): self.setTimestamp(x.getAttr('stamp')) except: pass if timestamp is not None: self.setTimestamp( timestamp) # To auto-timestamp stanza just pass timestamp=''
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns=None, node=None): """ 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 stamped over stanza xmlns - namespace of top stanza node node - parsed or unparsed stana to be taken as prototype. """ 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']: self.setTo(self['to']) if self['from']: self.setFrom(self['from']) if node and isinstance(self, type(node)) and self.__class__==node.__class__ and 'id' in self.attrs: del self.attrs['id'] self.timestamp=None for d in self.getTags('delay',namespace=NS_DELAY2): try: if d.getAttr('stamp')<self.getTimestamp2(): self.setTimestamp(d.getAttr('stamp')) except: pass if not self.timestamp: for x in self.getTags('x',namespace=NS_DELAY): try: if x.getAttr('stamp')<self.getTimestamp(): self.setTimestamp(x.getAttr('stamp')) except: pass if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''
def __init__(self, name=None, value=None, typ=None, required=0, label=None, desc=None, options=None, node=None): """ 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. """ if options is None: options = [] 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 required: self.setRequired(required) if label: self.setLabel(label) if desc: self.setDesc(desc) if options: self.setOptions(options)
def __init__(self, typ=None, data=[], title=None, node=None): """ Create new dataform of type 'typ'. 'data' is the list of DataField instances that this dataform contains, 'title' - 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 SHOULD NOT contain newlines. Several instructions MAY be present. 'typ' can be one of ('form' | 'submit' | 'cancel' | 'result' ) 'typ' of reply iq can be ( 'result' | 'set' | 'set' | 'result' ) respectively. 'cancel' form can not contain any fields. All other forms contains AT LEAST one field. 'title' MAY be included in forms of type "form" and "result" """ Node.__init__(self, 'x', 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 if typ: self.setType(typ) self.setNamespace(NS_DATA) if title: self.setTitle(title) if isinstance(data, dict): newdata = [] for name in data.keys(): newdata.append(DataField(name, data[name])) data = newdata for child in data: if isinstance(child, basestring): self.addInstructions(child) elif child.__class__.__name__ == 'DataField': self.kids.append(child) else: self.kids.append(DataField(node=child))
def __init__(self, typ=None, data=[], title=None, node=None): """ title and instructions: optional. SHOULD NOT contain newlines. Several instructions MAY be present. type={ form | submit | cancel | result } # iq: { result | set | set | result } 'cancel' form contains no fields. Other forms contains AT LEAST one field. title MAY be included in forms of type "form|result" """ Node.__init__(self, 'x', 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 if typ: self.setType(typ) self.setNamespace(NS_DATA) if title: self.setTitle(title) if type(data) == type({}): newdata = [] for name in data.keys(): newdata.append(DataField(name, data[name])) data = newdata for child in data: if type(child) in [type(''), type(u'')]: self.addInstructions(child) elif child.__class__.__name__ == 'DataField': self.kids.append(child) else: self.kids.append(DataField(node=child))
def __init__(self, name=None, to=None, typ=None, frm=None, attrs=None, xmlns=NS_CLIENT, node=None): """ 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 xmlns - namespace of top stanza node node - parsed or unparsed stana to be taken as prototype. """ if not attrs: attrs = {} if to: attrs["to"] = to if frm: attrs["from"] = frm if typ: attrs["type"] = typ Node.__init__(self, name=name, attrs=attrs, node=node) if xmlns and not node: self.setXMLNS(xmlns) to = self.getAttr("to") if to: self.setTo(to) frm = self.getAttr("from") if frm: self.setFrom(frm)
def __init__(self,data=None,node=None): Node.__init__(self,'x',node=node) self.setNamespace(NS_DATA) dict={} if type(data) in [type(()),type([])]: for i in data: dict[i]='' elif data: dict=data for key in dict.keys(): self.setField(key,dict[key])
def __init__(self, data=None, node=None): Node.__init__(self, 'x', node=node) self.setNamespace(NS_DATA) dict = {} if type(data) in [type(()), type([])]: for i in data: dict[i] = '' elif data: dict = data for key in dict.keys(): self.setField(key, dict[key])
def __init__(self, node=None): """ 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. """ 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
def __init__(self,name,code=None,typ=None,text=None): """ Mandatory parameter: name Optional parameters: code, typ, text.""" if ERRORS.has_key(name): cod,type,txt=ERRORS[name] else: cod,type,txt='','cancel','' if typ: type=typ if code: cod=code if text: txt=text Node.__init__(self,'error',{'type':type},[Node(NS_STANZAS+' '+name)]) if txt: self.addChild(node=Node(NS_STANZAS+' text',{},[txt])) self.addData(txt) if cod: self.setAttr('code',cod)
def __init__(self,node=None): """ 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. """ 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
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=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 node and type(self)==type(node) and self.__class__==node.__class__ and self.attrs.has_key('id'): del self.attrs['id'] self.timestamp=None for x in self.getTags('x',namespace=NS_DELAY): try: if x.getAttr('stamp')>self.getTimestamp(): self.setTimestamp(x.getAttr('stamp')) except: pass if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''
def __init__(self, name, code=None, typ=None, text=None): """ Mandatory parameter: name Optional parameters: code, typ, text.""" if ERRORS.has_key(name): cod, type, txt = ERRORS[name] else: cod, type, txt = '', 'cancel', '' if typ: type = typ if code: cod = code if text: txt = text Node.__init__(self, 'error', {'type': type}, [Node(NS_STANZAS + ' ' + name)]) if txt: self.addChild(node=Node(NS_STANZAS + ' text', {}, [txt])) self.addData(txt) if cod: self.setAttr('code', cod)
def __init__(self,name=None,value=None,typ=None,required=0,desc=None,options=[],node=None): """ 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. """ Node.__init__(self,'field',node=node) if name: self.setVar(name) if isinstance(value, (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 required: self.setRequired(required) if desc: self.setDesc(desc) if options: self.setOptions(options)
def __init__(self, node=None): """ 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 object can be passed in as the 'node' parameted to replicate it as a new dataitem. """ 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
def __init__(self,node=None): """ 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 object can be passed in as the 'node' parameted to replicate it as a new dataitem. """ 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
def __init__(self, name, code=None, typ=None, text=None): """ Mandatory parameter: name Optional parameters: code, typ, text.""" 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)]) if type: self.setAttr('type', type) if not cod: self.setName('stream:error') if txt: self.addChild(node=Node(ns + ' text', {}, [txt])) if cod: self.setAttr('code', cod)
def __init__(self,name,code=None,typ=None,text=None): """ 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.""" 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)]) if type: self.setAttr('type',type) if not cod: self.setName('stream:error') if txt: self.addChild(node=Node(ns+' text',{},[txt])) if cod: self.setAttr('code',cod)
def __init__(self, name=None, to=None, typ=None, frm=None, attrs={}, payload=[], timestamp=None, xmlns=None, node=None): """ 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 stamped over stanza xmlns - namespace of top stanza node node - parsed or unparsed stana to be taken as prototype. """ 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']: self.setTo(self['to']) if self['from']: self.setFrom(self['from']) if node and isinstance( self, type(node) ) and self.__class__ == node.__class__ and 'id' in self.attrs: del self.attrs['id'] self.timestamp = None for d in self.getTags('delay', namespace=NS_DELAY2): try: if d.getAttr('stamp') < self.getTimestamp2(): self.setTimestamp(d.getAttr('stamp')) except: pass if not self.timestamp: for x in self.getTags('x', namespace=NS_DELAY): try: if x.getAttr('stamp') < self.getTimestamp(): self.setTimestamp(x.getAttr('stamp')) except: pass if timestamp is not None: self.setTimestamp( timestamp) # To auto-timestamp stanza just pass timestamp=''
def __init__(self, name=None, value=None, typ=None, required=0, 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 required: self.setRequired(required) if desc: self.setDesc(desc) if options: self.setOptions(options)
def __init__(self, name, code=None, typ=None, text=None): """ 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.""" 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)]) if type: self.setAttr('type', type) if not cod: self.setName('stream:error') if txt: self.addChild(node=Node(ns + ' text', {}, [txt])) if cod: self.setAttr('code', cod)
def __init__(self, name=None, value=None, typ=None, required=0, desc=None, options=[], node=None): """ 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. """ 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 required: self.setRequired(required) if desc: self.setDesc(desc) if options: self.setOptions(options)
def __init__( self, name=None, to=None, typ=None, frm=None, attrs=None, payload=None, timestamp=None, xmlns=None, node=None ): """ 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 stamped over stanza xmlns - namespace of top stanza node node - parsed or unparsed stana to be taken as prototype. """ if attrs is None: attrs = {} if payload is None: payload = [] 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"]: self.setTo(self["to"]) if self["from"]: self.setFrom(self["from"]) if node and type(self) == type(node) and self.__class__ == node.__class__ and self.attrs.has_key("id"): del self.attrs["id"] self.timestamp = None for x in self.getTags("x", namespace=NS_DELAY): try: if not self.getTimestamp() or x.getAttr("stamp") < self.getTimestamp(): self.setTimestamp(x.getAttr("stamp")) except: pass if timestamp is not None: self.setTimestamp(timestamp) # To auto-timestamp stanza just pass timestamp=''