本文整理汇总了Python中twisted.words.xish.domish.Element.attributes["type"]方法的典型用法代码示例。如果您正苦于以下问题:Python Element.attributes["type"]方法的具体用法?Python Element.attributes["type"]怎么用?Python Element.attributes["type"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.xish.domish.Element
的用法示例。
在下文中一共展示了Element.attributes["type"]方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: incomingIq
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def incomingIq(self, el):
to = el.getAttribute("from")
ID = el.getAttribute("id")
ulang = utils.getLang(el)
if config.admins.count(internJID(to).userhost()) == 0:
self.pytrans.iq.sendIqError(to=to, fro=config.jid, ID=ID, xmlns=globals.COMMANDS, etype="cancel", condition="not-authorized")
return
self.sendProbes()
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
x = command.addElement("x")
x.attributes["xmlns"] = globals.XDATA
x.attributes["type"] = "result"
title = x.addElement("title")
title.addContent(lang.get("command_ConnectUsers", ulang))
field = x.addElement("field")
field.attributes["type"] = "fixed"
field.addElement("value").addContent(lang.get("command_Done", ulang))
self.pytrans.send(iq)
示例2: pwdChangeResults
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def pwdChangeResults(self, results, el, sessionid, newpassword):
to = el.getAttribute("from")
toj = internJID(to)
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
if sessionid:
command.attributes["sessionid"] = sessionid
else:
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["node"] = "changepassword"
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
note = command.addElement("note")
if results[3]:
note.attributes["type"] = "error"
note.addContent(lang.get("command_ChangePassword_Failed", ulang))
else:
note.attributes["type"] = "info"
note.addContent(lang.get("command_Done", ulang))
(username, oldpassword) = self.pytrans.xdb.getRegistration(toj.userhost())
self.pytrans.xdb.setRegistration(toj.userhost(), username, newpassword)
self.pytrans.send(iq)
示例3: sendErrorMessage
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendErrorMessage(pytrans, to, fro, etype, condition, explanation, body=None, el=None):
if el is None:
el = Element((None, "message"))
el.attributes["to"] = to
el.attributes["from"] = fro
el.attributes["type"] = "error"
error = el.addElement("error")
error.attributes["type"] = etype
error.attributes["code"] = str(utils.errorCodeMap[condition])
if condition:
desc = error.addElement(condition)
desc.attributes["xmlns"] = globals.XMPP_STANZAS
text = error.addElement("text")
text.attributes["xmlns"] = globals.XMPP_STANZAS
text.addContent(explanation)
bodywritten = False # no <body/> in message
for child in el.elements(): # try find in el
if child.name == 'body': # <body/> already in el
if body and len(body) > 0: # necessary add other info to it
body_txt = child.__str__()
child.addContent(body_txt + '\n' + body)
bodywritten = True
if not bodywritten and body and len(body) > 0: # <body/> in el don't found
b = el.addElement('body')
b.addContent(body)
pytrans.send(el)
示例4: sendCommandInfoResponse
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendCommandInfoResponse(self, to, ID, node, ulang):
LogEvent(INFO, msg="Replying to disco#info")
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = config.jid
iq.attributes["to"] = to
if ID: iq.attributes["id"] = ID
query = iq.addElement("query")
query.attributes["xmlns"] = globals.DISCO_INFO
# Add identity
identity = query.addElement("identity")
identity.attributes["name"] = lang.get(self.commandNames[node], ulang)
identity.attributes["category"] = "automation"
identity.attributes["type"] = "command-node"
# Add supported feature
feature = query.addElement("feature")
feature.attributes["var"] = globals.COMMANDS
# Add supported feature
feature = query.addElement("feature")
feature.attributes["var"] = globals.XDATA
self.pytrans.send(iq)
示例5: sendRegistrationFields
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendRegistrationFields(self, incoming):
# Construct a reply with the fields they must fill out
LogEvent(INFO)
reply = Element((None, "iq"))
reply.attributes["from"] = config.jid
reply.attributes["to"] = incoming.getAttribute("from")
reply.attributes["id"] = incoming.getAttribute("id")
reply.attributes["type"] = "result"
query = reply.addElement("query")
query.attributes["xmlns"] = globals.IQREGISTER
instructions = query.addElement("instructions")
ulang = utils.getLang(incoming)
instructions.addContent(lang.get("registertext", ulang))
userEl = query.addElement("username")
passEl = query.addElement("password")
# Check to see if they're registered
source = internJID(incoming.getAttribute("from")).userhost()
result = self.pytrans.xdb.getRegistration(source)
if result:
username, password = result
if username != "local":
userEl.addContent(username)
query.addElement("registered")
self.pytrans.send(reply)
示例6: send
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def send(self, to, body, subject=None, mtype=None, delay=None):
print 'start sending'
el = Element((None, "message"))
el.attributes["to"] = to
el.attributes["from"] = self.juser
el.attributes["id"] = '111111'
if(subject):
subj = el.addElement("subject")
subj.addContent(subject)
if(mtype):
el.attributes["type"] = mtype
if(delay):
x = el.addElement("x")
x.attributes["xmlns"] = "jabber:x:delay"
x.attributes["from"] = fro
x.attributes["stamp"] = delay
b = el.addElement("body")
b.addContent(body)
self.theXmlstream.send(el)
print 'done sending'
示例7: sendDiscoItemsResponse
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendDiscoItemsResponse(self, to, ID, ulang, jid):
""" Send a service discovery disco#items stanza to the given 'to'. 'jid' is the JID that was queried. """
LogEvent(INFO)
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = jid
iq.attributes["to"] = to
if ID:
iq.attributes["id"] = ID
query = iq.addElement("query")
query.attributes["xmlns"] = globals.DISCO_ITEMS
searchjid = jid
if jid.find('@') > 0: searchjid = "USER"
for node in self.nodes.get(searchjid, []):
handler, name, rootnode = self.nodes[jid][node]
if rootnode:
LogEvent(INFO, msg="Found node %r" % (node))
name = lang.get(name, ulang)
item = query.addElement("item")
item.attributes["jid"] = jid
item.attributes["node"] = node
item.attributes["name"] = name
if searchjid == "USER":
# Add any user specific items
for hndl in self.userItemHandlers:
hndl(jid, query)
self.pytrans.send(iq)
示例8: __getDiscoInfo
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def __getDiscoInfo(self, sender: JID, identifier: str, node: str):
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = self.h2x.config.JID
iq.attributes["to"] = sender.full()
if identifier:
iq.attributes["id"] = identifier
query = iq.addElement("query")
query.attributes["xmlns"] = "http://jabber.org/protocol/disco#info"
# Node not set -> send component identity
if node == None:
identity = query.addElement("identity")
identity.attributes["name"] = "Google Hangouts transport"
identity.attributes["category"] = "gateway"
identity.attributes["type"] = "XMPP"
query.addElement("feature").attributes["var"] = "jabber:iq:gateway"
query.addElement("feature").attributes["var"] = "jabber:iq:register"
query.addElement("feature").attributes["var"] = "jabber:iq:version"
# Generic features for both node and component
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/commands"
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/disco#items"
query.addElement("feature").attributes["var"] = "http://jabber.org/protocol/disco#info"
self.h2x.send(iq)
示例9: sendResponse
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendResponse(self, failure, el, sessionid=None):
LogEvent(INFO)
to = el.getAttribute("from")
toj = internJID(to)
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
if sessionid:
command.attributes["sessionid"] = sessionid
else:
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["node"] = "confirmaccount"
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
note = command.addElement("note")
if failure:
note.attributes["type"] = "error"
note.addContent(lang.get("command_ConfirmAccount_Failed", ulang))
else:
note.attributes["type"] = "info"
note.addContent(lang.get("command_ConfirmAccount_Complete", ulang))
self.pytrans.send(iq)
示例10: sendError
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendError(self, node, el, errormsg, sessionid=None):
to = el.getAttribute("from")
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
if sessionid:
command.attributes["sessionid"] = sessionid
else:
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["node"] = node
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
note = command.addElement("note")
note.attributes["type"] = "error"
note.addContent(errormsg)
self.pytrans.send(iq)
示例11: snfmtChangeResults
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def snfmtChangeResults(self, results, el, sessionid):
to = el.getAttribute("from")
toj = internJID(to)
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
if sessionid:
command.attributes["sessionid"] = sessionid
else:
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["node"] = "formatscreenname"
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
note = command.addElement("note")
if results[3]:
note.attributes["type"] = "error"
note.addContent(results[3][1])
else:
note.attributes["type"] = "info"
note.addContent(lang.get("command_Done", ulang))
self.pytrans.send(iq)
示例12: sendCommandList
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendCommandList(self, el):
to = el.getAttribute("from")
toj_uh = internJID(to).userhost()
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
query = iq.addElement("query")
query.attributes["xmlns"] = globals.DISCO_ITEMS
query.attributes["node"] = globals.COMMANDS
rights = rights_guest
if toj_uh in self.pytrans.sessions: # logined
rights = rights_user
if toj_uh in config.admins: # admin
rights = rights_admin
for command in self.commands:
if self.commandRights[command] <= rights: # user can view this item (enough rights)
item = query.addElement("item")
item.attributes["jid"] = config.jid
item.attributes["node"] = command
item.attributes["name"] = lang.get(self.commandNames[command], ulang)
self.pytrans.send(iq)
示例13: sendSearchForm
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def sendSearchForm(self, el):
LogEvent(INFO)
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
iq.attributes["from"] = el.getAttribute("to")
iq.attributes["to"] = el.getAttribute("from")
if el.getAttribute("id"):
iq.attributes["id"] = el.getAttribute("id")
query = iq.addElement("query")
query.attributes["xmlns"] = globals.IQSEARCH
forminstr = query.addElement("instructions")
forminstr.addContent(lang.get("searchnodataform", ulang))
x = query.addElement("x")
x.attributes["xmlns"] = globals.XDATA
x.attributes["type"] = "form"
title = x.addElement("title")
title.addContent(lang.get("searchtitle", ulang))
instructions = x.addElement("instructions")
instructions.addContent(lang.get("searchinstructions", ulang))
x.addChild(utils.makeDataFormElement("hidden", "FORM_TYPE", value="jabber:iq:search"))
x.addChild(utils.makeDataFormElement("text-single", "email", "E-Mail Address"))
x.addChild(utils.makeDataFormElement("text-single", "first", "First Name"))
x.addChild(utils.makeDataFormElement("text-single", "middle", "Middle Name"))
x.addChild(utils.makeDataFormElement("text-single", "last", "Last Name"))
x.addChild(utils.makeDataFormElement("text-single", "maiden", "Maiden Name"))
x.addChild(utils.makeDataFormElement("text-single", "nick", "Nickname"))
x.addChild(utils.makeDataFormElement("text-single", "address", "Street Address"))
x.addChild(utils.makeDataFormElement("text-single", "city", "City"))
x.addChild(utils.makeDataFormElement("text-single", "state", "State"))
x.addChild(utils.makeDataFormElement("text-single", "zip", "Zip Code"))
x.addChild(utils.makeDataFormElement("text-single", "country", "Country"))
x.addChild(utils.makeDataFormElement("text-single", "interest", "Interest"))
self.pytrans.send(iq)
示例14: incomingIq
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def incomingIq(self, el):
to = el.getAttribute("from")
ID = el.getAttribute("id")
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["to"] = to
iq.attributes["from"] = config.jid
if ID:
iq.attributes["id"] = ID
iq.attributes["type"] = "result"
command = iq.addElement("command")
command.attributes["sessionid"] = self.pytrans.makeMessageID()
command.attributes["xmlns"] = globals.COMMANDS
command.attributes["status"] = "completed"
x = command.addElement("x")
x.attributes["xmlns"] = globals.XDATA
x.attributes["type"] = "result"
title = x.addElement("title")
title.addContent(lang.get("command_Statistics", ulang))
for key in self.stats:
label = lang.get("statistics_%s" % key, ulang)
description = lang.get("statistics_%s_Desc" % key, ulang)
field = x.addElement("field")
field.attributes["var"] = key
field.attributes["label"] = label
field.attributes["type"] = "text-single"
field.addElement("value").addContent(str(self.stats[key]))
field.addElement("desc").addContent(description)
self.pytrans.send(iq)
示例15: processSearch
# 需要导入模块: from twisted.words.xish.domish import Element [as 别名]
# 或者: from twisted.words.xish.domish.Element import attributes["type"] [as 别名]
def processSearch(self, el):
LogEvent(INFO)
ulang = utils.getLang(el)
iq = Element((None, "iq"))
iq.attributes["type"] = "result"
to = el.getAttribute("to")
iq.attributes["from"] = to
fro = el.getAttribute("from")
iq.attributes["to"] = fro
ID = el.getAttribute("id")
if ID:
iq.attributes["id"] = ID
query = iq.addElement("query")
query.attributes["xmlns"] = globals.IQSEARCH
x = query.addElement("x")
x.attributes["xmlns"] = globals.XDATA
x.attributes["type"] = "result"
x.addChild(utils.makeDataFormElement(
"hidden", "FORM_TYPE", value="jabber:iq:search"))
reported = x.addElement("reported")
reported.addChild(utils.makeDataFormElement(None, "jid", "Jabber ID"))
reported.addChild(
utils.makeDataFormElement(None, "first", "First Name"))
reported.addChild(
utils.makeDataFormElement(None, "middle", "Middle Name"))
reported.addChild(utils.makeDataFormElement(None, "last", "Last Name"))
reported.addChild(
utils.makeDataFormElement(None, "maiden", "Maiden Name"))
reported.addChild(utils.makeDataFormElement(None, "nick", "Nickname"))
reported.addChild(
utils.makeDataFormElement(None, "email", "E-Mail Address"))
reported.addChild(
utils.makeDataFormElement(None, "address", "Street Address"))
reported.addChild(utils.makeDataFormElement(None, "city", "City"))
reported.addChild(utils.makeDataFormElement(None, "state", "State"))
reported.addChild(
utils.makeDataFormElement(None, "country", "Country"))
reported.addChild(utils.makeDataFormElement(None, "zip", "Zip Code"))
reported.addChild(utils.makeDataFormElement(None, "region", "Region"))
dataform = None
for query in el.elements():
if query.name == "query":
for child in query.elements():
if child.name == "x":
dataform = child
break
break
if not hasattr(self.pytrans, "legacycon"):
self.pytrans.iq.sendIqError(
to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="cancel", condition="bad-request")
if dataform:
self.pytrans.legacycon.doSearch(
dataform, iq).addCallback(self.gotSearchResponse)
else:
self.pytrans.iq.sendIqError(
to=to, fro=config.jid, ID=ID, xmlns=globals.IQSEARCH, etype="retry", condition="bad-request")