本文整理匯總了Python中pyxmpp2.streambase.StreamBase.set_authenticated方法的典型用法代碼示例。如果您正苦於以下問題:Python StreamBase.set_authenticated方法的具體用法?Python StreamBase.set_authenticated怎麽用?Python StreamBase.set_authenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyxmpp2.streambase.StreamBase
的用法示例。
在下文中一共展示了StreamBase.set_authenticated方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Server
# 需要導入模塊: from pyxmpp2.streambase import StreamBase [as 別名]
# 或者: from pyxmpp2.streambase.StreamBase import set_authenticated [as 別名]
class Server(StanzaProcessor, EventHandler, TimeoutHandler, XMPPFeatureHandler):
"""
The XMPP end of the proxy.
Handles local XMPP client connections. Forwards stanzas from the
client to the Tlen server, and the other way around. Stanzas are
adapted to achieve maximum satisfaction on both sides ;)
"""
def __init__(self, transport, avatars):
StanzaProcessor.__init__(self)
logger.debug('-- New connection')
self.avatars = avatars
self.settings = XMPPSettings()
self.handlers = [self, ResourceBindingHandler(self.settings)]
self.stream = StreamBase(u"jabber:client", self, self.handlers, self.settings)
self.stream.set_authenticated(JID(domain='tlen.pl'))
self.tlen = None
self.transport = transport
self.stream.receive(self.transport, 'tlen.pl')
self.uplink = self.stream
self.stream.set_authenticated(JID(domain='tlen.pl'))
@event_handler(AuthenticatedEvent)
def authenticated(self, event):
self.setup_stanza_handlers(self.handlers, 'post-auth')
@event_handler(DisconnectedEvent)
def disconnected(self, event):
logger.debug('Client disconnected')
if self.tlen:
self.tlen.close()
self.tlen = None
return QUIT
# Stanza handlers. Except for authentication stuff, they
# push everything to the TlenClient. Anything that needs
# fixing up before being sent to the server is performed
# in TlenClient.send()
@iq_get_stanza_handler(XMLPayload, '{jabber:iq:auth}query')
def handle_auth_get(self, stanza):
logger.debug('auth get %s', stanza.serialize())
resp = stanza.make_result_response()
query = ElementTree.Element('{jabber:iq:auth}query')
for x in ('username', 'password', 'resource'):
query.append(ElementTree.Element('{jabber:iq:auth}' + x))
resp.add_payload(query)
return resp
@iq_set_stanza_handler(XMLPayload, '{jabber:iq:auth}query')
def handle_auth_set(self, stanza):
"""
This is the part that actually starts the Tlen end
of the proxy.
We're expecting PLAIN XMPP authentication here, so we
can grab the auth data and log in to Tlen.pl, on behalf
of the user.
"""
query = stanza.get_payload(None, 'query').as_xml()
# XXX: Assuming the client will use legacy auth
username = query.findtext('{jabber:iq:auth}username')
password = query.findtext('{jabber:iq:auth}password')
resource = query.findtext('{jabber:iq:auth}resource')
if not username or not password:
# XXX
return stanza.make_error_response('bad-request')
self.tlen = TlenStream(JID(username, 'tlen.pl'), password, resource, self.avatars)
self.tlen.uplink = self.stream
self.tlen.start()
if self.tlen.wait_for_auth():
return stanza.make_result_response()
else:
# XXX: is this code ok?
return stanza.make_error_response('not-authorized')
@iq_get_stanza_handler(XMLPayload, '{jabber:iq:roster}query')
def handle_roster_get(self, stanza):
self.tlen.send(stanza)
@iq_set_stanza_handler(XMLPayload, '{jabber:iq:roster}query')
def handle_roster_set(self, stanza):
self.tlen.send(stanza)
#.........這裏部分代碼省略.........