Remove trailing whitespaces.
This commit is contained in:
parent
310e2cc347
commit
27b3592e16
26 changed files with 899 additions and 899 deletions
|
|
@ -83,7 +83,7 @@ class CS_Plugin():
|
|||
def dataLoaded(ignore):
|
||||
if not self.data[profile]:
|
||||
self.data[profile] = {'cookies':{}}
|
||||
|
||||
|
||||
self.data[profile].load().addCallback(dataLoaded)
|
||||
|
||||
def profileDisconnected(self, profile):
|
||||
|
|
@ -104,10 +104,10 @@ class CS_Plugin():
|
|||
self.host.bridge.actionResult("ERROR", id, message_data)
|
||||
return
|
||||
|
||||
post_data = urllib.urlencode({'auth_login[un]':login,'auth_login[pw]':password,'auth_login[action]':'Login...'})
|
||||
|
||||
post_data = urllib.urlencode({'auth_login[un]':login,'auth_login[pw]':password,'auth_login[action]':'Login...'})
|
||||
|
||||
self.data[profile]['cookies'] = {}
|
||||
|
||||
|
||||
d = getPage('http://www.couchsurfing.org/login.html', method='POST', postdata=post_data, headers={'Content-Type':'application/x-www-form-urlencoded'} , agent=AGENT, cookies=self.data[profile]['cookies'])
|
||||
d.addCallback(self.__connectionCB, id, profile)
|
||||
d.addErrback(self.erroCB, id)
|
||||
|
|
@ -193,7 +193,7 @@ class CS_Plugin():
|
|||
friend_id = regex_href.search(unicode(a_tag)).groups()[0]
|
||||
|
||||
debug(_("CS friend found: %(friend_name)s (id: %(friend_id)s, link: %(friend_link)s)") % {'friend_name':friend_name, 'friend_id':friend_id, 'friend_link':friend_link})
|
||||
friends[friend_name] = {'link':friend_link,'id':friend_id}
|
||||
friends[friend_name] = {'link':friend_link,'id':friend_id}
|
||||
a = soup.find('td','barmiddle next').a #is there several pages ?
|
||||
if a:
|
||||
#yes, we parse the next page
|
||||
|
|
@ -255,7 +255,7 @@ class CS_Plugin():
|
|||
message = data['message']
|
||||
info(_("sending message to %(friends)s with subject [%(subject)s]" % {'friends':friends, 'subject':subject}))
|
||||
self.__sendMessage(None, subject, message, self.data[profile], friends, id, profile)
|
||||
|
||||
|
||||
def __showUnreadMessages2(self, html, id, profile):
|
||||
"""Called when the inbox page has been received"""
|
||||
#FIXME: that's really too fragile, only works if the unread messages are in the first page, and it would be too resources consuming for the website to DL each time all pages. In addition, the show attribute doesn't work as expected.
|
||||
|
|
@ -269,4 +269,4 @@ class CS_Plugin():
|
|||
d = getPage("http://www.couchsurfing.org/messages.html?message_status=inbox&show=10000", agent=AGENT, cookies=self.data[profile]['cookies'])
|
||||
d.addCallback(self.__showUnreadMessages2, id, profile)
|
||||
d.addErrback(self.erroCB, id)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ from twisted.words.protocols.jabber import jid
|
|||
|
||||
|
||||
from sat.core.exceptions import UnknownEntityError
|
||||
from sat.tools.misc import SkipOtherTriggers
|
||||
from sat.tools.misc import SkipOtherTriggers
|
||||
|
||||
PLUGIN_INFO = {
|
||||
"name": "Parrot Plugin",
|
||||
|
|
@ -57,28 +57,28 @@ class Exp_Parrot():
|
|||
# _links = client.parrot_links
|
||||
# except AttributeError:
|
||||
# return True
|
||||
#
|
||||
#
|
||||
# if mess_data['to'].userhostJID() in _links.values():
|
||||
# debug("Parrot link detected, skipping other triggers")
|
||||
# raise SkipOtherTriggers
|
||||
# raise SkipOtherTriggers
|
||||
|
||||
def MessageReceivedTrigger(self, message, profile):
|
||||
""" Check if source is linked and repeat message, else do nothing """
|
||||
client = self.host.getClient(profile)
|
||||
from_jid = jid.JID(message["from"])
|
||||
|
||||
|
||||
try:
|
||||
_links = client.parrot_links
|
||||
except AttributeError:
|
||||
return True
|
||||
|
||||
|
||||
if not from_jid.userhostJID() in _links:
|
||||
return True
|
||||
|
||||
|
||||
for e in message.elements():
|
||||
if e.name == "body":
|
||||
mess_body = e.children[0] if e.children else ""
|
||||
|
||||
|
||||
try:
|
||||
entity_type = self.host.memory.getEntityData(from_jid, ['type'], profile)["type"]
|
||||
except (UnknownEntityError, KeyError):
|
||||
|
|
@ -97,7 +97,7 @@ class Exp_Parrot():
|
|||
self.host.sendMessage(unicode(linked), msg, None, "auto", profile_key=profile)
|
||||
else:
|
||||
warning("No body element found in message, following normal behaviour")
|
||||
|
||||
|
||||
return True
|
||||
|
||||
def addParrot(self, source_jid, dest_jid, profile):
|
||||
|
|
|
|||
|
|
@ -57,9 +57,9 @@ class Exp_Pipe():
|
|||
|
||||
def profileConnected(self, profile):
|
||||
client = self.host.getClient(profile)
|
||||
client._pipe_waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout,
|
||||
client._pipe_waiting_for_approval = {} #key = id, value = [transfer data, IdelayedCall Reactor timeout,
|
||||
# current stream method, [failed stream methods], profile]
|
||||
|
||||
|
||||
def _kill_id(self, approval_id, profile):
|
||||
"""Delete a waiting_for_approval id, called after timeout
|
||||
@param approval_id: id of _pipe_waiting_for_approval"""
|
||||
|
|
@ -69,7 +69,7 @@ class Exp_Pipe():
|
|||
del client._pipe_waiting_for_approval[approval_id]
|
||||
except KeyError:
|
||||
warning(_("kill id called on a non existant approval id"))
|
||||
|
||||
|
||||
def transferRequest(self, iq_id, from_jid, si_id, si_mime_type, si_el, profile):
|
||||
"""Called when a pipe transfer is requested
|
||||
@param iq_id: id of the iq request
|
||||
|
|
@ -85,12 +85,12 @@ class Exp_Pipe():
|
|||
raise ProfileNotInCacheError
|
||||
pipe_elts = filter(lambda elt: elt.name == 'pipe', si_el.elements())
|
||||
feature_elts = self.host.plugins["XEP-0020"].getFeatureElt(si_el)
|
||||
|
||||
|
||||
if not pipe_elts:
|
||||
warning(_("No pipe element found"))
|
||||
self.host.plugins["XEP-0095"].sendBadRequestError(iq_id, from_jid, profile)
|
||||
return
|
||||
|
||||
|
||||
if feature_elts:
|
||||
feature_el = feature_elts[0]
|
||||
form = data_form.Form.fromElement(feature_el.firstChildElement())
|
||||
|
|
@ -202,7 +202,7 @@ class Exp_Pipe():
|
|||
if not feature_elts:
|
||||
warning(_("No feature element"))
|
||||
return
|
||||
|
||||
|
||||
choosed_options = self.host.plugins["XEP-0020"].getChoosedOptions(feature_elts[0])
|
||||
try:
|
||||
stream_method = choosed_options["stream-method"]
|
||||
|
|
@ -236,9 +236,9 @@ class Exp_Pipe():
|
|||
warning(_("Trying to send a file from an unknown profile"))
|
||||
return ""
|
||||
feature_elt = self.host.plugins["XEP-0020"].proposeFeatures({'stream-method': self.managed_stream_m})
|
||||
|
||||
|
||||
pipe_transfer_elts = []
|
||||
|
||||
|
||||
pipe_elt = domish.Element((PROFILE, 'pipe'))
|
||||
pipe_transfer_elts.append(pipe_elt)
|
||||
|
||||
|
|
|
|||
|
|
@ -52,12 +52,12 @@ RESERVED = ['libervia']
|
|||
|
||||
class ProsodyRegisterProtocol(protocol.ProcessProtocol):
|
||||
""" Try to register an account with prosody """
|
||||
|
||||
|
||||
def __init__(self, password, deferred = None):
|
||||
self.password = password
|
||||
self.deferred = deferred
|
||||
self.data = ''
|
||||
|
||||
|
||||
def connectionMade(self):
|
||||
self.transport.write("%s\n%s" % ((self.password.encode('utf-8'),)*2))
|
||||
self.transport.closeStdin()
|
||||
|
|
@ -65,10 +65,10 @@ class ProsodyRegisterProtocol(protocol.ProcessProtocol):
|
|||
|
||||
def outReceived(self, data):
|
||||
self.data += data
|
||||
|
||||
|
||||
def errReceived(self, data):
|
||||
self.data += data
|
||||
|
||||
|
||||
def processEnded(self, reason):
|
||||
if (reason.value.exitCode == 0):
|
||||
info(_('Prosody registration success'))
|
||||
|
|
@ -97,7 +97,7 @@ class MiscAccount():
|
|||
info(_('Prosody path found: %s') % (self._prosody_path,))
|
||||
|
||||
def _registerAccount(self, email, password, profile):
|
||||
|
||||
|
||||
"""
|
||||
#Password Generation
|
||||
#_charset = [chr(i) for i in range(0x21,0x7F)] #XXX: this charset seems to have some issues with openfire
|
||||
|
|
@ -117,13 +117,13 @@ class MiscAccount():
|
|||
return d
|
||||
|
||||
def _profileRegistered(self, result, email, password, profile):
|
||||
|
||||
|
||||
#FIXME: values must be in a config file instead of hardcoded
|
||||
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile)
|
||||
self.host.memory.setParam("JabberID", "%s@%s/%s" % (profile, _NEW_ACCOUNT_DOMAIN, _NEW_ACCOUNT_RESOURCE), "Connection", profile)
|
||||
self.host.memory.setParam("Server", _NEW_ACCOUNT_SERVER, "Connection", profile)
|
||||
self.host.memory.setParam("Password", password, "Connection", profile)
|
||||
#and the account
|
||||
|
||||
|
||||
#XXX: we use "prosodyctl adduser" because "register" doesn't check conflict
|
||||
# and just change the password if the account already exists
|
||||
d = defer.Deferred()
|
||||
|
|
@ -146,7 +146,7 @@ class MiscAccount():
|
|||
def email_ko(ignore):
|
||||
#TODO: return error code to user
|
||||
error ("Failed to send email to %s" % email)
|
||||
|
||||
|
||||
body = (u"""Welcome to Libervia, a Salut à Toi project part
|
||||
|
||||
/!\\ WARNING, THIS IS ONLY A TECHNICAL DEMO, DON'T USE THIS ACCOUNT FOR ANY SERIOUS PURPOSE /!\\
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ class GroupBlog():
|
|||
|
||||
host.bridge.addMethod("sendGroupBlog", ".plugin", in_sign='sasss', out_sign='',
|
||||
method=self.sendGroupBlog)
|
||||
|
||||
|
||||
host.bridge.addMethod("getLastGroupBlogs", ".plugin",
|
||||
in_sign='sis', out_sign='aa{ss}',
|
||||
method=self.getLastGroupBlogs,
|
||||
|
|
@ -92,21 +92,21 @@ class GroupBlog():
|
|||
in_sign='sasis', out_sign='a{saa{ss}}',
|
||||
method=self.getMassiveLastGroupBlogs,
|
||||
async = True)
|
||||
|
||||
|
||||
host.bridge.addMethod("subscribeGroupBlog", ".plugin", in_sign='ss', out_sign='',
|
||||
method=self.subscribeGroupBlog,
|
||||
async = True)
|
||||
|
||||
|
||||
host.bridge.addMethod("massiveSubscribeGroupBlogs", ".plugin", in_sign='sass', out_sign='',
|
||||
method=self.massiveSubscribeGroupBlogs,
|
||||
async = True)
|
||||
|
||||
|
||||
host.trigger.add("PubSubItemsReceived", self.pubSubItemsReceivedTrigger)
|
||||
|
||||
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return GroupBlog_handler()
|
||||
|
||||
|
||||
@defer.inlineCallbacks
|
||||
def initialise(self, profile_key):
|
||||
"""Check that this data for this profile are initialised, and do it else
|
||||
|
|
@ -115,14 +115,14 @@ class GroupBlog():
|
|||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not profile:
|
||||
error(_("Unknown profile"))
|
||||
raise Exception("Unknown profile")
|
||||
|
||||
raise Exception("Unknown profile")
|
||||
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
error(_('No client for this profile key: %s') % profile_key)
|
||||
raise Exception("Unknown profile")
|
||||
raise Exception("Unknown profile")
|
||||
yield client.client_initialized #we want to be sure that the client is initialized
|
||||
|
||||
|
||||
#we first check that we have a item-access pubsub server
|
||||
if not hasattr(client,"item_access_pubsub"):
|
||||
debug(_('Looking for item-access power pubsub server'))
|
||||
|
|
@ -136,7 +136,7 @@ class GroupBlog():
|
|||
info(_("item-access powered pubsub service found: [%s]") % entity.full())
|
||||
client.item_access_pubsub = entity
|
||||
client._item_access_pubsub_pending.callback(None)
|
||||
|
||||
|
||||
if hasattr(client,"_item_access_pubsub_pending"):
|
||||
#XXX: we need to wait for item access pubsub service check
|
||||
yield client._item_access_pubsub_pending
|
||||
|
|
@ -174,7 +174,7 @@ class GroupBlog():
|
|||
form_elts = filter(lambda elt: elt.name == "x", item.children)
|
||||
for form_elt in form_elts:
|
||||
form = data_form.Form.fromElement(form_elt)
|
||||
|
||||
|
||||
if (form.formNamespace == NS_PUBSUB_ITEM_CONFIG):
|
||||
access_model = form.get(OPT_ACCESS_MODEL, 'open')
|
||||
if access_model == "roster":
|
||||
|
|
@ -183,7 +183,7 @@ class GroupBlog():
|
|||
except KeyError:
|
||||
warning("No group found for roster access-model")
|
||||
microblog_data["groups"] = ''
|
||||
|
||||
|
||||
break
|
||||
|
||||
def item2gbdata(self, item):
|
||||
|
|
@ -258,12 +258,12 @@ class GroupBlog():
|
|||
raise NotImplementedError
|
||||
else:
|
||||
error(_("Unknown access type"))
|
||||
raise BadAccessTypeError
|
||||
|
||||
raise BadAccessTypeError
|
||||
|
||||
self.initialise(profile_key).addCallback(initialised)
|
||||
|
||||
|
||||
|
||||
|
||||
def getLastGroupBlogs(self, pub_jid, max_items=10, profile_key='@DEFAULT@'):
|
||||
"""Get the last published microblogs
|
||||
@param pub_jid: jid of the publisher
|
||||
|
|
@ -271,7 +271,7 @@ class GroupBlog():
|
|||
@param profile_key: profile key
|
||||
@return: list of microblog data (dict)
|
||||
"""
|
||||
|
||||
|
||||
def initialised(result):
|
||||
profile, client = result
|
||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(pub_jid)),
|
||||
|
|
@ -292,14 +292,14 @@ class GroupBlog():
|
|||
"""
|
||||
def sendResult(result):
|
||||
"""send result of DeferredList (list of microblogs to the calling method"""
|
||||
|
||||
|
||||
ret = {}
|
||||
|
||||
for (success, value) in result:
|
||||
if success:
|
||||
source_jid, data = value
|
||||
ret[source_jid] = data
|
||||
|
||||
|
||||
return ret
|
||||
|
||||
def initialised(result):
|
||||
|
|
@ -316,9 +316,9 @@ class GroupBlog():
|
|||
jids = publishers
|
||||
else:
|
||||
raise UnknownType
|
||||
|
||||
|
||||
mblogs = []
|
||||
|
||||
|
||||
for _jid in jids:
|
||||
d = self.host.plugins["XEP-0060"].getItems(client.item_access_pubsub, self.getNodeName(jid.JID(_jid)),
|
||||
max_items=max_items, profile_key=profile_key)
|
||||
|
|
@ -326,7 +326,7 @@ class GroupBlog():
|
|||
mblogs.append(d)
|
||||
dlist = defer.DeferredList(mblogs)
|
||||
dlist.addCallback(sendResult)
|
||||
|
||||
|
||||
return dlist
|
||||
|
||||
|
||||
|
|
@ -391,7 +391,7 @@ class GroupBlog():
|
|||
|
||||
class GroupBlog_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||
return [disco.DiscoFeature(NS_GROUPBLOG)]
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ PLUGIN_INFO = {
|
|||
|
||||
class IMAP_server():
|
||||
#TODO: connect profile on mailbox request, once password is accepted
|
||||
|
||||
|
||||
params = """
|
||||
<params>
|
||||
<general>
|
||||
|
|
@ -65,13 +65,13 @@ class IMAP_server():
|
|||
def __init__(self, host):
|
||||
info(_("Plugin Imap Server initialization"))
|
||||
self.host = host
|
||||
|
||||
|
||||
#parameters
|
||||
host.memory.importParams(self.params)
|
||||
|
||||
port = int(self.host.memory.getParamA("IMAP Port", "Mail Server"))
|
||||
info(_("Launching IMAP server on port %d"), port)
|
||||
|
||||
|
||||
self.server_factory = ImapServerFactory(self.host)
|
||||
reactor.listenTCP(port, self.server_factory)
|
||||
|
||||
|
|
@ -84,7 +84,7 @@ class Message():
|
|||
self.flags=flags
|
||||
self.mess_fp=mess_fp
|
||||
self.message=Parser().parse(mess_fp)
|
||||
|
||||
|
||||
def getUID(self):
|
||||
"""Retrieve the unique identifier associated with this message.
|
||||
"""
|
||||
|
|
@ -221,7 +221,7 @@ class SatMailbox:
|
|||
"""Called before this mailbox is deleted, permanently.
|
||||
"""
|
||||
debug('destroy')
|
||||
|
||||
|
||||
|
||||
def requestStatus(self, names):
|
||||
"""Return status information about this mailbox.
|
||||
|
|
@ -340,7 +340,7 @@ class SatMailbox:
|
|||
setF(mess_id, new_flags)
|
||||
ret[mess_id] = tuple(new_flags)
|
||||
return ret
|
||||
|
||||
|
||||
if uid:
|
||||
messages.last = self.mailbox.getMaxUid()
|
||||
messages.getnext = self.mailbox.getNextExistingUid
|
||||
|
|
@ -348,7 +348,7 @@ class SatMailbox:
|
|||
for listener in self.listeners:
|
||||
listener.flagsChanged(ret)
|
||||
return ret
|
||||
|
||||
|
||||
else:
|
||||
messages.last = self.getMessageCount()
|
||||
ret = updateFlags(self.mailbox.getFlags,self.mailbox.setFlags)
|
||||
|
|
@ -412,7 +412,7 @@ class SatProfileCredentialChecker:
|
|||
credentialInterfaces = (credentials.IUsernamePassword,
|
||||
credentials.IUsernameHashedPassword)
|
||||
|
||||
|
||||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ class MaildirError(Exception):
|
|||
pass
|
||||
|
||||
class MaildirBox():
|
||||
|
||||
|
||||
def __init__(self, host):
|
||||
info(_("Plugin Maildir initialization"))
|
||||
self.host = host
|
||||
|
|
@ -184,14 +184,14 @@ class MaildirBox():
|
|||
if idx>box_data['cur_idx']:
|
||||
return None
|
||||
return idx
|
||||
|
||||
|
||||
def getMaxUid(self, boxname, profile):
|
||||
"""Give the max existing uid
|
||||
@param boxname: name of the box where the message is
|
||||
@return: uid"""
|
||||
box_data = self.__getBoxData(boxname, profile)
|
||||
return box_data['cur_idx']
|
||||
|
||||
|
||||
def getIdFromUid(self, boxname, message_uid, profile):
|
||||
"""Return the message unique id from it's integer UID
|
||||
@param boxname: name of the box where the message is
|
||||
|
|
@ -251,9 +251,9 @@ class MaildirBox():
|
|||
"""
|
||||
box_data = self.__getBoxData(boxname, profile)
|
||||
for mess_id in self.getMessageIdsWithFlag(boxname,"\\Deleted", profile):
|
||||
del(box_data[mess_id])
|
||||
del(box_data[mess_id])
|
||||
self.data[profile].force(boxname)
|
||||
|
||||
|
||||
def cleanTable(self, boxname, existant_id, profile):
|
||||
"""Remove mails which no longuer exist from the table
|
||||
@param boxname: name of the box to clean
|
||||
|
|
@ -265,7 +265,7 @@ class MaildirBox():
|
|||
to_remove.append(key)
|
||||
for key in to_remove:
|
||||
del box_data[key]
|
||||
|
||||
|
||||
def addObserver(self, callback, profile, boxname, signal="NEW_MESSAGE"):
|
||||
"""Add an observer for maildir box changes
|
||||
@param callback: method to call when the the box is updated
|
||||
|
|
@ -327,7 +327,7 @@ class MailboxUser:
|
|||
elif e.name == "subject":
|
||||
mail['Subject'] = e.children[0].encode('utf-8')
|
||||
return mail.as_string()
|
||||
|
||||
|
||||
def __init__(self, _maildir, name, observer=None, profile="@NONE@"):
|
||||
"""@param _maildir: the main MaildirBox instance
|
||||
@param name: name of the mailbox
|
||||
|
|
@ -350,7 +350,7 @@ class MailboxUser:
|
|||
self.mailbox = maildir.MaildirMailbox(mailbox_path)
|
||||
self.observer=observer
|
||||
self.__uid_table_update()
|
||||
|
||||
|
||||
if observer:
|
||||
debug("adding observer for %s (%s)" % (name,profile))
|
||||
self.maildir.addObserver(observer, profile, name, "NEW_MESSAGE")
|
||||
|
|
@ -362,7 +362,7 @@ class MailboxUser:
|
|||
existant_id.append(self.getId(mess_idx))
|
||||
self.getUid(mess_idx)
|
||||
self.maildir.cleanTable(self.name, existant_id, profile=self.profile)
|
||||
|
||||
|
||||
|
||||
def __del__(self):
|
||||
if observer:
|
||||
|
|
@ -417,7 +417,7 @@ class MailboxUser:
|
|||
if self.getUid(mess_idx) == mess_uid:
|
||||
return mess_idx
|
||||
raise IndexError
|
||||
|
||||
|
||||
def getIdxFromId(self, mess_id):
|
||||
"""Return the message index from the unique index
|
||||
@param mess_id: message unique index as given by MaildirMailbox
|
||||
|
|
@ -426,7 +426,7 @@ class MailboxUser:
|
|||
if self.mailbox.getUidl(mess_idx) == mess_id:
|
||||
return mess_idx
|
||||
raise IndexError
|
||||
|
||||
|
||||
def getMessage(self, mess_idx):
|
||||
"""Return the full message
|
||||
@param mess_idx: message index"""
|
||||
|
|
@ -443,7 +443,7 @@ class MailboxUser:
|
|||
@return: list of strings"""
|
||||
id = self.getId(mess_idx)
|
||||
return self.maildir.getFlags(self.name, id, profile=self.profile)
|
||||
|
||||
|
||||
def getFlagsUid(self, mess_uid):
|
||||
"""Return the flags of the message
|
||||
@param mess_uid: message unique identifier
|
||||
|
|
@ -487,4 +487,4 @@ class MailboxUser:
|
|||
"""Delete everything in the .Trash dir"""
|
||||
import shutils
|
||||
pdb.set_trace()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
SAT plugin for managing Quiz game
|
||||
SAT plugin for managing Quiz game
|
||||
Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -133,7 +133,7 @@ class Quiz():
|
|||
for data in game_data:
|
||||
data_elt = domish.Element((None,data))
|
||||
data_elt.addContent(game_data[data])
|
||||
game_data_elt.addChild(data_elt)
|
||||
game_data_elt.addChild(data_elt)
|
||||
return game_data_elt
|
||||
|
||||
def __xml_to_game_data(self, game_data_elt):
|
||||
|
|
@ -161,17 +161,17 @@ class Quiz():
|
|||
score = {}
|
||||
for player in game_data['players']:
|
||||
score[player] = players_data[player]['score']
|
||||
|
||||
|
||||
answer_result_elt = domish.Element((None,'answer_result'))
|
||||
answer_result_elt['player'] = player_answering
|
||||
answer_result_elt['good_answer'] = str(good_answer)
|
||||
|
||||
|
||||
for player in score:
|
||||
score_elt = domish.Element((None,"score"))
|
||||
score_elt['player'] = player
|
||||
score_elt['score'] = str(score[player])
|
||||
answer_result_elt.addChild(score_elt)
|
||||
|
||||
answer_result_elt.addChild(score_elt)
|
||||
|
||||
return answer_result_elt
|
||||
|
||||
def __create_started_elt(self, players):
|
||||
|
|
@ -193,7 +193,7 @@ class Quiz():
|
|||
question_elt['timer'] = str(timer)
|
||||
question_elt.addContent(question)
|
||||
return question_elt
|
||||
|
||||
|
||||
def __start_play(self, room_jid, game_data, profile):
|
||||
"""Start the game (tell to the first player after dealer to play"""
|
||||
game_data['stage'] = "play"
|
||||
|
|
@ -231,14 +231,14 @@ class Quiz():
|
|||
for player in players:
|
||||
self.host.plugins["XEP-0249"].invite(jid.JID(player), room.occupantJID.userhostJID(), {"game":"Quiz"}, profile)
|
||||
self.waiting_inv[_room] = (time(), players) #TODO: remove invitation waiting for too long, using the time data
|
||||
|
||||
|
||||
def after_init(ignore):
|
||||
room_name = "sat_quiz_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key)
|
||||
print "\n\n===> room_name:", room_name
|
||||
muc_service = None
|
||||
for service in self.host.memory.getServerServiceEntities("conference", "text", profile):
|
||||
if not ".irc." in service.userhost():
|
||||
#FIXME:
|
||||
#FIXME:
|
||||
#This awfull ugly hack is here to avoid an issue with openfire: the irc gateway
|
||||
#use "conference/text" identity (instead of "conference/irc"), there is certainly a better way
|
||||
#to manage this, but this hack fill do it for test purpose
|
||||
|
|
@ -247,7 +247,7 @@ class Quiz():
|
|||
if not muc_service:
|
||||
error(_("Can't find a MUC service"))
|
||||
return
|
||||
|
||||
|
||||
_jid, xmlstream = self.host.getJidNStream(profile)
|
||||
d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile).addCallback(quizRoomJoined)
|
||||
|
||||
|
|
@ -355,18 +355,18 @@ class Quiz():
|
|||
game_data["timer"] = reactor.callLater(timer, self.timerExpired, room_jid, profile)
|
||||
game_data["time_left"] = None
|
||||
|
||||
def checkAnswer(self, room_jid, player, answer, profile):
|
||||
def checkAnswer(self, room_jid, player, answer, profile):
|
||||
"""Check if the answer given is right"""
|
||||
game_data = self.games[room_jid.userhost()]
|
||||
players_data = game_data['players_data']
|
||||
good_answer = game_data['question_id'] == "1" and answer=="42"
|
||||
players_data[player]['score'] += 1 if good_answer else -1
|
||||
players_data[player]['score'] = min(9, max(0, players_data[player]['score']))
|
||||
|
||||
|
||||
mess = self.createGameElt(room_jid)
|
||||
mess.firstChildElement().addChild(self.__answer_result(player, good_answer, game_data))
|
||||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
|
||||
|
||||
if good_answer:
|
||||
reactor.callLater(4, self.askQuestion, room_jid, profile)
|
||||
else:
|
||||
|
|
@ -382,7 +382,7 @@ class Quiz():
|
|||
|
||||
for player in players:
|
||||
players_data[player]['game_score'] = 0
|
||||
|
||||
|
||||
new_game_data = {"instructions": _(u"""Bienvenue dans cette partie rapide de quizz, le premier à atteindre le score de 9 remporte le jeu
|
||||
|
||||
Attention, tu es prêt ?""")}
|
||||
|
|
@ -393,20 +393,20 @@ Attention, tu es prêt ?""")}
|
|||
reactor.callLater(10, self.askQuestion, room_jid, profile)
|
||||
|
||||
def quiz_game_cmd(self, mess_elt, profile):
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
room_jid = jid.JID(from_jid.userhost())
|
||||
game_elt = mess_elt.firstChildElement()
|
||||
game_data = self.games[room_jid.userhost()]
|
||||
players_data = game_data['players_data']
|
||||
|
||||
|
||||
for elt in game_elt.elements():
|
||||
|
||||
|
||||
if elt.name == 'started': #new game created
|
||||
players = []
|
||||
for player in elt.elements():
|
||||
players.append(unicode(player))
|
||||
self.host.bridge.quizGameStarted(room_jid.userhost(), from_jid.full(), players, profile)
|
||||
|
||||
|
||||
elif elt.name == 'player_ready': #ready to play
|
||||
player = elt['player']
|
||||
status = self.games[room_jid.userhost()]['status']
|
||||
|
|
@ -418,10 +418,10 @@ Attention, tu es prêt ?""")}
|
|||
|
||||
elif elt.name == 'game_data':
|
||||
self.host.bridge.quizGameNew(room_jid.userhost(), self.__xml_to_game_data(elt), profile)
|
||||
|
||||
|
||||
elif elt.name == 'question': #A question is asked
|
||||
self.host.bridge.quizGameQuestion(room_jid.userhost(), elt["id"], unicode(elt), int(elt["timer"]), profile )
|
||||
|
||||
|
||||
elif elt.name == 'player_answer':
|
||||
player = elt['player']
|
||||
pause = game_data['stage'] == 'question' #we pause the game only if we are have a question at the moment
|
||||
|
|
@ -429,7 +429,7 @@ Attention, tu es prêt ?""")}
|
|||
mess = self.createGameElt(room_jid)
|
||||
buzzer_elt = mess.firstChildElement().addElement('player_buzzed')
|
||||
buzzer_elt['player'] = player
|
||||
buzzer_elt['pause'] = str(pause)
|
||||
buzzer_elt['pause'] = str(pause)
|
||||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
if pause:
|
||||
self.pauseTimer(room_jid)
|
||||
|
|
@ -442,17 +442,17 @@ Attention, tu es prêt ?""")}
|
|||
say_elt['delay'] = "3"
|
||||
reactor.callLater(2, self.host.profiles[profile].xmlstream.send, mess)
|
||||
reactor.callLater(6, self.checkAnswer, room_jid, player, _answer, profile=profile)
|
||||
|
||||
|
||||
elif elt.name == 'player_buzzed':
|
||||
self.host.bridge.quizGamePlayerBuzzed(room_jid.userhost(), elt["player"], elt['pause'] == str(True), profile)
|
||||
|
||||
|
||||
elif elt.name == 'player_says':
|
||||
self.host.bridge.quizGamePlayerSays(room_jid.userhost(), elt["player"], unicode(elt), int(elt["delay"]), profile)
|
||||
|
||||
|
||||
elif elt.name == 'answer_result':
|
||||
player, good_answer, score = self.__answer_result_to_signal_args(elt)
|
||||
self.host.bridge.quizGameAnswerResult(room_jid.userhost(), player, good_answer, score, profile)
|
||||
|
||||
|
||||
elif elt.name == 'timer_expired':
|
||||
self.host.bridge.quizGameTimerExpired(room_jid.userhost(), profile)
|
||||
|
||||
|
|
@ -461,13 +461,13 @@ Attention, tu es prêt ?""")}
|
|||
|
||||
else:
|
||||
error (_('Unmanaged game element: %s') % elt.name)
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return QuizGameHandler(self)
|
||||
|
||||
class QuizGameHandler (XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
SAT plugin for managing Radiocol
|
||||
SAT plugin for managing Radiocol
|
||||
Copyright (C) 2009, 2010, 2011, 2012, 2013 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -80,7 +80,7 @@ class Radiocol():
|
|||
elt["type"] = type
|
||||
elt.addElement((NC_RADIOCOL, RADIOC_TAG))
|
||||
return elt
|
||||
|
||||
|
||||
def __create_started_elt(self):
|
||||
"""Create a game_started domish element"""
|
||||
started_elt = domish.Element((None,'started'))
|
||||
|
|
@ -122,14 +122,14 @@ class Radiocol():
|
|||
self.radiocolCreate(_room_jid.userhost(), profile_key=profile)
|
||||
for occupant in occupants:
|
||||
self.host.plugins["XEP-0249"].invite(jid.JID(occupant), room.occupantJID.userhostJID(), {"game":"Radiocol"}, profile)
|
||||
|
||||
|
||||
def after_init(ignore):
|
||||
room_name = "sat_radiocol_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key)
|
||||
print "\n\n===> room_name:", room_name
|
||||
muc_service = None
|
||||
for service in self.host.memory.getServerServiceEntities("conference", "text", profile):
|
||||
if not ".irc." in service.userhost():
|
||||
#FIXME:
|
||||
#FIXME:
|
||||
#This awfull ugly hack is here to avoid an issue with openfire: the irc gateway
|
||||
#use "conference/text" identity (instead of "conference/irc"), there is certainly a better way
|
||||
#to manage this, but this hack fill do it for test purpose
|
||||
|
|
@ -138,7 +138,7 @@ class Radiocol():
|
|||
if not muc_service:
|
||||
error(_("Can't find a MUC service"))
|
||||
return
|
||||
|
||||
|
||||
_jid, xmlstream = self.host.getJidNStream(profile)
|
||||
d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile)
|
||||
d.addCallback(radiocolRoomJoined)
|
||||
|
|
@ -184,7 +184,7 @@ class Radiocol():
|
|||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
error(_("Can't access profile's data"))
|
||||
return
|
||||
return
|
||||
try:
|
||||
song = OggVorbis(song_path)
|
||||
except OggVorbisHeaderError:
|
||||
|
|
@ -213,7 +213,7 @@ class Radiocol():
|
|||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
|
||||
radio_data = self.radios[jid.JID(referee).userhost()] #FIXME: referee comes from Libervia's client side, it's unsecure
|
||||
radio_data['to_delete'][filename] = song_path #FIXME: works only because of the same host trick, see the note under the docstring
|
||||
radio_data['to_delete'][filename] = song_path #FIXME: works only because of the same host trick, see the note under the docstring
|
||||
|
||||
def playNext(self, room_jid, profile):
|
||||
""""Play next sont in queue if exists, and put a timer
|
||||
|
|
@ -248,22 +248,22 @@ class Radiocol():
|
|||
except KeyError:
|
||||
error(_("INTERNAL ERROR: can't find full path of the song to delete"))
|
||||
return
|
||||
|
||||
#we wait more than the song length to delete the file, to manage poorly reactive networks/clients
|
||||
|
||||
#we wait more than the song length to delete the file, to manage poorly reactive networks/clients
|
||||
reactor.callLater(length + 90, unlink, file_to_delete) #FIXME: same host trick (see above)
|
||||
|
||||
|
||||
def radiocol_game_cmd(self, mess_elt, profile):
|
||||
#FIXME: we should check sender (is it referee ?) here before accepting commands
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
room_jid = jid.JID(from_jid.userhost())
|
||||
radio_elt = mess_elt.firstChildElement()
|
||||
radio_data = self.radios[room_jid.userhost()]
|
||||
occupants_data = radio_data['occupants_data']
|
||||
queue = radio_data['queue']
|
||||
|
||||
|
||||
for elt in radio_elt.elements():
|
||||
|
||||
|
||||
if elt.name == 'started': #new game created
|
||||
self.host.bridge.radiocolStarted(room_jid.userhost(), from_jid.full(), profile)
|
||||
elif elt.name == 'preload': #a song is in queue and must be preloaded
|
||||
|
|
@ -279,7 +279,7 @@ class Radiocol():
|
|||
elif elt.name == 'song_added': #a song has been added
|
||||
#FIXME: we are KISS for the proof of concept: every song is added, to a limit of 3 in queue.
|
||||
# Need to manage some sort of rules to allow peoples to send songs
|
||||
|
||||
|
||||
if len(queue) >= QUEUE_LIMIT:
|
||||
#there are already too many songs in queue, we reject this one
|
||||
mess = self.createRadiocolElt(room_jid)
|
||||
|
|
@ -289,7 +289,7 @@ class Radiocol():
|
|||
#FIXME: add an error code
|
||||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
return
|
||||
|
||||
|
||||
#The song is accepted and added in queue
|
||||
queue.append((elt['filename'], float(elt['length'])))
|
||||
|
||||
|
|
@ -317,13 +317,13 @@ class Radiocol():
|
|||
self.playNext(room_jid, profile)
|
||||
else:
|
||||
error (_('Unmanaged game element: %s') % elt.name)
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return RadiocolHandler(self)
|
||||
|
||||
class RadiocolHandler (XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
class SMTP_server():
|
||||
|
||||
|
||||
params = """
|
||||
<params>
|
||||
<general>
|
||||
|
|
@ -64,13 +64,13 @@ class SMTP_server():
|
|||
def __init__(self, host):
|
||||
info(_("Plugin SMTP Server initialization"))
|
||||
self.host = host
|
||||
|
||||
|
||||
#parameters
|
||||
host.memory.importParams(self.params)
|
||||
|
||||
port = int(self.host.memory.getParamA("SMTP Port", "Mail Server"))
|
||||
info(_("Launching SMTP server on port %d"), port)
|
||||
|
||||
|
||||
self.server_factory = SmtpServerFactory(self.host)
|
||||
reactor.listenTCP(port, self.server_factory)
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class SatSmtpMessage:
|
|||
self.host=host
|
||||
self.profile=profile
|
||||
self.message=[]
|
||||
|
||||
|
||||
def lineReceived(self, line):
|
||||
"""handle another line"""
|
||||
self.message.append(line)
|
||||
|
|
@ -167,7 +167,7 @@ class SatProfileCredentialChecker:
|
|||
credentialInterfaces = (credentials.IUsernamePassword,
|
||||
credentials.IUsernameHashedPassword)
|
||||
|
||||
|
||||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
|
||||
|
|
@ -203,7 +203,7 @@ class SmtpServerFactory(smtp.SMTPFactory):
|
|||
def clientConnectionLost(self, connector, reason):
|
||||
debug (_("SMTP server connection lost (reason: %s)"), reason)
|
||||
smtp.SMTPFactory.clientConnectionLost(self, connector, reason)
|
||||
|
||||
|
||||
def buildProtocol(self, addr):
|
||||
p = smtp.SMTPFactory.buildProtocol(self, addr)
|
||||
# add the challengers from imap4, more secure and complicated challengers are available
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ class Tarot():
|
|||
card_elt = domish.Element((None,'card'))
|
||||
card_elt['suit'] = card.suit
|
||||
card_elt['value'] = card.value
|
||||
cards_list_elt.addChild(card_elt)
|
||||
cards_list_elt.addChild(card_elt)
|
||||
return cards_list_elt
|
||||
|
||||
def __xml_to_list(self, cards_list_elt):
|
||||
|
|
@ -107,7 +107,7 @@ class Tarot():
|
|||
for card in cards_list_elt.elements():
|
||||
cards_list.append((card['suit'], card['value']))
|
||||
return cards_list
|
||||
|
||||
|
||||
|
||||
def __create_started_elt(self, players):
|
||||
"""Create a game_started domish element"""
|
||||
|
|
@ -164,7 +164,7 @@ class Tarot():
|
|||
error_elt.addChild(played_elt)
|
||||
error_elt.addChild(invalid_elt)
|
||||
return error_elt
|
||||
|
||||
|
||||
def __next_player(self, game_data, next_pl = None):
|
||||
"""Increment player number & return player name
|
||||
@param next_pl: if given, then next_player is forced to this one
|
||||
|
|
@ -180,7 +180,7 @@ class Tarot():
|
|||
"""give the nick of the player who win this trick"""
|
||||
players_data = game_data['players_data']
|
||||
first = game_data['first_player']
|
||||
first_idx = game_data['players'].index(first)
|
||||
first_idx = game_data['players'].index(first)
|
||||
suit_asked = None
|
||||
strongest = None
|
||||
winner = None
|
||||
|
|
@ -225,19 +225,19 @@ class Tarot():
|
|||
if not excuse in played:
|
||||
#the Excuse is not on the table, nothing to do
|
||||
return
|
||||
|
||||
|
||||
excuse_player = None #Who has played the Excuse ?
|
||||
for player in game_data['players']:
|
||||
if players_data[player]['played'] == excuse:
|
||||
excuse_player = player
|
||||
break
|
||||
|
||||
|
||||
if excuse_player == winner:
|
||||
return #the excuse player win the trick, nothing to do
|
||||
|
||||
|
||||
#first we remove the excuse from played cards
|
||||
played.remove(excuse)
|
||||
#then we give it back to the original owner
|
||||
#then we give it back to the original owner
|
||||
owner_levees = players_data[excuse_player]['levees']
|
||||
owner_levees.append(excuse)
|
||||
#finally we give a low card to the trick winner
|
||||
|
|
@ -267,10 +267,10 @@ class Tarot():
|
|||
for player in game_data['players']:
|
||||
scores_str+=_("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player':player, 'score_game':0, 'total_score': players_data[player]['score']}
|
||||
debug(scores_str)
|
||||
|
||||
|
||||
return (scores_str, [], [])
|
||||
|
||||
|
||||
|
||||
def __calculate_scores(self, game_data):
|
||||
"""The game is finished, time to know who won :)
|
||||
@param game_data: data of the game
|
||||
|
|
@ -285,7 +285,7 @@ class Tarot():
|
|||
nb_bouts +=1
|
||||
bouts.append(card.value)
|
||||
score += card.points
|
||||
|
||||
|
||||
#We we do a basic check on score calculation
|
||||
check_score = 0
|
||||
defenseurs = game_data['players'][:]
|
||||
|
|
@ -297,7 +297,7 @@ class Tarot():
|
|||
for card in game_data['chien']:
|
||||
check_score+=card.points
|
||||
assert (score + check_score == 91)
|
||||
|
||||
|
||||
point_limit = None
|
||||
if nb_bouts == 3:
|
||||
point_limit = 36
|
||||
|
|
@ -340,7 +340,7 @@ class Tarot():
|
|||
for player in game_data['players']:
|
||||
scores_str+=_("\n--\n%(player)s:\nscore for this game ==> %(score_game)i\ntotal score ==> %(total_score)i") % {'player':player, 'score_game':player_score[player], 'total_score': players_data[player]['score']}
|
||||
debug(scores_str)
|
||||
|
||||
|
||||
return (scores_str, winners, loosers)
|
||||
|
||||
def __invalid_cards(self, game_data, cards):
|
||||
|
|
@ -437,7 +437,7 @@ class Tarot():
|
|||
for player in players:
|
||||
self.host.plugins["XEP-0249"].invite(jid.JID(player), room.occupantJID.userhostJID(), {"game":"Tarot"}, profile)
|
||||
self.waiting_inv[_room] = (time(), players) #TODO: remove invitation waiting for too long, using the time data
|
||||
|
||||
|
||||
def after_init(ignore):
|
||||
room_name = "sat_tarot_%s" % self.host.plugins["XEP-0045"].getUniqueName(profile_key)
|
||||
print "\n\n===> room_name:", room_name
|
||||
|
|
@ -445,7 +445,7 @@ class Tarot():
|
|||
muc_service = None
|
||||
for service in self.host.memory.getServerServiceEntities("conference", "text", profile):
|
||||
if not ".irc." in service.userhost():
|
||||
#FIXME:
|
||||
#FIXME:
|
||||
#This awfull ugly hack is here to avoid an issue with openfire: the irc gateway
|
||||
#use "conference/text" identity (instead of "conference/irc"), there is certainly a better way
|
||||
#to manage this, but this hack fill do it for test purpose
|
||||
|
|
@ -454,7 +454,7 @@ class Tarot():
|
|||
if not muc_service:
|
||||
error(_("Can't find a MUC service"))
|
||||
return
|
||||
|
||||
|
||||
_jid, xmlstream = self.host.getJidNStream(profile)
|
||||
d = self.host.plugins["XEP-0045"].join(jid.JID("%s@%s" % (room_name, muc_service.userhost())), _jid.user, {}, profile).addCallback(tarotRoomJoined)
|
||||
|
||||
|
|
@ -580,23 +580,23 @@ class Tarot():
|
|||
mess = self.createGameElt(to_jid)
|
||||
mess.firstChildElement().addChild(self.__ask_contrat())
|
||||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
|
||||
|
||||
|
||||
def card_game_cmd(self, mess_elt, profile):
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
from_jid = jid.JID(mess_elt['from'])
|
||||
room_jid = jid.JID(from_jid.userhost())
|
||||
game_elt = mess_elt.firstChildElement()
|
||||
game_data = self.games[room_jid.userhost()]
|
||||
players_data = game_data['players_data']
|
||||
|
||||
|
||||
for elt in game_elt.elements():
|
||||
|
||||
|
||||
if elt.name == 'started': #new game created
|
||||
players = []
|
||||
for player in elt.elements():
|
||||
players.append(unicode(player))
|
||||
self.host.bridge.tarotGameStarted(room_jid.userhost(), from_jid.full(), players, profile)
|
||||
|
||||
|
||||
elif elt.name == 'player_ready': #ready to play
|
||||
player = elt['player']
|
||||
status = self.games[room_jid.userhost()]['status']
|
||||
|
|
@ -605,7 +605,7 @@ class Tarot():
|
|||
debug (_('Player %(player)s is ready to start [status: %(status)s]') % {'player':player, 'status':status})
|
||||
if status.values().count('ready') == nb_players: #everybody is ready, we can start the game
|
||||
self.newGame(room_jid, profile)
|
||||
|
||||
|
||||
elif elt.name == 'hand': #a new hand has been received
|
||||
self.host.bridge.tarotGameNew(room_jid.userhost(), self.__xml_to_list(elt), profile)
|
||||
|
||||
|
|
@ -613,7 +613,7 @@ class Tarot():
|
|||
form = data_form.Form.fromElement(elt.firstChildElement())
|
||||
xml_data = dataForm2xml(form)
|
||||
self.host.bridge.tarotGameChooseContrat(room_jid.userhost(), xml_data, profile)
|
||||
|
||||
|
||||
elif elt.name == 'contrat_choosed':
|
||||
#TODO: check we receive the contrat from the right person
|
||||
#TODO: use proper XEP-0004 way for answering form
|
||||
|
|
@ -648,7 +648,7 @@ class Tarot():
|
|||
return
|
||||
debug (_("%(player)s win the bid with %(contrat)s") % {'player':best_contrat[0],'contrat':best_contrat[1]})
|
||||
game_data['contrat'] = best_contrat[1]
|
||||
|
||||
|
||||
if game_data['contrat'] == "Garde Sans" or game_data['contrat'] == "Garde Contre":
|
||||
self.__start_play(room_jid, game_data, profile)
|
||||
game_data['attaquant'] = best_contrat[0]
|
||||
|
|
@ -662,7 +662,7 @@ class Tarot():
|
|||
#the attacker (attaquant) get the chien
|
||||
game_data['hand'][best_contrat[0]].extend(game_data['chien'])
|
||||
del game_data['chien'][:]
|
||||
|
||||
|
||||
if game_data['contrat'] == "Garde Sans":
|
||||
#The chien go into attaquant's (attacker) levees
|
||||
players_data[best_contrat[0]]['levees'].extend(game_data['chien'])
|
||||
|
|
@ -693,13 +693,13 @@ class Tarot():
|
|||
players_data[elt['player']]['levees'].extend(list_cards) #we add the chien to attaquant's levées
|
||||
for card in list_cards:
|
||||
game_data['hand'][elt['player']].remove(card)
|
||||
|
||||
|
||||
self.__start_play(room_jid, game_data, profile)
|
||||
|
||||
|
||||
elif game_data['stage'] == "play":
|
||||
current_player = game_data['players'][game_data['current_player']]
|
||||
cards = TarotCard.from_tuples(self.__xml_to_list(elt))
|
||||
|
||||
|
||||
if mess_elt['type'] == 'groupchat':
|
||||
self.host.bridge.tarotGameCardsPlayed(room_jid.userhost(), elt['player'], self.__xml_to_list(elt), profile)
|
||||
else:
|
||||
|
|
@ -719,7 +719,7 @@ class Tarot():
|
|||
mess = self.createGameElt(room_jid)
|
||||
playcard_elt = mess.firstChildElement().addChild(elt)
|
||||
self.host.profiles[profile].xmlstream.send(mess)
|
||||
|
||||
|
||||
#Did everybody played ?
|
||||
played = [players_data[player]['played'] for player in game_data['players']]
|
||||
if all(played):
|
||||
|
|
@ -776,13 +776,13 @@ class Tarot():
|
|||
error (_('Unmanaged error type: %s') % elt['type'])
|
||||
else:
|
||||
error (_('Unmanaged card game element: %s') % elt.name)
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return CardGameHandler(self)
|
||||
|
||||
class CardGameHandler (XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
|
|
|||
|
|
@ -89,29 +89,29 @@ class TextCommands():
|
|||
def cmd_nick(self, mess_data, profile):
|
||||
"""change nickname"""
|
||||
debug("Catched nick command")
|
||||
|
||||
|
||||
if mess_data['type'] != "groupchat":
|
||||
#/nick command does nothing if we are not on a group chat
|
||||
info("Ignoring /nick command on a non groupchat message")
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
nick = mess_data["unparsed"].strip()
|
||||
room = mess_data["to"]
|
||||
|
||||
self.host.plugins["XEP-0045"].nick(room,nick,profile)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def cmd_join(self, mess_data, profile):
|
||||
"""join a new room (on the same service if full jid is not specified)"""
|
||||
debug("Catched join command")
|
||||
|
||||
|
||||
if mess_data['type'] != "groupchat":
|
||||
#/leave command does nothing if we are not on a group chat
|
||||
info("Ignoring /join command on a non groupchat message")
|
||||
return True
|
||||
|
||||
|
||||
if mess_data["unparsed"].strip():
|
||||
room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
|
||||
nick = (self.host.plugins["XEP-0045"].getRoomNick(mess_data["to"].userhost(), profile) or
|
||||
|
|
@ -123,14 +123,14 @@ class TextCommands():
|
|||
def cmd_leave(self, mess_data, profile):
|
||||
"""quit a room"""
|
||||
debug("Catched leave command")
|
||||
|
||||
|
||||
if mess_data['type'] != "groupchat":
|
||||
#/leave command does nothing if we are not on a group chat
|
||||
info("Ignoring /leave command on a non groupchat message")
|
||||
return True
|
||||
|
||||
|
||||
if mess_data["unparsed"].strip():
|
||||
room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
|
||||
room = self._getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
|
||||
else:
|
||||
room = mess_data["to"]
|
||||
|
||||
|
|
@ -145,14 +145,14 @@ class TextCommands():
|
|||
def cmd_title(self, mess_data, profile):
|
||||
"""change room's subject"""
|
||||
debug("Catched title command")
|
||||
|
||||
|
||||
if mess_data['type'] != "groupchat":
|
||||
#/leave command does nothing if we are not on a group chat
|
||||
info("Ignoring /title command on a non groupchat message")
|
||||
return True
|
||||
|
||||
|
||||
subject = mess_data["unparsed"].strip()
|
||||
|
||||
|
||||
if subject:
|
||||
room = mess_data["to"]
|
||||
self.host.plugins["XEP-0045"].subject(room, subject, profile)
|
||||
|
|
@ -167,9 +167,9 @@ class TextCommands():
|
|||
"""activate Parrot mode between 2 entities, in both directions."""
|
||||
#TODO: these commands must not be hardcoded, an interface should be made
|
||||
# to allow plugins to register simple commands like this.
|
||||
|
||||
|
||||
debug("Catched parrot command")
|
||||
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
|
|
@ -184,13 +184,13 @@ class TextCommands():
|
|||
self.host.plugins["EXP-PARROT"].addParrot(link_right_jid, link_left_jid, profile)
|
||||
|
||||
self._feedBack("Parrot mode activated for %s" % (unicode(link_left_jid),), mess_data, profile)
|
||||
|
||||
|
||||
return False
|
||||
|
||||
def cmd_unparrot(self, mess_data, profile):
|
||||
"""remove Parrot mode between 2 entities, in both directions."""
|
||||
debug("Catched unparrot command")
|
||||
|
||||
|
||||
try:
|
||||
link_left_jid = jid.JID(mess_data["unparsed"].strip())
|
||||
if not link_left_jid.user or not link_left_jid.host:
|
||||
|
|
@ -205,7 +205,7 @@ class TextCommands():
|
|||
self.host.plugins["EXP-PARROT"].removeParrot(link_right_jid, profile)
|
||||
|
||||
self._feedBack("Parrot mode deactivated for %s and %s" % (unicode(link_left_jid), unicode(link_right_jid)), mess_data, profile)
|
||||
|
||||
|
||||
return False
|
||||
|
||||
def cmd_help(self, mess_data, profile):
|
||||
|
|
@ -213,7 +213,7 @@ class TextCommands():
|
|||
commands=filter(lambda method: method.startswith('cmd_'), dir(self))
|
||||
longuest = max([len(command) for command in commands])
|
||||
help_cmds = []
|
||||
|
||||
|
||||
for command in commands:
|
||||
method = getattr(self, command)
|
||||
try:
|
||||
|
|
@ -223,7 +223,7 @@ class TextCommands():
|
|||
spaces = (longuest - len(command)) * ' '
|
||||
help_cmds.append(" /%s: %s %s" % (command[4:], spaces, help_str))
|
||||
|
||||
help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),)
|
||||
help_mess = _(u"Text commands available:\n%s") % (u'\n'.join(help_cmds),)
|
||||
self._feedBack(help_mess, mess_data, profile)
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
SàT plugin for managing raw XML log
|
||||
SàT plugin for managing raw XML log
|
||||
Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -50,10 +50,10 @@ class LoggingXmlStream(XmlStream):
|
|||
def dataReceived(self, data):
|
||||
self._host.bridge.xmlLog("IN", data.decode('utf-8'), self._profile)
|
||||
return XmlStream.dataReceived(self, data)
|
||||
|
||||
|
||||
|
||||
class XmlLog():
|
||||
|
||||
|
||||
params = """
|
||||
<params>
|
||||
<general>
|
||||
|
|
@ -67,18 +67,18 @@ class XmlLog():
|
|||
def __init__(self, host):
|
||||
info(_("Plugin XML Log initialization"))
|
||||
self.host = host
|
||||
|
||||
|
||||
#parameters
|
||||
host.memory.importParams(self.params)
|
||||
|
||||
|
||||
#bridge
|
||||
host.bridge.addSignal("xmlLog", ".plugin", signature='sss') #args: direction("IN" or "OUT"), xml_data, profile
|
||||
|
||||
|
||||
do_log = self.host.memory.getParamA("Xml log", "Debug")
|
||||
if do_log:
|
||||
info(_("XML log activated"))
|
||||
host.trigger.add("XML Initialized", self.logXml)
|
||||
|
||||
|
||||
def logXml(self, xmlstream, profile):
|
||||
xmlstream.__class__ = LoggingXmlStream
|
||||
xmlstream._profile = profile
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class XEP_0020():
|
|||
|
||||
def __init__(self, host):
|
||||
info(_("Plugin XEP_0020 initialization"))
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return XEP_0020_handler()
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ class XEP_0020():
|
|||
|
||||
class XEP_0020_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||
return [disco.DiscoFeature(NS_FEATURE_NEG)]
|
||||
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ class XEP_0045():
|
|||
# we have a nickname conflict, we try again with "_" suffixed to current nickname
|
||||
nick += '_'
|
||||
return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
|
||||
|
||||
|
||||
mess = _("Error when joining the room")
|
||||
error (mess)
|
||||
self.host.bridge.newAlert(mess, _("Group chat error"), "ERROR", profile)
|
||||
|
|
@ -131,14 +131,14 @@ class XEP_0045():
|
|||
if not self.__check_profile(profile) or not self.clients[profile].joined_rooms.has_key(room_jid_s):
|
||||
return ''
|
||||
return self.clients[profile].joined_rooms[room_jid_s].nick
|
||||
|
||||
|
||||
def isNickInRoom(self, room_jid, nick, profile):
|
||||
"""Tell if a nick is currently present in a room"""
|
||||
profile = self.host.memory.getProfileName(profile)
|
||||
if not self.__check_profile(profile):
|
||||
raise exceptions.UnknownProfileError("Unknown or disconnected profile")
|
||||
if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].joined_rooms[room_jid.userhost()].inRoster(nick)
|
||||
|
||||
def getRoomsSubjects(self, profile_key='@DEFAULT@'):
|
||||
|
|
@ -152,7 +152,7 @@ class XEP_0045():
|
|||
"""Return unique name for room, avoiding collision"""
|
||||
#TODO: we should use #RFC-0045 10.1.4 when available here
|
||||
#TODO: we should be able to select the MUC service here
|
||||
return uuid.uuid1()
|
||||
return uuid.uuid1()
|
||||
|
||||
def join(self, room_jid, nick, options, profile_key='@DEFAULT@'):
|
||||
def _errDeferred(exc_obj = Exception, txt='Error while joining room'):
|
||||
|
|
@ -162,15 +162,15 @@ class XEP_0045():
|
|||
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not self.__check_profile(profile):
|
||||
return _errDeferred()
|
||||
return _errDeferred()
|
||||
if self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
|
||||
warning(_('%(profile)s is already in room %(room_jid)s') % {'profile':profile, 'room_jid':room_jid.userhost()})
|
||||
return _errDeferred()
|
||||
return _errDeferred()
|
||||
info (_("[%(profile)s] is joining room %(room)s with nick %(nick)s") % {'profile':profile,'room':room_jid.userhost(), 'nick':nick})
|
||||
|
||||
history_options = options["history"] == "True" if options.has_key("history") else None
|
||||
password = options["password"] if options.has_key("password") else None
|
||||
|
||||
|
||||
return self.clients[profile].join(room_jid, nick, history_options, password).addCallbacks(self.__room_joined, self.__err_joining_room, callbackKeywords={'profile':profile}, errbackArgs=[room_jid, nick, history_options, password, profile])
|
||||
|
||||
def _join(self, room_jid_s, nick, options={}, profile_key='@DEFAULT@'):
|
||||
|
|
@ -193,23 +193,23 @@ class XEP_0045():
|
|||
if not self.__check_profile(profile):
|
||||
raise exceptions.UnknownProfileError("Unknown or disconnected profile")
|
||||
if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].nick(room_jid, nick)
|
||||
|
||||
def leave(self, room_jid, profile_key):
|
||||
|
||||
def leave(self, room_jid, profile_key):
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not self.__check_profile(profile):
|
||||
raise exceptions.UnknownProfileError("Unknown or disconnected profile")
|
||||
if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].leave(room_jid)
|
||||
|
||||
def subject(self, room_jid, subject, profile_key):
|
||||
def subject(self, room_jid, subject, profile_key):
|
||||
profile = self.host.memory.getProfileName(profile_key)
|
||||
if not self.__check_profile(profile):
|
||||
raise exceptions.UnknownProfileError("Unknown or disconnected profile")
|
||||
if not self.clients[profile].joined_rooms.has_key(room_jid.userhost()):
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
raise UnknownRoom("This room has not been joined")
|
||||
return self.clients[profile].subject(room_jid, subject)
|
||||
|
||||
def mucNick(self, room_jid_s, nick, profile_key='@DEFAULT@'):
|
||||
|
|
@ -227,7 +227,7 @@ class XEP_0045():
|
|||
|
||||
class SatMUCClient (muc.MUCClient):
|
||||
#implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
|
@ -240,7 +240,7 @@ class SatMUCClient (muc.MUCClient):
|
|||
|
||||
def subject(self, room, subject):
|
||||
return muc.MUCClientProtocol.subject(self, room, subject)
|
||||
|
||||
|
||||
def unavailableReceived(self, presence):
|
||||
#XXX: we override this method to manage nickname change
|
||||
#TODO: feed this back to Wokkel
|
||||
|
|
@ -274,9 +274,9 @@ class SatMUCClient (muc.MUCClient):
|
|||
debug (_("user %(nick)s has joined room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
|
||||
if not self.host.trigger.point("MUC user joined", room, user, self.parent.profile):
|
||||
return
|
||||
user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
|
||||
user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
|
||||
self.host.bridge.roomUserJoined(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
|
||||
|
||||
|
||||
def userLeftRoom(self, room, user):
|
||||
if user.nick == room.nick:
|
||||
# we left the room
|
||||
|
|
@ -288,7 +288,7 @@ class SatMUCClient (muc.MUCClient):
|
|||
self.host.bridge.roomLeft(room.roomJID.userhost(), self.parent.profile)
|
||||
else:
|
||||
debug (_("user %(nick)s left room (%(room_id)s)") % {'nick':user.nick, 'room_id':room.occupantJID.userhost()})
|
||||
user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
|
||||
user_data={'entity':user.entity.full() if user.entity else '', 'affiliation':user.affiliation, 'role':user.role}
|
||||
self.host.bridge.roomUserLeft(room.roomJID.userhost(), user.nick, user_data, self.parent.profile)
|
||||
|
||||
def userChangedNick(self, room, user, new_nick):
|
||||
|
|
@ -305,10 +305,10 @@ class SatMUCClient (muc.MUCClient):
|
|||
|
||||
#def connectionInitialized(self):
|
||||
#pass
|
||||
|
||||
|
||||
#def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||
#return [disco.DiscoFeature(NS_VCARD)]
|
||||
|
||||
#def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||
#return []
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -72,13 +72,13 @@ class XEP_0047():
|
|||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
client.xep_0047_current_stream = {} #key: stream_id, value: data(dict)
|
||||
|
||||
|
||||
def _timeOut(self, sid, profile):
|
||||
"""Delecte current_stream id, called after timeout
|
||||
@param id: id of client.xep_0047_current_stream"""
|
||||
info(_("In-Band Bytestream: TimeOut reached for id %s [%s]") % (sid, profile))
|
||||
self._killId(sid, False, "TIMEOUT", profile)
|
||||
|
||||
|
||||
def _killId(self, sid, success=False, failure_reason="UNKNOWN", profile=None):
|
||||
"""Delete an current_stream id, clean up associated observers
|
||||
@param sid: id of client.xep_0047_current_stream"""
|
||||
|
|
@ -96,18 +96,18 @@ class XEP_0047():
|
|||
client.xep_0047_current_stream[sid]['timer'].cancel()
|
||||
if client.xep_0047_current_stream[sid].has_key("size"):
|
||||
self.host.removeProgressCB(sid, profile)
|
||||
|
||||
|
||||
file_obj = client.xep_0047_current_stream[sid]['file_obj']
|
||||
success_cb = client.xep_0047_current_stream[sid]['success_cb']
|
||||
failure_cb = client.xep_0047_current_stream[sid]['failure_cb']
|
||||
|
||||
|
||||
del client.xep_0047_current_stream[sid]
|
||||
|
||||
if success:
|
||||
success_cb(sid, file_obj, NS_IBB, profile)
|
||||
else:
|
||||
failure_cb(sid, file_obj, NS_IBB, failure_reason, profile)
|
||||
|
||||
|
||||
def getProgress(self, sid, data, profile):
|
||||
"""Fill data with position of current transfer"""
|
||||
client = self.host.getClient(profile)
|
||||
|
|
@ -119,7 +119,7 @@ class XEP_0047():
|
|||
data["size"] = str(client.xep_0047_current_stream[sid]["size"])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def prepareToReceive(self, from_jid, sid, file_obj, size, success_cb, failure_cb, profile):
|
||||
"""Called when a bytestream is imminent
|
||||
@param from_jid: jid of the sender
|
||||
|
|
@ -174,7 +174,7 @@ class XEP_0047():
|
|||
|
||||
#we save the xmlstream, events and observer data to allow observer removal
|
||||
client.xep_0047_current_stream[sid]["event_data"] = event_data = (IBB_MESSAGE_DATA if stanza=='message' else IBB_IQ_DATA) % sid
|
||||
client.xep_0047_current_stream[sid]["observer_cb"] = observer_cb = self.messageData if stanza=='message' else self.iqData
|
||||
client.xep_0047_current_stream[sid]["observer_cb"] = observer_cb = self.messageData if stanza=='message' else self.iqData
|
||||
event_close = IBB_CLOSE % sid
|
||||
#we now set the stream observer to look after data packet
|
||||
client.xmlstream.addObserver(event_data, observer_cb, profile = profile)
|
||||
|
|
@ -207,16 +207,16 @@ class XEP_0047():
|
|||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
data_elt = IQ.firstChildElement()
|
||||
|
||||
|
||||
if self._manageDataElt(data_elt, 'iq', IQ['id'], jid.JID(IQ['from']), profile):
|
||||
#and send a success answer
|
||||
result = domish.Element((None, 'iq'))
|
||||
result['type'] = 'result'
|
||||
result['id'] = IQ['id']
|
||||
result['to'] = IQ['from']
|
||||
|
||||
|
||||
client.xmlstream.send(result)
|
||||
|
||||
|
||||
def messageData(self, message_elt, profile):
|
||||
data_elt = message_elt.firstChildElement()
|
||||
sid = message_elt.getAttribute('id','')
|
||||
|
|
@ -272,7 +272,7 @@ class XEP_0047():
|
|||
result = domish.Element((None, 'iq'))
|
||||
result['type'] = 'result'
|
||||
result['id'] = iq_id
|
||||
result['to'] = to_jid
|
||||
result['to'] = to_jid
|
||||
error_el = result.addElement('error')
|
||||
error_el['type'] = 'cancel'
|
||||
error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','not-acceptable'))
|
||||
|
|
@ -323,10 +323,10 @@ class XEP_0047():
|
|||
warning(_("Transfer failed"))
|
||||
self.terminateStream(sid, "IQ_ERROR")
|
||||
return
|
||||
|
||||
|
||||
if data['timer'].active():
|
||||
data['timer'].cancel()
|
||||
|
||||
|
||||
buffer = data["file_obj"].read(data["block_size"])
|
||||
if buffer:
|
||||
next_iq_elt = jabber_client.IQ(client.xmlstream,'set')
|
||||
|
|
@ -366,10 +366,10 @@ class XEP_0047():
|
|||
|
||||
class XEP_0047_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self,parent):
|
||||
self.plugin_parent = parent
|
||||
|
||||
|
||||
def connectionInitialized(self):
|
||||
self.xmlstream.addObserver(IBB_OPEN, self.plugin_parent.streamOpening, profile = self.parent.profile)
|
||||
|
||||
|
|
|
|||
|
|
@ -90,9 +90,9 @@ class XEP_0054():
|
|||
x_elt = domish.Element((NS_VCARD_UPDATE, 'x'))
|
||||
x_elt.addElement('photo', content=self.avatars_cache[client.jid.userhost()])
|
||||
presence_elt.addChild(x_elt)
|
||||
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def _fillCachedValues(self, result, client):
|
||||
#FIXME: this is really suboptimal, need to be reworked
|
||||
# the current naive approach keeps a map between all jids of all profiles
|
||||
|
|
@ -101,11 +101,11 @@ class XEP_0054():
|
|||
for _jid in client.roster.getBareJids() + [client.jid.userhost()]:
|
||||
if _jid in self.avatars_cache:
|
||||
self.host.memory.updateEntityData(jid.JID(_jid), "avatar", self.avatars_cache[_jid], client.profile)
|
||||
|
||||
|
||||
def profileConnected(self, profile):
|
||||
client = self.host.getClient(profile)
|
||||
client.roster.got_roster.addCallback(self._fillCachedValues, client)
|
||||
|
||||
|
||||
def update_cache(self, jid, name, value, profile):
|
||||
"""update cache value
|
||||
- save value in memory in case of change
|
||||
|
|
@ -122,7 +122,7 @@ class XEP_0054():
|
|||
self.host.memory.updateEntityData(jid, name, value, profile)
|
||||
if name == "avatar":
|
||||
self.avatars_cache[jid.userhost()] = value
|
||||
|
||||
|
||||
def get_cache(self, jid, name, profile):
|
||||
"""return cached value for jid
|
||||
@param jid: target contact
|
||||
|
|
@ -158,7 +158,7 @@ class XEP_0054():
|
|||
"""Convert a VCard to a dict, and save binaries"""
|
||||
debug (_("parsing vcard"))
|
||||
dictionary = {}
|
||||
|
||||
|
||||
for elem in vcard.elements():
|
||||
if elem.name == 'FN':
|
||||
dictionary['fullname'] = unicode(elem)
|
||||
|
|
@ -170,7 +170,7 @@ class XEP_0054():
|
|||
elif elem.name == 'EMAIL':
|
||||
dictionary['email'] = unicode(elem)
|
||||
elif elem.name == 'BDAY':
|
||||
dictionary['birthday'] = unicode(elem)
|
||||
dictionary['birthday'] = unicode(elem)
|
||||
elif elem.name == 'PHOTO':
|
||||
dictionary["avatar"] = yield threads.deferToThread(self.save_photo, elem)
|
||||
if not dictionary["avatar"]: #can happen in case of e.g. empty photo elem
|
||||
|
|
@ -202,7 +202,7 @@ class XEP_0054():
|
|||
"""Called when something is wrong with registration"""
|
||||
error (_("Can't find VCard of %s") % failure.value.stanza['from'])
|
||||
self.host.bridge.actionResult("SUPPRESS", failure.value.stanza['id'], {}, profile) #FIXME: maybe an error message would be better
|
||||
|
||||
|
||||
def getCard(self, target_s, profile_key='@DEFAULT@'):
|
||||
"""Ask server for VCard
|
||||
@param target_s: jid from which we want the VCard
|
||||
|
|
@ -219,7 +219,7 @@ class XEP_0054():
|
|||
reg_request["to"] = to_jid.userhost()
|
||||
reg_request.addElement('vCard', NS_VCARD)
|
||||
reg_request.send(to_jid.userhost()).addCallbacks(self.vcard_ok, self.vcard_err, callbackArgs=[profile], errbackArgs=[profile])
|
||||
return reg_request["id"]
|
||||
return reg_request["id"]
|
||||
|
||||
def getAvatarFile(self, avatar_hash):
|
||||
"""Give the full path of avatar from hash
|
||||
|
|
@ -258,38 +258,38 @@ class XEP_0054():
|
|||
client = self.host.getClient(profile_key)
|
||||
if not client:
|
||||
raise exceptions.NotConnectedProfileError(_('Trying to set avatar for a non-existant or not connected profile'))
|
||||
|
||||
|
||||
vcard_set = IQ(client.xmlstream,'set')
|
||||
d = threads.deferToThread(self._buildSetAvatar, vcard_set, filepath)
|
||||
|
||||
|
||||
def elementBuilt(result):
|
||||
"""Called once the image is at the right size/format, and the vcard set element is build"""
|
||||
set_avatar_elt, img_hash = result
|
||||
self.avatars_cache[client.jid.userhost()] = img_hash # we need to update the hash, so we can send a new presence
|
||||
# element with the right hash
|
||||
# element with the right hash
|
||||
return set_avatar_elt.send().addCallback(lambda ignore: client.presence.available())
|
||||
|
||||
|
||||
d.addCallback(elementBuilt)
|
||||
|
||||
|
||||
return d
|
||||
|
||||
|
||||
class XEP_0054_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
||||
def connectionInitialized(self):
|
||||
self.xmlstream.addObserver(VCARD_UPDATE, self.update)
|
||||
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||
return [disco.DiscoFeature(NS_VCARD)]
|
||||
|
||||
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||
return []
|
||||
|
||||
|
||||
def update(self, presence):
|
||||
"""Request for VCard's nickname
|
||||
return the cached nickname if exists, else get VCard
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ class XEP_0060():
|
|||
|
||||
def publish(self, service, nodeIdentifier, items=None, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'publish item')
|
||||
return client.publish(service, nodeIdentifier, items, client.parent.jid)
|
||||
return client.publish(service, nodeIdentifier, items, client.parent.jid)
|
||||
|
||||
def getItems(self, service, node, max_items=None, sub_id=None, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'get items')
|
||||
|
|
@ -105,7 +105,7 @@ class XEP_0060():
|
|||
def setOptions(self, service, nodeIdentifier, subscriber, options, subscriptionIdentifier=None, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'set options')
|
||||
return client.setOptions(service, nodeIdentifier, subscriber, options, subscriptionIdentifier)
|
||||
|
||||
|
||||
def createNode(self, service, nodeIdentifier, options, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'create node')
|
||||
return client.createNode(service, nodeIdentifier, options)
|
||||
|
|
@ -113,12 +113,12 @@ class XEP_0060():
|
|||
def deleteNode(self, service, nodeIdentifier, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'delete node')
|
||||
return client.deleteNode(service, nodeIdentifier)
|
||||
|
||||
|
||||
def subscribe(self, service, nodeIdentifier, sub_jid = None, options=None, profile_key='@DEFAULT@'):
|
||||
profile,client = self.__getClientNProfile(profile_key, 'subscribe node')
|
||||
return client.subscribe(service, nodeIdentifier, sub_jid or client.parent.jid.userhostJID(), options=options)
|
||||
return client.subscribe(service, nodeIdentifier, sub_jid or client.parent.jid.userhostJID(), options=options)
|
||||
|
||||
|
||||
|
||||
class SatPubSubClient(pubsub.PubSubClient):
|
||||
implements(disco.IDisco)
|
||||
|
||||
|
|
@ -129,7 +129,7 @@ class SatPubSubClient(pubsub.PubSubClient):
|
|||
|
||||
def connectionInitialized(self):
|
||||
pubsub.PubSubClient.connectionInitialized(self)
|
||||
|
||||
|
||||
def itemsReceived(self, event):
|
||||
if not self.host.trigger.point("PubSubItemsReceived", event, self.parent.profile):
|
||||
return
|
||||
|
|
@ -149,7 +149,7 @@ class SatPubSubClient(pubsub.PubSubClient):
|
|||
_disco_info = []
|
||||
self.host.trigger.point("PubSub Disco Info", _disco_info, self.parent.profile)
|
||||
return _disco_info
|
||||
|
||||
|
||||
def getDiscoItems(self, requestor, target, nodeIdentifier=''):
|
||||
return []
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ license.
|
|||
|
||||
Here is a copy of the original license:
|
||||
|
||||
Copyright (C)
|
||||
Copyright (C)
|
||||
2002-2004 Dave Smith (dizzyd@jabber.org)
|
||||
2007-2008 Fabio Forno (xmpp:ff@jabber.bluendo.com)
|
||||
|
||||
|
|
@ -172,7 +172,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
|
||||
# Trim off front of the buffer
|
||||
self.buf = self.buf[nmethod+2:]
|
||||
|
||||
|
||||
# Check for supported auth mechs
|
||||
for m in self.supportedAuthMechs:
|
||||
if m in methods:
|
||||
|
|
@ -219,7 +219,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
result = struct.pack('!BBBBIH', SOCKS5_VER, errorcode, 0, 1, 0, 0)
|
||||
self.transport.write(result)
|
||||
self.transport.loseConnection()
|
||||
|
||||
|
||||
def _parseRequest(self):
|
||||
debug("_parseRequest")
|
||||
try:
|
||||
|
|
@ -235,7 +235,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
if self.addressType == ADDR_IPV4:
|
||||
addr, port = struct.unpack('!IH', self.buf[4:10])
|
||||
self.buf = self.buf[10:]
|
||||
elif self.addressType == ADDR_DOMAINNAME:
|
||||
elif self.addressType == ADDR_DOMAINNAME:
|
||||
nlen = ord(self.buf[4])
|
||||
addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:])
|
||||
self.buf = self.buf[7 + len(addr):]
|
||||
|
|
@ -282,7 +282,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
if self.addressType == ADDR_IPV4:
|
||||
addr, port = struct.unpack('!IH', self.buf[4:10])
|
||||
self.buf = self.buf[10:]
|
||||
elif self.addressType == ADDR_DOMAINNAME:
|
||||
elif self.addressType == ADDR_DOMAINNAME:
|
||||
nlen = ord(self.buf[4])
|
||||
addr, port = struct.unpack('!%dsH' % nlen, self.buf[5:])
|
||||
self.buf = self.buf[7 + len(addr):]
|
||||
|
|
@ -308,7 +308,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
|
||||
def connectionMade(self):
|
||||
debug("connectionMade (mode = %s)" % "requester" if isinstance(self.factory, Socks5ServerFactory) else "target")
|
||||
|
||||
|
||||
if isinstance(self.factory, Socks5ClientFactory):
|
||||
self.sid = self.factory.sid
|
||||
self.profile = self.factory.profile
|
||||
|
|
@ -318,7 +318,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
|
||||
def connectRequested(self, addr, port):
|
||||
debug("connectRequested")
|
||||
|
||||
|
||||
# Check that this session is expected
|
||||
if not self.factory.hash_sid_map.has_key(addr):
|
||||
#no: we refuse it
|
||||
|
|
@ -336,7 +336,7 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
"""Callback called when the result iq is received"""
|
||||
d = self.beginFileTransfer(file_obj, self.transport)
|
||||
d.addCallback(self.fileTransfered)
|
||||
|
||||
|
||||
def fileTransfered(self, d):
|
||||
info(_("File transfer completed, closing connection"))
|
||||
self.transport.loseConnection()
|
||||
|
|
@ -351,10 +351,10 @@ class SOCKSv5(protocol.Protocol, FileSender):
|
|||
ADDR_DOMAINNAME, len(remotehost), remotehost, remoteport)
|
||||
self.transport.write(result)
|
||||
self.state = STATE_READY
|
||||
|
||||
|
||||
def bindRequested(self, addr, port):
|
||||
pass
|
||||
|
||||
|
||||
def authenticateUserPass(self, user, passwd):
|
||||
debug("User/pass: %s/%s", user, passwd)
|
||||
return True
|
||||
|
|
@ -440,7 +440,7 @@ class Socks5ClientFactory(protocol.ClientFactory):
|
|||
|
||||
|
||||
class XEP_0065():
|
||||
|
||||
|
||||
NAMESPACE = NS_BS
|
||||
|
||||
params = """
|
||||
|
|
@ -463,10 +463,10 @@ class XEP_0065():
|
|||
|
||||
def __init__(self, host):
|
||||
info(_("Plugin XEP_0065 initialization"))
|
||||
|
||||
|
||||
#session data
|
||||
self.hash_sid_map = {} #key: hash of the transfer session, value: (session id, profile)
|
||||
|
||||
|
||||
self.host = host
|
||||
debug(_("registering"))
|
||||
self.server_factory = Socks5ServerFactory(host, self.hash_sid_map, lambda sid, success, profile: self._killId(sid, success, profile=profile))
|
||||
|
|
@ -475,13 +475,13 @@ class XEP_0065():
|
|||
host.memory.importParams(XEP_0065.params)
|
||||
host.memory.setDefault("IP", "File Transfer", self.getExternalIP)
|
||||
port = int(self.host.memory.getParamA("Port", "File Transfer"))
|
||||
|
||||
|
||||
info(_("Launching Socks5 Stream server on port %d"), port)
|
||||
reactor.listenTCP(port, self.server_factory)
|
||||
|
||||
|
||||
def getHandler(self, profile):
|
||||
return XEP_0065_handler(self)
|
||||
|
||||
return XEP_0065_handler(self)
|
||||
|
||||
def profileConnected(self, profile):
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
|
|
@ -503,13 +503,13 @@ class XEP_0065():
|
|||
data["size"] = str(client.xep_0065_current_stream[sid]["size"])
|
||||
except:
|
||||
pass
|
||||
|
||||
|
||||
def _timeOut(self, sid, profile):
|
||||
"""Delecte current_stream id, called after timeout
|
||||
@param id: id of client.xep_0065_current_stream"""
|
||||
info(_("Socks5 Bytestream: TimeOut reached for id %s [%s]") % (sid, profile))
|
||||
self._killId(sid, False, "TIMEOUT", profile)
|
||||
|
||||
|
||||
def _killId(self, sid, success=False, failure_reason="UNKNOWN", profile=None):
|
||||
"""Delete an current_stream id, clean up associated observers
|
||||
@param sid: id of client.xep_0065_current_stream"""
|
||||
|
|
@ -528,11 +528,11 @@ class XEP_0065():
|
|||
client.xep_0065_current_stream[sid]['timer'].cancel()
|
||||
if client.xep_0065_current_stream[sid].has_key("size"):
|
||||
self.host.removeProgressCB(sid, profile)
|
||||
|
||||
|
||||
file_obj = client.xep_0065_current_stream[sid]['file_obj']
|
||||
success_cb = client.xep_0065_current_stream[sid]['success_cb']
|
||||
failure_cb = client.xep_0065_current_stream[sid]['failure_cb']
|
||||
|
||||
|
||||
session_hash = client.xep_0065_current_stream[sid].get('hash')
|
||||
del client.xep_0065_current_stream[sid]
|
||||
if session_hash in self.hash_sid_map:
|
||||
|
|
@ -558,14 +558,14 @@ class XEP_0065():
|
|||
if not client:
|
||||
error(_("Unknown profile, this should not happen"))
|
||||
raise ProfileNotInCacheError
|
||||
|
||||
|
||||
if length != None:
|
||||
error(_('stream length not managed yet'))
|
||||
return
|
||||
|
||||
|
||||
profile_jid = client.jid
|
||||
xmlstream = client.xmlstream
|
||||
|
||||
|
||||
data = client.xep_0065_current_stream[sid] = {}
|
||||
data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile)
|
||||
data["file_obj"] = file_obj
|
||||
|
|
@ -615,10 +615,10 @@ class XEP_0065():
|
|||
except KeyError:
|
||||
error(_("Internal error, can't do transfer"))
|
||||
return
|
||||
|
||||
|
||||
if timer.active():
|
||||
timer.cancel()
|
||||
|
||||
|
||||
profile_jid, xmlstream = self.host.getJidNStream(profile)
|
||||
query_elt = iq_elt.firstChildElement()
|
||||
streamhost_elts = filter(lambda elt: elt.name == 'streamhost-used', query_elt.elements())
|
||||
|
|
@ -686,23 +686,23 @@ class XEP_0065():
|
|||
data["timer"] = reactor.callLater(TIMEOUT, self._timeOut, sid, profile)
|
||||
data["success_cb"] = success_cb
|
||||
data["failure_cb"] = failure_cb
|
||||
|
||||
|
||||
|
||||
|
||||
def streamQuery(self, iq_elt, profile):
|
||||
"""Get file using byte stream"""
|
||||
debug(_("BS stream query"))
|
||||
client = self.host.getClient(profile)
|
||||
|
||||
|
||||
if not client:
|
||||
raise ProfileNotInCacheError
|
||||
|
||||
|
||||
xmlstream = client.xmlstream
|
||||
|
||||
iq_elt.handled = True
|
||||
query_elt = iq_elt.firstChildElement()
|
||||
sid = query_elt.getAttribute("sid")
|
||||
streamhost_elts = filter(lambda elt: elt.name == 'streamhost', query_elt.elements())
|
||||
|
||||
|
||||
if not sid in client.xep_0065_current_stream:
|
||||
warning(_("Ignoring unexpected BS transfer: %s" % sid))
|
||||
self.sendNotAcceptableError(iq_elt['id'], iq_elt['from'], xmlstream)
|
||||
|
|
@ -731,7 +731,7 @@ class XEP_0065():
|
|||
info (_("Stream proposed: host=[%(host)s] port=[%(port)s]") % {'host':sh_host, 'port':sh_port})
|
||||
factory = Socks5ClientFactory(client.xep_0065_current_stream, sid, iq_elt["id"], self.activateStream, lambda sid, success, profile: self._killId(sid, success, profile=profile), profile=profile)
|
||||
reactor.connectTCP(sh_host, int(sh_port), factory)
|
||||
|
||||
|
||||
def activateStream(self, sid, iq_id, profile):
|
||||
client = self.host.getClient(profile)
|
||||
if not client:
|
||||
|
|
@ -757,7 +757,7 @@ class XEP_0065():
|
|||
result = domish.Element((None, 'iq'))
|
||||
result['type'] = 'result'
|
||||
result['id'] = iq_id
|
||||
result['to'] = to_jid
|
||||
result['to'] = to_jid
|
||||
error_el = result.addElement('error')
|
||||
error_el['type'] = 'modify'
|
||||
error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','not-acceptable'))
|
||||
|
|
@ -771,7 +771,7 @@ class XEP_0065():
|
|||
result = domish.Element((None, 'iq'))
|
||||
result['type'] = 'result'
|
||||
result['id'] = iq_id
|
||||
result['to'] = to_jid
|
||||
result['to'] = to_jid
|
||||
error_el = result.addElement('error')
|
||||
error_el['type'] = 'cancel'
|
||||
error_el.addElement(('urn:ietf:params:xml:ns:xmpp-stanzas','bad-request'))
|
||||
|
|
@ -779,7 +779,7 @@ class XEP_0065():
|
|||
|
||||
class XEP_0065_handler(XMPPHandler):
|
||||
implements(iwokkel.IDisco)
|
||||
|
||||
|
||||
def __init__(self, plugin_parent):
|
||||
self.plugin_parent = plugin_parent
|
||||
self.host = plugin_parent.host
|
||||
|
|
@ -805,7 +805,7 @@ class XEP_0065_handler(XMPPHandler):
|
|||
proxy = self.host.memory.setParam("Proxy host", streamhost_elt.getAttribute("host",""), "File Transfer", self.parent.profile)
|
||||
proxy = self.host.memory.setParam("Proxy port", streamhost_elt.getAttribute("port",""), "File Transfer", self.parent.profile)
|
||||
|
||||
|
||||
|
||||
def connectionInitialized(self):
|
||||
def after_init(ignore):
|
||||
proxy_ent = self.host.memory.getServerServiceEntity("proxy", "bytestreams", self.parent.profile)
|
||||
|
|
@ -823,7 +823,7 @@ class XEP_0065_handler(XMPPHandler):
|
|||
proxy = self.host.memory.getParamA("Proxy", "File Transfer", profile_key = self.parent.profile)
|
||||
if not proxy:
|
||||
self.parent.client_initialized.addCallback(after_init)
|
||||
|
||||
|
||||
|
||||
|
||||
def getDiscoInfo(self, requestor, target, nodeIdentifier=''):
|
||||
|
|
|
|||
|
|
@ -39,18 +39,18 @@ PLUGIN_INFO = {
|
|||
}
|
||||
|
||||
class XEP_0077():
|
||||
|
||||
|
||||
def __init__(self, host):
|
||||
info(_("Plugin XEP_0077 initialization"))
|
||||
self.host = host
|
||||
self.triggers = {} #used by other protocol (e.g. XEP-0100) to finish registration. key = target_jid
|
||||
host.bridge.addMethod("in_band_register", ".plugin", in_sign='ss', out_sign='s', method=self.in_band_register)
|
||||
host.bridge.addMethod("in_band_submit", ".plugin", in_sign='ssa(ss)s', out_sign='s', method=self.in_band_submit)
|
||||
|
||||
|
||||
def addTrigger(self, target, cb, profile):
|
||||
"""Add a callback which is called when registration to target is successful"""
|
||||
self.triggers[target] = (cb, profile)
|
||||
|
||||
|
||||
def reg_ok(self, answer, profile):
|
||||
"""Called after the first get IQ"""
|
||||
try:
|
||||
|
|
@ -62,7 +62,7 @@ class XEP_0077():
|
|||
answer_type = "ERROR"
|
||||
self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
|
||||
return
|
||||
|
||||
|
||||
form = data_form.Form.fromElement(x_elem)
|
||||
xml_data = dataForm2xml(form)
|
||||
self.host.bridge.actionResult("XMLUI", answer['id'], {"target":answer["from"], "type":"registration", "xml":xml_data}, profile)
|
||||
|
|
@ -75,13 +75,13 @@ class XEP_0077():
|
|||
answer_data={"message":"%s [code: %s]" % (failure.value.condition, unicode(failure.value))}
|
||||
answer_type = "ERROR"
|
||||
self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
|
||||
|
||||
|
||||
def unregistrationAnswer(self, answer, profile):
|
||||
debug (_("registration answer: %s") % answer.toXml())
|
||||
answer_type = "SUCCESS"
|
||||
answer_data={"message":_("Your are now unregistred")}
|
||||
self.host.bridge.actionResult(answer_type, answer['id'], answer_data, profile)
|
||||
|
||||
|
||||
def unregistrationFailure(self, failure, profile):
|
||||
info (_("Unregistration failure: %s") % str(failure.value))
|
||||
answer_type = "ERROR"
|
||||
|
|
@ -89,7 +89,7 @@ class XEP_0077():
|
|||
answer_data['reason'] = 'unknown'
|
||||
answer_data={"message":_("Unregistration failed: %s") % failure.value.condition}
|
||||
self.host.bridge.actionResult(answer_type, failure.value.stanza['id'], answer_data, profile)
|
||||
|
||||
|
||||
def registrationAnswer(self, answer, profile):
|
||||
debug (_("registration answer: %s") % answer.toXml())
|
||||
answer_type = "SUCCESS"
|
||||
|
|
@ -99,7 +99,7 @@ class XEP_0077():
|
|||
callback,profile = self.triggers[answer["from"]]
|
||||
callback(answer["from"], profile)
|
||||
del self.triggers[answer["from"]]
|
||||
|
||||
|
||||
def registrationFailure(self, failure, profile):
|
||||
info (_("Registration failure: %s") % str(failure.value))
|
||||
print failure.value.stanza.toXml()
|
||||
|
|
@ -120,10 +120,10 @@ class XEP_0077():
|
|||
id, deferred = self.host.submitForm(action, target, fields, profile)
|
||||
if action == 'CANCEL':
|
||||
deferred.addCallbacks(self.unregistrationAnswer, self.unregistrationFailure, callbackArgs=[profile], errbackArgs=[profile])
|
||||
else:
|
||||
else:
|
||||
deferred.addCallbacks(self.registrationAnswer, self.registrationFailure, callbackArgs=[profile], errbackArgs=[profile])
|
||||
return id
|
||||
|
||||
|
||||
def in_band_register(self, target, profile_key='@DEFAULT@'):
|
||||
"""register to a target JID"""
|
||||
client = self.host.getClient(profile_key)
|
||||
|
|
@ -137,4 +137,4 @@ class XEP_0077():
|
|||
reg_request["to"] = to_jid.full()
|
||||
reg_request.addElement('query', NS_REG)
|
||||
reg_request.send(to_jid.full()).addCallbacks(self.reg_ok, self.reg_err, callbackArgs=[client.profile], errbackArgs=[client.profile])
|
||||
return reg_request["id"]
|
||||
return reg_request["id"]
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue