本文整理汇总了Python中pyxmpp.iq.Iq类的典型用法代码示例。如果您正苦于以下问题:Python Iq类的具体用法?Python Iq怎么用?Python Iq使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Iq类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: configure_room
def configure_room(self, form):
"""
Configure the room using the provided data.
Do nothing if the provided form is of type 'cancel'.
:Parameters:
- `form`: the configuration parameters. Should be a 'submit' form made by filling-in
the configuration form retireved using `self.request_configuration_form` or
a 'cancel' form.
:Types:
- `form`: `Form`
:return: id of the request stanza or `None` if a 'cancel' form was provieded.
:returntype: `unicode`
"""
if form.type == "cancel":
return None
elif form.type != "submit":
raise ValueError, "A 'submit' form required to configure a room"
iq = Iq(to_jid = self.room_jid.bare(), stanza_type = "set")
query = iq.new_query(MUC_OWNER_NS, "query")
form.as_xml(query)
self.manager.stream.set_response_handlers(
iq, self.process_configuration_success, self.process_configuration_error)
self.manager.stream.send(iq)
return iq.get_id()
示例2: __init__
def __init__(self,xmlnode=None,from_jid=None,to_jid=None,stanza_type=None,stanza_id=None,
error=None,error_cond=None):
"""Initialize an `Iq` object.
:Parameters:
- `xmlnode`: XML node to_jid be wrapped into the `Iq` object
or other Iq object to be copied. If not given then new
presence stanza is created using following parameters.
- `from_jid`: sender JID.
- `to_jid`: recipient JID.
- `stanza_type`: staza type: one of: "get", "set", "result" or "error".
- `stanza_id`: stanza id -- value of stanza's "id" attribute. If not
given, then unique for the session value is generated.
- `error_cond`: error condition name. Ignored if `stanza_type` is not "error".
:Types:
- `xmlnode`: `unicode` or `libxml2.xmlNode` or `Iq`
- `from_jid`: `JID`
- `to_jid`: `JID`
- `stanza_type`: `unicode`
- `stanza_id`: `unicode`
- `error_cond`: `unicode`"""
MucStanzaExt.__init__(self)
Iq.__init__(self,xmlnode,from_jid=from_jid,to_jid=to_jid,
stanza_type=stanza_type,stanza_id=stanza_id,
error=error,error_cond=error_cond)
示例3: request_session
def request_session(self):
"""Request an IM session."""
stream=self.get_stream()
if not stream.version:
need_session=False
elif not stream.features:
need_session=False
else:
ctxt = stream.doc_in.xpathNewContext()
ctxt.setContextNode(stream.features)
ctxt.xpathRegisterNs("sess","urn:ietf:params:xml:ns:xmpp-session")
# jabberd2 hack
ctxt.xpathRegisterNs("jsess","http://jabberd.jabberstudio.org/ns/session/1.0")
sess_n=None
try:
sess_n=ctxt.xpathEval("sess:session or jsess:session")
finally:
ctxt.xpathFreeContext()
if sess_n:
need_session=True
else:
need_session=False
if not need_session:
self.state_changed.acquire()
self.session_established=1
self.state_changed.notify()
self.state_changed.release()
self._session_started()
else:
iq=Iq(stanza_type="set")
iq.new_query("urn:ietf:params:xml:ns:xmpp-session","session")
stream.set_response_handlers(iq,
self.__session_result,self.__session_error,self.__session_timeout)
stream.send(iq)
示例4: make_push
def make_push(self, digsby_protocol):
'Creates a set stanza.'
iq=Iq(stanza_type="set")
iq.set_to(digsby_protocol.jid.domain)
self.as_xml(parent=iq.get_node())
return iq
示例5: query_get
def query_get(self, jid, handler) :
stream = self.client.get_stream()
iq = Iq(to_jid=jid, stanza_type="get")
q=iq.new_query(VCARD_NS, "vCard")
stream.set_response_handlers(iq, self.on_get_result, self.on_get_error)
stream.send(iq)
self.handler = handler
示例6: test_get_lang_class_from_node
def test_get_lang_class_from_node(self):
iq = Iq(from_jid = "[email protected]", \
to_jid = "[email protected]", \
stanza_type = "get")
iq_node = iq.get_node()
iq_node.setLang("fr")
lang = self.lang.get_lang_class_from_node(iq_node)
self.assertEquals(lang, Lang.fr)
示例7: query_set
def query_set(self, vcard) :
stream = self.client.get_stream()
new_id = stream.generate_id()
iq = Iq(None, None, None, "set", new_id)
node=iq.new_query(VCARD_NS, "vCard")
vcard.as_xml(node)
stream.set_response_handlers(iq, self.on_set_result, self.on_set_error)
stream.send(iq)
示例8: make_roster_push
def make_roster_push(self):
"""
Make "roster push" IQ stanza from the item representing roster update
request.
"""
iq=Iq(stanza_type="set")
q=iq.new_query(ROSTER_NS)
self.as_xml(parent=q, doc=common_doc)
return iq
示例9: request_roster
def request_roster(self):
"""Request the user's roster."""
stream=self.get_stream()
iq=Iq(stanza_type="get")
iq.new_query("jabber:iq:roster")
stream.set_response_handlers(iq,
self.__roster_result,self.__roster_error,self.__roster_timeout)
stream.set_iq_set_handler("query","jabber:iq:roster",self.__roster_push)
stream.send(iq)
示例10: fetch
def fetch(self):
"""Initialize the Service Discovery process."""
from pyxmpp.iq import Iq
jid,node = self.address
iq = Iq(to_jid = jid, stanza_type = "get")
disco = self.disco_class(node)
iq.add_content(disco.xmlnode)
self.stream.set_response_handlers(iq,self.__response, self.__error,
self.__timeout)
self.stream.send(iq)
示例11: _auth_stage1
def _auth_stage1(self):
"""Do the first stage (<iq type='get'/>) of legacy ("plain" or
"digest") authentication.
[client only]"""
iq=Iq(stanza_type="get")
q=iq.new_query("jabber:iq:auth")
q.newTextChild(None,"username",to_utf8(self.my_jid.node))
q.newTextChild(None,"resource",to_utf8(self.my_jid.resource))
self.send(iq)
self.set_response_handlers(iq,self.auth_stage2,self.auth_error,
self.auth_timeout,timeout=60)
iq.free()
示例12: _plain_auth_stage2
def _plain_auth_stage2(self, _unused):
"""Do the second stage (<iq type='set'/>) of legacy "plain"
authentication.
[client only]"""
iq=Iq(stanza_type="set")
q=iq.new_query("jabber:iq:auth")
q.newTextChild(None,"username",to_utf8(self.my_jid.node))
q.newTextChild(None,"resource",to_utf8(self.my_jid.resource))
q.newTextChild(None,"password",to_utf8(self.password))
self.send(iq)
self.set_response_handlers(iq,self.auth_finish,self.auth_error)
iq.free()
示例13: request_configuration_form
def request_configuration_form(self):
"""
Request a configuration form for the room.
When the form is received `self.handler.configuration_form_received` will be called.
When an error response is received then `self.handler.error` will be called.
:return: id of the request stanza.
:returntype: `unicode`
"""
iq = Iq(to_jid = self.room_jid.bare(), stanza_type = "get")
iq.new_query(MUC_OWNER_NS, "query")
self.manager.stream.set_response_handlers(
iq, self.process_configuration_form_success, self.process_configuration_form_error)
self.manager.stream.send(iq)
return iq.get_id()
示例14: _post_connect
def _post_connect(self):
"""Initialize authentication when the connection is established
and we are the initiator."""
if not self.initiator:
if "plain" in self.auth_methods or "digest" in self.auth_methods:
self.set_iq_get_handler("query","jabber:iq:auth",
self.auth_in_stage1)
self.set_iq_set_handler("query","jabber:iq:auth",
self.auth_in_stage2)
elif self.registration_callback:
iq = Iq(stanza_type = "get")
iq.set_content(Register())
self.set_response_handlers(iq, self.registration_form_received, self.registration_error)
self.send(iq)
return
ClientStream._post_connect(self)
示例15: _digest_auth_stage2
def _digest_auth_stage2(self, _unused):
"""Do the second stage (<iq type='set'/>) of legacy "digest"
authentication.
[client only]"""
iq=Iq(stanza_type="set")
q=iq.new_query("jabber:iq:auth")
q.newTextChild(None,"username",to_utf8(self.my_jid.node))
q.newTextChild(None,"resource",to_utf8(self.my_jid.resource))
digest = hashlib.sha1(to_utf8(self.stream_id)+to_utf8(self.password)).hexdigest()
q.newTextChild(None,"digest",digest)
self.send(iq)
self.set_response_handlers(iq,self.auth_finish,self.auth_error)
iq.free()