本文整理匯總了Python中simplexml.Node.__init__方法的典型用法代碼示例。如果您正苦於以下問題:Python Node.__init__方法的具體用法?Python Node.__init__怎麽用?Python Node.__init__使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類simplexml.Node
的用法示例。
在下文中一共展示了Node.__init__方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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=''
示例2: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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))
示例3: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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)
示例4: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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)
示例5: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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])
示例6: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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
示例7: __init__
# 需要導入模塊: from simplexml import Node [as 別名]
# 或者: from simplexml.Node import __init__ [as 別名]
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)