Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mrDoctorWho/vk4xmpp.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Smith <mrdoctorwho@gmail.com>2016-12-25 12:08:59 +0300
committerJohn Smith <mrdoctorwho@gmail.com>2016-12-25 12:08:59 +0300
commit80781818123375d3d9f65c7ed82d877e72252733 (patch)
treeb0c2408d95f9e8450989514b9707614ea19241c8 /modules
parent441bde97f22f5d1d87a05a60e7364b049f8fcfd1 (diff)
Refactoring: rename Transport to Users, create error reporter, fix #135
Diffstat (limited to 'modules')
-rw-r--r--modules/mod_iq_captcha.py4
-rw-r--r--modules/mod_iq_disco.py14
-rw-r--r--modules/mod_iq_last.py6
-rw-r--r--modules/mod_iq_register.py6
-rw-r--r--modules/mod_iq_vcard.py4
-rw-r--r--modules/mod_msg_main.py6
-rw-r--r--modules/mod_msg_xhtml.py6
-rw-r--r--modules/mod_prs_main.py13
8 files changed, 30 insertions, 29 deletions
diff --git a/modules/mod_iq_captcha.py b/modules/mod_iq_captcha.py
index 9757c6f..4ddaaf7 100644
--- a/modules/mod_iq_captcha.py
+++ b/modules/mod_iq_captcha.py
@@ -6,7 +6,7 @@
Module purpose is to accept the captcha value from iq
"""
-from __main__ import TransportID, Transport
+from __main__ import TransportID, Users
import xmpp
import utils
import mod_msg_main as mod_msg
@@ -16,7 +16,7 @@ import mod_msg_main as mod_msg
def captcha_handler(cl, iq):
if iq.getTagAttr("captcha", "xmlns") == xmpp.NS_CAPTCHA:
source = iq.getFrom().getStripped()
- if source in Transport:
+ if source in Users:
destination = iq.getTo()
if destination == TransportID:
capTag = iq.getTag("captcha")
diff --git a/modules/mod_iq_disco.py b/modules/mod_iq_disco.py
index c4def19..d063b97 100644
--- a/modules/mod_iq_disco.py
+++ b/modules/mod_iq_disco.py
@@ -67,7 +67,7 @@ def disco_handler(cl, iq):
if source in ADMIN_JIDS:
users = []
if node == "Online users":
- users = Transport.keys()
+ users = Users.keys()
elif node == "All users":
users = getUsersList()
users = [user[0] for user in users]
@@ -110,7 +110,7 @@ def sendAnnouncement(destination, body, subject):
def sendGlobalMessage(body, subject, online):
if online:
- users = Transport.keys()
+ users = Users.keys()
else:
users = getUsersList()
for user in users:
@@ -274,14 +274,14 @@ def commands_handler(cl, iq):
note = wException()
elif node == NODE_GLOBAL_SETTINGS:
- config = transportSettings.settings
+ config = Transport.settings
if not form:
simpleForm = buildForm(simpleForm, fields=getConfigFields(config), title="Choose wisely")
elif form:
for key in dictForm.keys():
if key in config.keys():
- transportSettings.settings[key]["value"] = utils.normalizeValue(dictForm[key])
+ config[key]["value"] = utils.normalizeValue(dictForm[key])
note = "The settings were changed."
simpleForm = None
completed = True
@@ -337,16 +337,16 @@ def commands_handler(cl, iq):
simpleForm = buildForm(simpleForm, fields=_fields, title="Result")
completed = True
- if node == NODE_EDIT_SETTINGS and source in Transport:
+ if node == NODE_EDIT_SETTINGS and source in Users:
logger.info("user want to edit their settings (jid: %s)" % source)
- config = Transport[source].settings
+ config = Users[source].settings
if not form:
simpleForm = buildForm(simpleForm, fields=getConfigFields(config), title="Choose wisely")
elif form:
for key in dictForm.keys():
if key in config:
- Transport[source].settings[key] = utils.normalizeValue(dictForm[key])
+ Users[source].settings[key] = utils.normalizeValue(dictForm[key])
note = "The settings were changed."
simpleForm = None
completed = True
diff --git a/modules/mod_iq_last.py b/modules/mod_iq_last.py
index 8b79e94..4120585 100644
--- a/modules/mod_iq_last.py
+++ b/modules/mod_iq_last.py
@@ -17,10 +17,10 @@ def last_handler(cl, iq):
if id == TransportID:
last = int(time.time() - startTime)
name = IDENTIFIER["name"]
- elif source in Transport and id in Transport[source].friends:
- last = Transport[source].vk.method("execute.getLastTime", {"uid": id}) or 0
+ elif source in Users and id in Users[source].friends:
+ last = Users[source].vk.method("execute.getLastTime", {"uid": id}) or 0
last = int(time.time() - last)
- name = Transport[source].vk.getUserData(id).get("name", "Unknown")
+ name = Users[source].vk.getUserData(id).get("name", "Unknown")
else:
raise xmpp.NodeProcessed()
result = xmpp.Iq("result", to=jidFrom, frm=destination)
diff --git a/modules/mod_iq_register.py b/modules/mod_iq_register.py
index cec22c3..1046c49 100644
--- a/modules/mod_iq_register.py
+++ b/modules/mod_iq_register.py
@@ -34,8 +34,8 @@ def register_handler(cl, iq):
result = iq.buildReply("result")
if USER_LIMIT:
count = calcStats()[0]
- if count >= USER_LIMIT and not source in Transport:
- sender(cl, utils.buildIQError(iq, xmpp.ERR_NOT_ALLOWED, _("Transport's admins limited registrations, sorry.")))
+ if count >= USER_LIMIT and source not in Users:
+ sender(cl, utils.buildIQError(iq, xmpp.ERR_NOT_ALLOWED, _("The gateway admins limited registrations, sorry.")))
raise xmpp.NodeProcessed()
if destination == TransportID and iq.getQueryChildren():
@@ -76,7 +76,7 @@ def register_handler(cl, iq):
elif query.getTag("remove"):
logger.debug("user %s want to remove me..." % source)
- if source in Transport:
+ if source in Users:
user = Transport[source]
result = iq.buildReply("result")
result.setPayload([], add=False)
diff --git a/modules/mod_iq_vcard.py b/modules/mod_iq_vcard.py
index 9ca270f..3b760a4 100644
--- a/modules/mod_iq_vcard.py
+++ b/modules/mod_iq_vcard.py
@@ -145,8 +145,8 @@ def vcard_handler(cl, iq):
vcard = buildVcard(template, template, template)
result.setPayload([vcard])
- elif source in Transport:
- user = Transport[source]
+ elif source in Users:
+ user = Users[source]
if user.friends:
id = vk2xmpp(destination)
args = ("screen_name", "bdate", "city", "country", "contacts", "home_town", PhotoSize) # todo: a feature to show the user's site instead of their URL?
diff --git a/modules/mod_msg_main.py b/modules/mod_msg_main.py
index b59a277..78807af 100644
--- a/modules/mod_msg_main.py
+++ b/modules/mod_msg_main.py
@@ -30,7 +30,7 @@ def acceptCaptcha(key, source, destination):
2. User sent an IQ with the captcha value
"""
if args:
- user = Transport[source]
+ user = Users[source]
logger.debug("user %s called captcha challenge" % source)
try:
user.captchaChallenge(key)
@@ -56,8 +56,8 @@ def message_handler(cl, msg):
jidFrom = msg.getFrom()
source = jidFrom.getStripped()
- if msg.getType() == "chat" and source in Transport:
- user = Transport[source]
+ if msg.getType() == "chat" and source in Users:
+ user = Users[source]
if msg.getTag("composing"):
target = vk2xmpp(destination)
if target != TransportID:
diff --git a/modules/mod_msg_xhtml.py b/modules/mod_msg_xhtml.py
index 4cb615c..fa12a74 100644
--- a/modules/mod_msg_xhtml.py
+++ b/modules/mod_msg_xhtml.py
@@ -3,15 +3,15 @@
# © simpleApps, 2013 — 2015.
# This module depends on mod_xhtml.
-from __main__ import Transport, logger
+from __main__ import Users, logger
import xmpp
import mod_xhtml
def xhtml_handler(cl, msg):
destination = msg.getTo().getStripped()
source = msg.getFrom().getStripped()
- if source in Transport and msg.getType() == "chat":
- user = Transport[source]
+ if source in Users and msg.getType() == "chat":
+ user = Users[source]
html = msg.getTag("html")
if html and html.getTag("body"): # XHTML-IM!
logger.debug("fetched xhtml image from %s", source)
diff --git a/modules/mod_prs_main.py b/modules/mod_prs_main.py
index 49f3194..9c9da11 100644
--- a/modules/mod_prs_main.py
+++ b/modules/mod_prs_main.py
@@ -25,8 +25,9 @@ def initializeUser(source, resource, prs):
except Exception:
sendMessage(source, TransportID,
_("Auth failed! If this error repeated, "
- "please register again. This incident will be reported."))
- crashLog("user.connect")
+ "please register again."
+ " This incident will be reported.\nCause: %s") % returnExc())
+ report(crashLog("user.connect"))
else:
user.initialize(send=True, resource=resource) # probably we need to know resource a bit earlier than this time
utils.runThread(executeHandlers, ("prs01", (source, prs)))
@@ -41,8 +42,8 @@ def presence_handler(cl, prs):
source = jidFrom.getStripped()
resource = jidFrom.getResource()
destination = prs.getTo().getStripped()
- if source in Transport:
- user = Transport[source]
+ if source in Users:
+ user = Users[source]
if pType in ("available", "probe", None):
if destination == TransportID:
if resource not in user.resources and user not in USERS_ON_INIT:
@@ -57,11 +58,11 @@ def presence_handler(cl, prs):
user.sendOutPresence(jidFrom)
if not user.resources:
sendPresence(source, TransportID, "unavailable")
- if transportSettings.send_unavailable:
+ if Transport.settings.send_unavailable:
user.sendOutPresence(source)
try:
user.vk.disconnect()
- del Transport[source]
+ del Users[source]
except (AttributeError, KeyError):
pass