Code style cleanup
darcs-hash:20070605190158-86b55-3d4313f040b985814572e0196fac9b4476c3daaf.gz
This commit is contained in:
@@ -78,12 +78,12 @@ class JCLComponent(Component, object):
|
|||||||
disco_category="gateway",
|
disco_category="gateway",
|
||||||
disco_type="headline",
|
disco_type="headline",
|
||||||
lang=Lang()):
|
lang=Lang()):
|
||||||
Component.__init__(self, \
|
Component.__init__(self,
|
||||||
JID(jid), \
|
JID(jid),
|
||||||
secret, \
|
secret,
|
||||||
server, \
|
server,
|
||||||
port, \
|
port,
|
||||||
disco_category, \
|
disco_category,
|
||||||
disco_type)
|
disco_type)
|
||||||
# default values
|
# default values
|
||||||
self.name = lang.get_default_lang_class().component_name
|
self.name = lang.get_default_lang_class().component_name
|
||||||
@@ -117,12 +117,12 @@ class JCLComponent(Component, object):
|
|||||||
self.spool_dir += "/" + unicode(self.jid)
|
self.spool_dir += "/" + unicode(self.jid)
|
||||||
self.running = True
|
self.running = True
|
||||||
self.connect()
|
self.connect()
|
||||||
timer_thread = threading.Thread(target = self.time_handler, \
|
timer_thread = threading.Thread(target=self.time_handler,
|
||||||
name="TimerThread")
|
name="TimerThread")
|
||||||
timer_thread.start()
|
timer_thread.start()
|
||||||
try:
|
try:
|
||||||
while (self.running and self.stream \
|
while (self.running and self.stream
|
||||||
and not self.stream.eof \
|
and not self.stream.eof
|
||||||
and self.stream.socket is not None):
|
and self.stream.socket is not None):
|
||||||
self.stream.loop_iter(JCLComponent.timeout)
|
self.stream.loop_iter(JCLComponent.timeout)
|
||||||
if self.queue.qsize():
|
if self.queue.qsize():
|
||||||
@@ -162,8 +162,8 @@ class JCLComponent(Component, object):
|
|||||||
"""
|
"""
|
||||||
self.__logger.info("Timer thread started...")
|
self.__logger.info("Timer thread started...")
|
||||||
try:
|
try:
|
||||||
while (self.running and self.stream \
|
while (self.running and self.stream
|
||||||
and not self.stream.eof \
|
and not self.stream.eof
|
||||||
and self.stream.socket is not None):
|
and self.stream.socket is not None):
|
||||||
self.handle_tick()
|
self.handle_tick()
|
||||||
self.__logger.debug("Resetting alarm signal")
|
self.__logger.debug("Resetting alarm signal")
|
||||||
@@ -180,32 +180,32 @@ class JCLComponent(Component, object):
|
|||||||
"""
|
"""
|
||||||
self.__logger.debug("AUTHENTICATED")
|
self.__logger.debug("AUTHENTICATED")
|
||||||
Component.authenticated(self)
|
Component.authenticated(self)
|
||||||
self.stream.set_iq_get_handler("query", "jabber:iq:version", \
|
self.stream.set_iq_get_handler("query", "jabber:iq:version",
|
||||||
self.handle_get_version)
|
self.handle_get_version)
|
||||||
self.stream.set_iq_get_handler("query", "jabber:iq:register", \
|
self.stream.set_iq_get_handler("query", "jabber:iq:register",
|
||||||
self.handle_get_register)
|
self.handle_get_register)
|
||||||
self.stream.set_iq_set_handler("query", "jabber:iq:register", \
|
self.stream.set_iq_set_handler("query", "jabber:iq:register",
|
||||||
self.handle_set_register)
|
self.handle_set_register)
|
||||||
|
|
||||||
self.stream.set_presence_handler("available", \
|
self.stream.set_presence_handler("available",
|
||||||
self.handle_presence_available)
|
self.handle_presence_available)
|
||||||
|
|
||||||
self.stream.set_presence_handler("probe", \
|
self.stream.set_presence_handler("probe",
|
||||||
self.handle_presence_available)
|
self.handle_presence_available)
|
||||||
|
|
||||||
self.stream.set_presence_handler("unavailable", \
|
self.stream.set_presence_handler("unavailable",
|
||||||
self.handle_presence_unavailable)
|
self.handle_presence_unavailable)
|
||||||
|
|
||||||
self.stream.set_presence_handler("unsubscribe", \
|
self.stream.set_presence_handler("unsubscribe",
|
||||||
self.handle_presence_unsubscribe)
|
self.handle_presence_unsubscribe)
|
||||||
self.stream.set_presence_handler("unsubscribed", \
|
self.stream.set_presence_handler("unsubscribed",
|
||||||
self.handle_presence_unsubscribed)
|
self.handle_presence_unsubscribed)
|
||||||
self.stream.set_presence_handler("subscribe", \
|
self.stream.set_presence_handler("subscribe",
|
||||||
self.handle_presence_subscribe)
|
self.handle_presence_subscribe)
|
||||||
self.stream.set_presence_handler("subscribed", \
|
self.stream.set_presence_handler("subscribed",
|
||||||
self.handle_presence_subscribed)
|
self.handle_presence_subscribed)
|
||||||
|
|
||||||
self.stream.set_message_handler("normal", \
|
self.stream.set_message_handler("normal",
|
||||||
self.handle_message)
|
self.handle_message)
|
||||||
self.send_stanzas(self.account_manager.probe_all_accounts_presence())
|
self.send_stanzas(self.account_manager.probe_all_accounts_presence())
|
||||||
|
|
||||||
@@ -224,10 +224,10 @@ class JCLComponent(Component, object):
|
|||||||
for stanza in stanzas:
|
for stanza in stanzas:
|
||||||
self.stream.send(stanza)
|
self.stream.send(stanza)
|
||||||
|
|
||||||
def apply_behavior(self, info_query, \
|
def apply_behavior(self, info_query,
|
||||||
account_handler, \
|
account_handler,
|
||||||
account_type_handler, \
|
account_type_handler,
|
||||||
root_handler, \
|
root_handler,
|
||||||
send_result=False):
|
send_result=False):
|
||||||
"""Apply given handler depending on info_query receiver"""
|
"""Apply given handler depending on info_query receiver"""
|
||||||
from_jid = info_query.get_from()
|
from_jid = info_query.get_from()
|
||||||
@@ -244,13 +244,17 @@ class JCLComponent(Component, object):
|
|||||||
# |-* account4
|
# |-* account4
|
||||||
if name is not None: # account
|
if name is not None: # account
|
||||||
self.__logger.debug("Applying behavior on account " + name)
|
self.__logger.debug("Applying behavior on account " + name)
|
||||||
result = account_handler(name, from_jid, account_type or "", lang_class)
|
result = account_handler(name, from_jid, account_type or "",
|
||||||
|
lang_class)
|
||||||
elif account_type is None: # root
|
elif account_type is None: # root
|
||||||
self.__logger.debug("Applying behavior on root node")
|
self.__logger.debug("Applying behavior on root node")
|
||||||
result = root_handler(name, from_jid, "", lang_class) # TODO : account_type not needed
|
result = root_handler(name, from_jid, "",
|
||||||
|
lang_class) # TODO : account_type not needed
|
||||||
else: # account type
|
else: # account type
|
||||||
self.__logger.debug("Applying behavior on account type " + account_type)
|
self.__logger.debug("Applying behavior on account type " +
|
||||||
result = account_type_handler(name, from_jid, account_type, lang_class)
|
account_type)
|
||||||
|
result = account_type_handler(name, from_jid, account_type,
|
||||||
|
lang_class)
|
||||||
if send_result:
|
if send_result:
|
||||||
self.send_stanzas(result)
|
self.send_stanzas(result)
|
||||||
return result
|
return result
|
||||||
@@ -295,13 +299,16 @@ class JCLComponent(Component, object):
|
|||||||
def disco_get_items(self, node, info_query):
|
def disco_get_items(self, node, info_query):
|
||||||
"""Discovery get nested nodes handler
|
"""Discovery get nested nodes handler
|
||||||
"""
|
"""
|
||||||
return self.apply_behavior(info_query, \
|
return self.apply_behavior(\
|
||||||
|
info_query,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
DiscoItems(), \
|
DiscoItems(),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_type_disco_get_items(from_jid, account_type), \
|
self.account_manager.account_type_disco_get_items(from_jid,
|
||||||
|
account_type),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_disco_get_items(from_jid, lang_class))
|
self.account_manager.root_disco_get_items(from_jid,
|
||||||
|
lang_class))
|
||||||
|
|
||||||
def handle_get_version(self, info_query):
|
def handle_get_version(self, info_query):
|
||||||
"""Get Version handler
|
"""Get Version handler
|
||||||
@@ -319,20 +326,21 @@ class JCLComponent(Component, object):
|
|||||||
see node structure in disco_get_items()
|
see node structure in disco_get_items()
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("GET_REGISTER")
|
self.__logger.debug("GET_REGISTER")
|
||||||
self.apply_behavior(info_query, \
|
self.apply_behavior(\
|
||||||
|
info_query,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_get_register(info_query, \
|
self.account_manager.account_get_register(info_query,
|
||||||
name, \
|
name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
account_type, \
|
account_type,
|
||||||
lang_class), \
|
lang_class),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_type_get_register(info_query, \
|
self.account_manager.account_type_get_register(info_query,
|
||||||
account_type, \
|
account_type,
|
||||||
lang_class), \
|
lang_class),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_get_register(info_query, \
|
self.account_manager.root_get_register(info_query,
|
||||||
lang_class), \
|
lang_class),
|
||||||
send_result=True)
|
send_result=True)
|
||||||
|
|
||||||
def handle_set_register(self, info_query):
|
def handle_set_register(self, info_query):
|
||||||
@@ -343,47 +351,49 @@ class JCLComponent(Component, object):
|
|||||||
self.lang.get_lang_class_from_node(info_query.get_node())
|
self.lang.get_lang_class_from_node(info_query.get_node())
|
||||||
from_jid = info_query.get_from()
|
from_jid = info_query.get_from()
|
||||||
base_from_jid = unicode(from_jid.bare())
|
base_from_jid = unicode(from_jid.bare())
|
||||||
remove = info_query.xpath_eval("r:query/r:remove", \
|
remove = info_query.xpath_eval("r:query/r:remove",
|
||||||
{"r" : "jabber:iq:register"})
|
{"r" : "jabber:iq:register"})
|
||||||
if remove:
|
if remove:
|
||||||
result = self.account_manager.remove_all_accounts(from_jid.bare())
|
result = self.account_manager.remove_all_accounts(from_jid.bare())
|
||||||
self.send_stanzas(result)
|
self.send_stanzas(result)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
x_node = info_query.xpath_eval("jir:query/jxd:x", \
|
x_node = info_query.xpath_eval("jir:query/jxd:x",
|
||||||
{"jir" : "jabber:iq:register", \
|
{"jir" : "jabber:iq:register",
|
||||||
"jxd" : "jabber:x:data"})[0]
|
"jxd" : "jabber:x:data"})[0]
|
||||||
|
|
||||||
x_data = Form(x_node)
|
x_data = Form(x_node)
|
||||||
if not "name" in x_data or x_data["name"].value == "":
|
if not "name" in x_data or x_data["name"].value == "":
|
||||||
iq_error = info_query.make_error_response("not-acceptable")
|
iq_error = info_query.make_error_response("not-acceptable")
|
||||||
text = iq_error.get_error().xmlnode.newTextChild(None, \
|
text = iq_error.get_error().xmlnode.newTextChild(\
|
||||||
"text", \
|
None,
|
||||||
|
"text",
|
||||||
lang_class.mandatory_field % ("name"))
|
lang_class.mandatory_field % ("name"))
|
||||||
text.setNs(text.newNs(error.STANZA_ERROR_NS, None))
|
text.setNs(text.newNs(error.STANZA_ERROR_NS, None))
|
||||||
self.stream.send(iq_error)
|
self.stream.send(iq_error)
|
||||||
return
|
return
|
||||||
account_name = x_data["name"].value
|
account_name = x_data["name"].value
|
||||||
return self.apply_behavior(info_query, \
|
return self.apply_behavior(\
|
||||||
|
info_query,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_set_register(name, \
|
self.account_manager.account_set_register(name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
lang_class, \
|
lang_class,
|
||||||
x_data, \
|
x_data,
|
||||||
info_query), \
|
info_query),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_type_set_register(account_name, \
|
self.account_manager.account_type_set_register(account_name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
account_type, \
|
account_type,
|
||||||
lang_class, \
|
lang_class,
|
||||||
x_data, \
|
x_data,
|
||||||
info_query), \
|
info_query),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_set_register(account_name, \
|
self.account_manager.root_set_register(account_name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
lang_class, \
|
lang_class,
|
||||||
x_data, \
|
x_data,
|
||||||
info_query), \
|
info_query),
|
||||||
send_result=True)
|
send_result=True)
|
||||||
|
|
||||||
def handle_presence_available(self, stanza):
|
def handle_presence_available(self, stanza):
|
||||||
@@ -393,18 +403,19 @@ class JCLComponent(Component, object):
|
|||||||
"""
|
"""
|
||||||
result = self.apply_registered_behavior(self.available_handlers, stanza)
|
result = self.apply_registered_behavior(self.available_handlers, stanza)
|
||||||
if result == []:
|
if result == []:
|
||||||
result = self.apply_behavior(stanza, \
|
result = self.apply_behavior(\
|
||||||
|
stanza,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_handle_presence_available(name, \
|
self.account_manager.account_handle_presence_available(name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
lang_class, \
|
lang_class,
|
||||||
stanza.get_show()), \
|
stanza.get_show()),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
[], \
|
[],
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_handle_presence_available(from_jid, \
|
self.account_manager.root_handle_presence_available(from_jid,
|
||||||
lang_class, \
|
lang_class,
|
||||||
stanza.get_show()), \
|
stanza.get_show()),
|
||||||
send_result=True)
|
send_result=True)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -415,14 +426,15 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.debug("PRESENCE_UNAVAILABLE")
|
self.__logger.debug("PRESENCE_UNAVAILABLE")
|
||||||
result = self.apply_registered_behavior(self.unavailable_handlers, stanza)
|
result = self.apply_registered_behavior(self.unavailable_handlers, stanza)
|
||||||
if result == []:
|
if result == []:
|
||||||
result = self.apply_behavior(stanza, \
|
result = self.apply_behavior(\
|
||||||
|
stanza,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_handle_presence_unavailable(name, \
|
self.account_manager.account_handle_presence_unavailable(name,
|
||||||
from_jid), \
|
from_jid),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
[], \
|
[],
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_handle_presence_unavailable(from_jid), \
|
self.account_manager.root_handle_presence_unavailable(from_jid),
|
||||||
send_result=True)
|
send_result=True)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -432,16 +444,17 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.debug("PRESENCE_SUBSCRIBE")
|
self.__logger.debug("PRESENCE_SUBSCRIBE")
|
||||||
result = self.apply_registered_behavior(self.subscribe_handlers, stanza)
|
result = self.apply_registered_behavior(self.subscribe_handlers, stanza)
|
||||||
if result == []:
|
if result == []:
|
||||||
result = self.apply_behavior(stanza, \
|
result = self.apply_behavior(\
|
||||||
|
stanza,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_handle_presence_subscribe(name, \
|
self.account_manager.account_handle_presence_subscribe(name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
stanza), \
|
stanza),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
[], \
|
[],
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.root_handle_presence_subscribe(from_jid, \
|
self.account_manager.root_handle_presence_subscribe(from_jid,
|
||||||
stanza), \
|
stanza),
|
||||||
send_result=True)
|
send_result=True)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -457,14 +470,15 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.debug("PRESENCE_UNSUBSCRIBE")
|
self.__logger.debug("PRESENCE_UNSUBSCRIBE")
|
||||||
result = self.apply_registered_behavior(self.unsubscribe_handlers, stanza)
|
result = self.apply_registered_behavior(self.unsubscribe_handlers, stanza)
|
||||||
if result == []:
|
if result == []:
|
||||||
result = self.apply_behavior(stanza, \
|
result = self.apply_behavior(\
|
||||||
|
stanza,
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
self.account_manager.account_handle_presence_unsubscribe(name, \
|
self.account_manager.account_handle_presence_unsubscribe(name,
|
||||||
from_jid), \
|
from_jid),
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
[], \
|
[],
|
||||||
lambda name, from_jid, account_type, lang_class: \
|
lambda name, from_jid, account_type, lang_class: \
|
||||||
[], \
|
[],
|
||||||
send_result=True)
|
send_result=True)
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -472,8 +486,8 @@ class JCLComponent(Component, object):
|
|||||||
"""Handle unsubscribed presence from user
|
"""Handle unsubscribed presence from user
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_UNSUBSCRIBED")
|
self.__logger.debug("PRESENCE_UNSUBSCRIBED")
|
||||||
presence = Presence(from_jid = stanza.get_to(), \
|
presence = Presence(from_jid=stanza.get_to(),
|
||||||
to_jid = stanza.get_from(), \
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="unavailable")
|
stanza_type="unavailable")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
return 1
|
return 1
|
||||||
@@ -494,7 +508,7 @@ class JCLComponent(Component, object):
|
|||||||
self.send_stanzas(self.account_manager.send_error(_account, exception))
|
self.send_stanzas(self.account_manager.send_error(_account, exception))
|
||||||
type, value, stack = sys.exc_info()
|
type, value, stack = sys.exc_info()
|
||||||
# TODO : not checking email here
|
# TODO : not checking email here
|
||||||
self.__logger.debug("Error: %s\n%s" \
|
self.__logger.debug("Error: %s\n%s"
|
||||||
% (exception, "".join(traceback.format_exception
|
% (exception, "".join(traceback.format_exception
|
||||||
(type, value, stack, 5))))
|
(type, value, stack, 5))))
|
||||||
|
|
||||||
@@ -548,9 +562,8 @@ class AccountManager(object):
|
|||||||
disco_info.add_feature("jabber:iq:version")
|
disco_info.add_feature("jabber:iq:version")
|
||||||
if not self.has_multiple_account_type:
|
if not self.has_multiple_account_type:
|
||||||
disco_info.add_feature("jabber:iq:register")
|
disco_info.add_feature("jabber:iq:register")
|
||||||
# TODO: name is always None
|
DiscoIdentity(disco_info, name,
|
||||||
DiscoIdentity(disco_info, name, \
|
category,
|
||||||
category, \
|
|
||||||
type)
|
type)
|
||||||
return disco_info
|
return disco_info
|
||||||
|
|
||||||
@@ -561,12 +574,12 @@ class AccountManager(object):
|
|||||||
disco_items = DiscoItems()
|
disco_items = DiscoItems()
|
||||||
account_class = self._get_account_class(account_type + "Account")
|
account_class = self._get_account_class(account_type + "Account")
|
||||||
if account_class is not None:
|
if account_class is not None:
|
||||||
self._list_accounts(disco_items, \
|
self._list_accounts(disco_items,
|
||||||
account_class, \
|
account_class,
|
||||||
from_jid.bare(), \
|
from_jid.bare(),
|
||||||
account_type=account_type)
|
account_type=account_type)
|
||||||
else:
|
else:
|
||||||
self.__logger.error("Error: " + account_class.__name__ \
|
self.__logger.error("Error: " + account_class.__name__
|
||||||
+ " class not in account_classes")
|
+ " class not in account_classes")
|
||||||
return disco_items
|
return disco_items
|
||||||
|
|
||||||
@@ -581,9 +594,10 @@ class AccountManager(object):
|
|||||||
type_label = getattr(lang_class, type_label_attr)
|
type_label = getattr(lang_class, type_label_attr)
|
||||||
else:
|
else:
|
||||||
type_label = account_type
|
type_label = account_type
|
||||||
return DiscoItem(disco_items, \
|
return DiscoItem(disco_items,
|
||||||
JID(unicode(self.component.jid) + "/" + account_type), \
|
JID(unicode(self.component.jid) + "/" +
|
||||||
account_type, \
|
account_type),
|
||||||
|
account_type,
|
||||||
type_label)
|
type_label)
|
||||||
list_func = _list_account_types
|
list_func = _list_account_types
|
||||||
|
|
||||||
@@ -594,18 +608,18 @@ class AccountManager(object):
|
|||||||
match = regexp_type.search(account_class.__name__)
|
match = regexp_type.search(account_class.__name__)
|
||||||
if match is not None:
|
if match is not None:
|
||||||
account_type = match.group(1)
|
account_type = match.group(1)
|
||||||
list_func(disco_items, account_class, \
|
list_func(disco_items, account_class,
|
||||||
from_jid.bare(), account_type)
|
from_jid.bare(), account_type)
|
||||||
else:
|
else:
|
||||||
self.__logger.error(account_class.__name__ + \
|
self.__logger.error(account_class.__name__ +
|
||||||
" name not well formed")
|
" name not well formed")
|
||||||
return disco_items
|
return disco_items
|
||||||
|
|
||||||
###### get_register handlers ######
|
###### get_register handlers ######
|
||||||
def account_get_register(self, info_query, \
|
def account_get_register(self, info_query,
|
||||||
name, \
|
name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
account_type, \
|
account_type,
|
||||||
lang_class):
|
lang_class):
|
||||||
"""Handle get_register on an account.
|
"""Handle get_register on an account.
|
||||||
Return a preinitialized form"""
|
Return a preinitialized form"""
|
||||||
@@ -613,11 +627,11 @@ class AccountManager(object):
|
|||||||
account_class = self._get_account_class(account_type + "Account")
|
account_class = self._get_account_class(account_type + "Account")
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = account_class.select(\
|
accounts = account_class.select(\
|
||||||
AND(account_class.q.name == name, \
|
AND(account_class.q.name == name,
|
||||||
account_class.q.user_jid == unicode(from_jid.bare())))
|
account_class.q.user_jid == unicode(from_jid.bare())))
|
||||||
if accounts is not None:
|
if accounts is not None:
|
||||||
query = info_query.new_query("jabber:iq:register")
|
query = info_query.new_query("jabber:iq:register")
|
||||||
self.get_reg_form_init(lang_class, \
|
self.get_reg_form_init(lang_class,
|
||||||
accounts[0]).as_xml(query)
|
accounts[0]).as_xml(query)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return [info_query]
|
return [info_query]
|
||||||
@@ -626,21 +640,22 @@ class AccountManager(object):
|
|||||||
"""Handle get_register for given account_class"""
|
"""Handle get_register for given account_class"""
|
||||||
info_query = info_query.make_result_response()
|
info_query = info_query.make_result_response()
|
||||||
query = info_query.new_query("jabber:iq:register")
|
query = info_query.new_query("jabber:iq:register")
|
||||||
self.get_reg_form(lang_class, \
|
self.get_reg_form(lang_class,
|
||||||
account_class).as_xml(query)
|
account_class).as_xml(query)
|
||||||
return [info_query]
|
return [info_query]
|
||||||
|
|
||||||
def account_type_get_register(self, info_query, account_type, lang_class):
|
def account_type_get_register(self, info_query, account_type, lang_class):
|
||||||
"""Handle get_register on an account_type node"""
|
"""Handle get_register on an account_type node"""
|
||||||
return self._account_type_get_register(info_query, \
|
return self._account_type_get_register(\
|
||||||
self._get_account_class(account_type + "Account"), \
|
info_query,
|
||||||
|
self._get_account_class(account_type + "Account"),
|
||||||
lang_class)
|
lang_class)
|
||||||
|
|
||||||
def root_get_register(self, info_query, lang_class):
|
def root_get_register(self, info_query, lang_class):
|
||||||
"""Handle get_register on root node"""
|
"""Handle get_register on root node"""
|
||||||
if not self.has_multiple_account_type:
|
if not self.has_multiple_account_type:
|
||||||
return self._account_type_get_register(info_query, \
|
return self._account_type_get_register(info_query,
|
||||||
self.account_classes[0], \
|
self.account_classes[0],
|
||||||
lang_class)
|
lang_class)
|
||||||
|
|
||||||
###### set_register handlers ######
|
###### set_register handlers ######
|
||||||
@@ -650,48 +665,51 @@ class AccountManager(object):
|
|||||||
self.db_connect()
|
self.db_connect()
|
||||||
result = []
|
result = []
|
||||||
for _account in Account.select(Account.q.user_jid == unicode(user_jid)):
|
for _account in Account.select(Account.q.user_jid == unicode(user_jid)):
|
||||||
self.__logger.debug("Deleting " + _account.name \
|
self.__logger.debug("Deleting " + _account.name
|
||||||
+ " for " + unicode(user_jid))
|
+ " for " + unicode(user_jid))
|
||||||
# get_jid
|
# get_jid
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = user_jid, \
|
to_jid=user_jid,
|
||||||
stanza_type="unsubscribe"))
|
stanza_type="unsubscribe"))
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = user_jid, \
|
to_jid=user_jid,
|
||||||
stanza_type="unsubscribed"))
|
stanza_type="unsubscribed"))
|
||||||
_account.destroySelf()
|
_account.destroySelf()
|
||||||
result.append(Presence(from_jid = self.component.jid, to_jid = user_jid, \
|
result.append(Presence(from_jid=self.component.jid,
|
||||||
|
to_jid=user_jid,
|
||||||
stanza_type="unsubscribe"))
|
stanza_type="unsubscribe"))
|
||||||
result.append(Presence(from_jid = self.component.jid, to_jid = user_jid, \
|
result.append(Presence(from_jid=self.component.jid,
|
||||||
|
to_jid=user_jid,
|
||||||
stanza_type="unsubscribed"))
|
stanza_type="unsubscribed"))
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def _populate_account(self, _account, lang_class, x_data, \
|
def _populate_account(self, _account, lang_class, x_data,
|
||||||
info_query, new_account, first_account):
|
info_query, new_account, first_account):
|
||||||
"""Populate given account"""
|
"""Populate given account"""
|
||||||
field = None
|
field = None
|
||||||
result = []
|
result = []
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
try:
|
try:
|
||||||
for (field, field_type, field_options, field_post_func, \
|
for (field, field_type, field_options, field_post_func,
|
||||||
field_default_func) in _account.get_register_fields():
|
field_default_func) in _account.get_register_fields():
|
||||||
if field is not None:
|
if field is not None:
|
||||||
if field in x_data:
|
if field in x_data:
|
||||||
value = x_data[field].value
|
value = x_data[field].value
|
||||||
else:
|
else:
|
||||||
value = None
|
value = None
|
||||||
setattr(_account, field, \
|
setattr(_account, field,
|
||||||
field_post_func(value, field_default_func))
|
field_post_func(value, field_default_func))
|
||||||
except FieldError, exception:
|
except FieldError, exception:
|
||||||
_account.destroySelf()
|
_account.destroySelf()
|
||||||
type, value, stack = sys.exc_info()
|
type, value, stack = sys.exc_info()
|
||||||
self.__logger.error("Error while populating account: %s\n%s" % \
|
self.__logger.error("Error while populating account: %s\n%s" %
|
||||||
(exception, "".join(traceback.format_exception
|
(exception, "".join(traceback.format_exception
|
||||||
(type, value, stack, 5))))
|
(type, value, stack, 5))))
|
||||||
iq_error = info_query.make_error_response("not-acceptable")
|
iq_error = info_query.make_error_response("not-acceptable")
|
||||||
text = iq_error.get_error().xmlnode.newTextChild(None, \
|
text = iq_error.get_error().xmlnode.newTextChild(\
|
||||||
"text", \
|
None,
|
||||||
|
"text",
|
||||||
lang_class.mandatory_field % (field))
|
lang_class.mandatory_field % (field))
|
||||||
text.setNs(text.newNs(error.STANZA_ERROR_NS, None))
|
text.setNs(text.newNs(error.STANZA_ERROR_NS, None))
|
||||||
result.append(iq_error)
|
result.append(iq_error)
|
||||||
@@ -701,86 +719,89 @@ class AccountManager(object):
|
|||||||
|
|
||||||
# TODO : _account.user_jid or from_jid
|
# TODO : _account.user_jid or from_jid
|
||||||
if first_account:
|
if first_account:
|
||||||
result.append(Presence(from_jid = self.component.jid, \
|
result.append(Presence(from_jid=self.component.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
stanza_type="subscribe"))
|
stanza_type="subscribe"))
|
||||||
if new_account:
|
if new_account:
|
||||||
result.append(Message(\
|
result.append(Message(\
|
||||||
from_jid = self.component.jid, to_jid = _account.user_jid, \
|
from_jid=self.component.jid,
|
||||||
subject = _account.get_new_message_subject(lang_class), \
|
to_jid=_account.user_jid,
|
||||||
|
subject=_account.get_new_message_subject(lang_class),
|
||||||
body=_account.get_new_message_body(lang_class)))
|
body=_account.get_new_message_body(lang_class)))
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
stanza_type="subscribe"))
|
stanza_type="subscribe"))
|
||||||
else:
|
else:
|
||||||
result.append(Message(\
|
result.append(Message(\
|
||||||
from_jid = self.component.jid, to_jid = _account.user_jid, \
|
from_jid=self.component.jid,
|
||||||
subject = _account.get_update_message_subject(lang_class), \
|
to_jid=_account.user_jid,
|
||||||
|
subject=_account.get_update_message_subject(lang_class),
|
||||||
body=_account.get_update_message_body(lang_class)))
|
body=_account.get_update_message_body(lang_class)))
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def account_set_register(self, name, from_jid, lang_class, \
|
def account_set_register(self, name, from_jid, lang_class,
|
||||||
x_data, info_query):
|
x_data, info_query):
|
||||||
"""Update account"""
|
"""Update account"""
|
||||||
self.__logger.debug("Updating account " + name)
|
self.__logger.debug("Updating account " + name)
|
||||||
bare_from_jid = from_jid.bare()
|
bare_from_jid = from_jid.bare()
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = Account.select(\
|
accounts = Account.select(\
|
||||||
AND(Account.q.name == name, \
|
AND(Account.q.name == name,
|
||||||
Account.q.user_jid == unicode(bare_from_jid)))
|
Account.q.user_jid == unicode(bare_from_jid)))
|
||||||
accounts_count = accounts.count()
|
accounts_count = accounts.count()
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
if accounts_count > 1:
|
if accounts_count > 1:
|
||||||
# Just print a warning, only the first account will be use
|
# Just print a warning, only the first account will be use
|
||||||
self.__logger.error("There might not exist 2 accounts for " + \
|
self.__logger.error("There might not exist 2 accounts for " +
|
||||||
bare_from_jid + " and named " + name)
|
bare_from_jid + " and named " + name)
|
||||||
if accounts_count >= 1:
|
if accounts_count >= 1:
|
||||||
return self._populate_account(_account, lang_class,
|
return self._populate_account(_account, lang_class,
|
||||||
x_data, info_query, False, False)
|
x_data, info_query, False, False)
|
||||||
else:
|
else:
|
||||||
self.__logger.error("Account " + name + \
|
self.__logger.error("Account " + name +
|
||||||
" was not found, cannot update it")
|
" was not found, cannot update it")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def _account_type_set_register(self, name, \
|
def _account_type_set_register(self, name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
account_class, \
|
account_class,
|
||||||
lang_class, \
|
lang_class,
|
||||||
x_data, \
|
x_data,
|
||||||
info_query):
|
info_query):
|
||||||
"""Create new account from account_class"""
|
"""Create new account from account_class"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
bare_from_jid = from_jid.bare()
|
bare_from_jid = from_jid.bare()
|
||||||
_account = account_class(user_jid = unicode(bare_from_jid), \
|
_account = account_class(user_jid=unicode(bare_from_jid),
|
||||||
name = name, \
|
name=name,
|
||||||
jid=self.get_account_jid(name))
|
jid=self.get_account_jid(name))
|
||||||
all_accounts = Account.select(\
|
all_accounts = Account.select(\
|
||||||
Account.q.user_jid == unicode(bare_from_jid))
|
Account.q.user_jid == unicode(bare_from_jid))
|
||||||
first_account = (all_accounts.count() > 0)
|
first_account = (all_accounts.count() > 0)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return self._populate_account(_account, lang_class, x_data, \
|
return self._populate_account(_account, lang_class, x_data,
|
||||||
info_query, True, first_account)
|
info_query, True, first_account)
|
||||||
|
|
||||||
def account_type_set_register(self, name, \
|
def account_type_set_register(self, name,
|
||||||
from_jid, \
|
from_jid,
|
||||||
account_type, \
|
account_type,
|
||||||
lang_class, \
|
lang_class,
|
||||||
x_data, \
|
x_data,
|
||||||
info_query):
|
info_query):
|
||||||
"""Create new typed account"""
|
"""Create new typed account"""
|
||||||
return self._account_type_set_register(name, from_jid, \
|
return self._account_type_set_register(\
|
||||||
self._get_account_class(account_type + "Account"), lang_class, \
|
name, from_jid,
|
||||||
|
self._get_account_class(account_type + "Account"), lang_class,
|
||||||
x_data, info_query)
|
x_data, info_query)
|
||||||
|
|
||||||
def root_set_register(self, name, from_jid, lang_class, \
|
def root_set_register(self, name, from_jid, lang_class,
|
||||||
x_data, info_query):
|
x_data, info_query):
|
||||||
"""Create new account when managing only one account type"""
|
"""Create new account when managing only one account type"""
|
||||||
if not self.has_multiple_account_type:
|
if not self.has_multiple_account_type:
|
||||||
return self._account_type_set_register(name, from_jid, \
|
return self._account_type_set_register(name, from_jid,
|
||||||
self.account_classes[0], \
|
self.account_classes[0],
|
||||||
lang_class, x_data, \
|
lang_class, x_data,
|
||||||
info_query)
|
info_query)
|
||||||
else:
|
else:
|
||||||
return []
|
return []
|
||||||
@@ -792,7 +813,7 @@ class AccountManager(object):
|
|||||||
result = []
|
result = []
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = Account.select(\
|
accounts = Account.select(\
|
||||||
AND(Account.q.name == name, \
|
AND(Account.q.name == name,
|
||||||
Account.q.user_jid == unicode(from_jid.bare())))
|
Account.q.user_jid == unicode(from_jid.bare())))
|
||||||
if accounts.count() > 0:
|
if accounts.count() > 0:
|
||||||
result.extend(presence_func(accounts[0]))
|
result.extend(presence_func(accounts[0]))
|
||||||
@@ -823,13 +844,13 @@ class AccountManager(object):
|
|||||||
# Explicit reference to account table (clauseTables) to use
|
# Explicit reference to account table (clauseTables) to use
|
||||||
# "user_jid" column with Account subclasses
|
# "user_jid" column with Account subclasses
|
||||||
for _account in \
|
for _account in \
|
||||||
Account.select(clauseTables = ["account"], \
|
Account.select(clauseTables=["account"],
|
||||||
orderBy="user_jid"):
|
orderBy="user_jid"):
|
||||||
if current_user_jid != _account.user_jid:
|
if current_user_jid != _account.user_jid:
|
||||||
current_user_jid = _account.user_jid
|
current_user_jid = _account.user_jid
|
||||||
result.extend(getattr(self, "_send_presence_" + \
|
result.extend(getattr(self, "_send_presence_" +
|
||||||
presence + "_root")(_account.user_jid))
|
presence + "_root")(_account.user_jid))
|
||||||
result.extend(getattr(self, "_send_presence_" + \
|
result.extend(getattr(self, "_send_presence_" +
|
||||||
presence)(_account))
|
presence)(_account))
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return result
|
return result
|
||||||
@@ -838,37 +859,41 @@ class AccountManager(object):
|
|||||||
###### presence_available handlers ######
|
###### presence_available handlers ######
|
||||||
def account_handle_presence_available(self, name, from_jid, lang_class, show):
|
def account_handle_presence_available(self, name, from_jid, lang_class, show):
|
||||||
"""Handle presence \"available\" sent to an account JID"""
|
"""Handle presence \"available\" sent to an account JID"""
|
||||||
return self.account_handle_presence(name, from_jid, \
|
return self.account_handle_presence(\
|
||||||
|
name, from_jid,
|
||||||
lambda _account: \
|
lambda _account: \
|
||||||
self._send_presence_available(_account, \
|
self._send_presence_available(_account,
|
||||||
show, \
|
show,
|
||||||
lang_class))
|
lang_class))
|
||||||
|
|
||||||
def root_handle_presence_available(self, from_jid, lang_class, show):
|
def root_handle_presence_available(self, from_jid, lang_class, show):
|
||||||
"""Handle presence \"available\" sent to component JID"""
|
"""Handle presence \"available\" sent to component JID"""
|
||||||
return self.root_handle_presence(from_jid, \
|
return self.root_handle_presence(\
|
||||||
|
from_jid,
|
||||||
lambda _account: \
|
lambda _account: \
|
||||||
self._send_presence_available(_account, \
|
self._send_presence_available(_account,
|
||||||
show, \
|
show,
|
||||||
lang_class), \
|
lang_class),
|
||||||
lambda nb_accounts: \
|
lambda nb_accounts: \
|
||||||
self._send_presence_available_root(from_jid, \
|
self._send_presence_available_root(from_jid,
|
||||||
show, \
|
show,
|
||||||
str(nb_accounts) \
|
str(nb_accounts)
|
||||||
+ lang_class.message_status))
|
+ lang_class.message_status))
|
||||||
|
|
||||||
###### presence_unavailable handlers ######
|
###### presence_unavailable handlers ######
|
||||||
def account_handle_presence_unavailable(self, name, from_jid):
|
def account_handle_presence_unavailable(self, name, from_jid):
|
||||||
"""Handle presence \"unavailable\" sent to an account JID"""
|
"""Handle presence \"unavailable\" sent to an account JID"""
|
||||||
return self.account_handle_presence(name, from_jid, \
|
return self.account_handle_presence(\
|
||||||
|
name, from_jid,
|
||||||
lambda _account: \
|
lambda _account: \
|
||||||
self._send_presence_unavailable(_account))
|
self._send_presence_unavailable(_account))
|
||||||
|
|
||||||
def root_handle_presence_unavailable(self, from_jid):
|
def root_handle_presence_unavailable(self, from_jid):
|
||||||
"""Handle presence \"unavailable\" sent to component JID"""
|
"""Handle presence \"unavailable\" sent to component JID"""
|
||||||
return self.root_handle_presence(from_jid, \
|
return self.root_handle_presence(\
|
||||||
|
from_jid,
|
||||||
lambda _account: \
|
lambda _account: \
|
||||||
self._send_presence_unavailable(_account), \
|
self._send_presence_unavailable(_account),
|
||||||
lambda nb_accounts: \
|
lambda nb_accounts: \
|
||||||
self._send_presence_unavailable_root(from_jid))
|
self._send_presence_unavailable_root(from_jid))
|
||||||
|
|
||||||
@@ -878,8 +903,8 @@ class AccountManager(object):
|
|||||||
if self._has_account(from_jid, name):
|
if self._has_account(from_jid, name):
|
||||||
return [stanza.make_accept_response()]
|
return [stanza.make_accept_response()]
|
||||||
else:
|
else:
|
||||||
self.__logger.debug("Account '" + str(name) + "' for user '" + \
|
self.__logger.debug("Account '" + str(name) + "' for user '" +
|
||||||
unicode(from_jid.bare()) + "' was not found. " + \
|
unicode(from_jid.bare()) + "' was not found. " +
|
||||||
"Refusing subscription")
|
"Refusing subscription")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -888,8 +913,9 @@ class AccountManager(object):
|
|||||||
if self._has_account(from_jid):
|
if self._has_account(from_jid):
|
||||||
return [stanza.make_accept_response()]
|
return [stanza.make_accept_response()]
|
||||||
else:
|
else:
|
||||||
self.__logger.debug("User '" + \
|
self.__logger.debug("User '" +
|
||||||
unicode(from_jid.bare()) + "' doesn't have any account. " + \
|
unicode(from_jid.bare()) +
|
||||||
|
"' doesn't have any account. " +
|
||||||
"Refusing subscription")
|
"Refusing subscription")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
@@ -899,14 +925,14 @@ class AccountManager(object):
|
|||||||
result = []
|
result = []
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = Account.select(\
|
accounts = Account.select(\
|
||||||
AND(Account.q.name == name, \
|
AND(Account.q.name == name,
|
||||||
Account.q.user_jid == unicode(from_jid.bare())))
|
Account.q.user_jid == unicode(from_jid.bare())))
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = from_jid, \
|
to_jid=from_jid,
|
||||||
stanza_type="unsubscribe"))
|
stanza_type="unsubscribe"))
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = from_jid, \
|
to_jid=from_jid,
|
||||||
stanza_type="unsubscribed"))
|
stanza_type="unsubscribed"))
|
||||||
_account.destroySelf()
|
_account.destroySelf()
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
@@ -926,7 +952,7 @@ class AccountManager(object):
|
|||||||
Account.q.user_jid == unicode(from_jid.bare()))
|
Account.q.user_jid == unicode(from_jid.bare()))
|
||||||
else:
|
else:
|
||||||
accounts = Account.select(\
|
accounts = Account.select(\
|
||||||
AND(Account.q.name == name, \
|
AND(Account.q.name == name,
|
||||||
Account.q.user_jid == unicode(from_jid.bare())))
|
Account.q.user_jid == unicode(from_jid.bare())))
|
||||||
result = (accounts is not None \
|
result = (accounts is not None \
|
||||||
and accounts.count() > 0)
|
and accounts.count() > 0)
|
||||||
@@ -934,7 +960,8 @@ class AccountManager(object):
|
|||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
def _list_accounts(self, disco_items, _account_class, bare_from_jid, account_type = ""):
|
def _list_accounts(self, disco_items, _account_class, bare_from_jid,
|
||||||
|
account_type=""):
|
||||||
"""List accounts in disco_items for given _account_class and user jid"""
|
"""List accounts in disco_items for given _account_class and user jid"""
|
||||||
if account_type is not None and account_type != "":
|
if account_type is not None and account_type != "":
|
||||||
resource = "/" + account_type
|
resource = "/" + account_type
|
||||||
@@ -945,9 +972,9 @@ class AccountManager(object):
|
|||||||
for _account in _account_class.select(_account_class.q.user_jid == \
|
for _account in _account_class.select(_account_class.q.user_jid == \
|
||||||
unicode(bare_from_jid)):
|
unicode(bare_from_jid)):
|
||||||
self.__logger.debug(str(_account))
|
self.__logger.debug(str(_account))
|
||||||
DiscoItem(disco_items, \
|
DiscoItem(disco_items,
|
||||||
JID(unicode(_account.jid) + resource), \
|
JID(unicode(_account.jid) + resource),
|
||||||
account_type + _account.name, \
|
account_type + _account.name,
|
||||||
_account.long_name)
|
_account.long_name)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
|
|
||||||
@@ -976,18 +1003,18 @@ class AccountManager(object):
|
|||||||
def get_reg_form(self, lang_class, _account_class):
|
def get_reg_form(self, lang_class, _account_class):
|
||||||
"""Return register form based on language and account class
|
"""Return register form based on language and account class
|
||||||
"""
|
"""
|
||||||
reg_form = Form(title = lang_class.register_title, \
|
reg_form = Form(title=lang_class.register_title,
|
||||||
instructions=lang_class.register_instructions)
|
instructions=lang_class.register_instructions)
|
||||||
# "name" field is mandatory
|
# "name" field is mandatory
|
||||||
reg_form.add_field(field_type = "text-single", \
|
reg_form.add_field(field_type="text-single",
|
||||||
label = lang_class.account_name, \
|
label=lang_class.account_name,
|
||||||
name = "name", \
|
name="name",
|
||||||
required=True)
|
required=True)
|
||||||
|
|
||||||
for (field_name, \
|
for (field_name,
|
||||||
field_type, \
|
field_type,
|
||||||
field_options, \
|
field_options,
|
||||||
post_func, \
|
post_func,
|
||||||
default_func) in \
|
default_func) in \
|
||||||
_account_class.get_register_fields():
|
_account_class.get_register_fields():
|
||||||
if field_name is None:
|
if field_name is None:
|
||||||
@@ -1000,9 +1027,9 @@ class AccountManager(object):
|
|||||||
else:
|
else:
|
||||||
label = field_name
|
label = field_name
|
||||||
self.__logger.debug("Adding field " + field_name + " to registration form")
|
self.__logger.debug("Adding field " + field_name + " to registration form")
|
||||||
field = reg_form.add_field(field_type = field_type, \
|
field = reg_form.add_field(field_type=field_type,
|
||||||
label = label, \
|
label=label,
|
||||||
name = field_name, \
|
name=field_name,
|
||||||
value=default_func())
|
value=default_func())
|
||||||
if field_options is not None:
|
if field_options is not None:
|
||||||
for option_value in field_options:
|
for option_value in field_options:
|
||||||
@@ -1011,7 +1038,7 @@ class AccountManager(object):
|
|||||||
label = getattr(lang_class, lang_label_attr)
|
label = getattr(lang_class, lang_label_attr)
|
||||||
else:
|
else:
|
||||||
label = option_value
|
label = option_value
|
||||||
field.add_option(label = label, \
|
field.add_option(label=label,
|
||||||
values=[option_value])
|
values=[option_value])
|
||||||
try:
|
try:
|
||||||
post_func(None, default_func)
|
post_func(None, default_func)
|
||||||
@@ -1038,35 +1065,35 @@ class AccountManager(object):
|
|||||||
|
|
||||||
def _send_presence_probe_root(self, to_jid):
|
def _send_presence_probe_root(self, to_jid):
|
||||||
"""Send presence probe to account's user from root JID"""
|
"""Send presence probe to account's user from root JID"""
|
||||||
return [Presence(from_jid = self.component.jid, \
|
return [Presence(from_jid=self.component.jid,
|
||||||
to_jid = to_jid, \
|
to_jid=to_jid,
|
||||||
stanza_type="probe")]
|
stanza_type="probe")]
|
||||||
|
|
||||||
def _send_presence_probe(self, _account):
|
def _send_presence_probe(self, _account):
|
||||||
"""Send presence probe to account's user"""
|
"""Send presence probe to account's user"""
|
||||||
return [Presence(from_jid = _account.jid, \
|
return [Presence(from_jid=_account.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
stanza_type="probe")]
|
stanza_type="probe")]
|
||||||
|
|
||||||
def _send_presence_unavailable_root(self, to_jid):
|
def _send_presence_unavailable_root(self, to_jid):
|
||||||
"""Send unavailable presence to account's user from root JID"""
|
"""Send unavailable presence to account's user from root JID"""
|
||||||
return [Presence(from_jid = self.component.jid, \
|
return [Presence(from_jid=self.component.jid,
|
||||||
to_jid = to_jid, \
|
to_jid=to_jid,
|
||||||
stanza_type="unavailable")]
|
stanza_type="unavailable")]
|
||||||
|
|
||||||
def _send_presence_unavailable(self, _account):
|
def _send_presence_unavailable(self, _account):
|
||||||
"""Send unavailable presence to account's user"""
|
"""Send unavailable presence to account's user"""
|
||||||
_account.status = account.OFFLINE
|
_account.status = account.OFFLINE
|
||||||
return [Presence(from_jid = _account.jid, \
|
return [Presence(from_jid=_account.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
stanza_type="unavailable")]
|
stanza_type="unavailable")]
|
||||||
|
|
||||||
def _send_presence_available_root(self, to_jid, show, status_msg):
|
def _send_presence_available_root(self, to_jid, show, status_msg):
|
||||||
"""Send available presence to account's user from root JID"""
|
"""Send available presence to account's user from root JID"""
|
||||||
return [Presence(from_jid = self.component.jid, \
|
return [Presence(from_jid=self.component.jid,
|
||||||
to_jid = to_jid, \
|
to_jid=to_jid,
|
||||||
status = status_msg, \
|
status=status_msg,
|
||||||
show = show, \
|
show=show,
|
||||||
stanza_type="available")]
|
stanza_type="available")]
|
||||||
|
|
||||||
def _send_presence_available(self, _account, show, lang_class):
|
def _send_presence_available(self, _account, show, lang_class):
|
||||||
@@ -1079,10 +1106,10 @@ class AccountManager(object):
|
|||||||
_account.status = account.ONLINE
|
_account.status = account.ONLINE
|
||||||
else:
|
else:
|
||||||
_account.status = show
|
_account.status = show
|
||||||
result.append(Presence(from_jid = _account.jid, \
|
result.append(Presence(from_jid=_account.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
status = _account.status_msg, \
|
status=_account.status_msg,
|
||||||
show = show, \
|
show=show,
|
||||||
stanza_type="available"))
|
stanza_type="available"))
|
||||||
if hasattr(_account, 'store_password') \
|
if hasattr(_account, 'store_password') \
|
||||||
and hasattr(_account, 'password') \
|
and hasattr(_account, 'password') \
|
||||||
@@ -1100,10 +1127,10 @@ class AccountManager(object):
|
|||||||
and not _account.waiting_password_reply \
|
and not _account.waiting_password_reply \
|
||||||
and _account.status != account.OFFLINE:
|
and _account.status != account.OFFLINE:
|
||||||
_account.waiting_password_reply = True
|
_account.waiting_password_reply = True
|
||||||
result.append(Message(from_jid = _account.jid, \
|
result.append(Message(from_jid=_account.jid,
|
||||||
to_jid = _account.user_jid, \
|
to_jid=_account.user_jid,
|
||||||
subject=u"[PASSWORD] " + \
|
subject=u"[PASSWORD] " + \
|
||||||
lang_class.ask_password_subject, \
|
lang_class.ask_password_subject,
|
||||||
body=lang_class.ask_password_body % \
|
body=lang_class.ask_password_body % \
|
||||||
(_account.name)))
|
(_account.name)))
|
||||||
return result
|
return result
|
||||||
@@ -1153,11 +1180,11 @@ class DefaultSubscribeHandler(Handler):
|
|||||||
def handle(self, stanza, lang, accounts):
|
def handle(self, stanza, lang, accounts):
|
||||||
"""Create subscribe response"""
|
"""Create subscribe response"""
|
||||||
result = []
|
result = []
|
||||||
result.append(Presence(from_jid = stanza.get_to(), \
|
result.append(Presence(from_jid=stanza.get_to(),
|
||||||
to_jid = stanza.get_from(), \
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="subscribe"))
|
stanza_type="subscribe"))
|
||||||
result.append(Presence(from_jid = stanza.get_to(), \
|
result.append(Presence(from_jid=stanza.get_to(),
|
||||||
to_jid = stanza.get_from(), \
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="subscribed"))
|
stanza_type="subscribed"))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
@@ -1167,11 +1194,11 @@ class DefaultUnsubscribeHandler(Handler):
|
|||||||
def handle(self, stanza, lang, accounts):
|
def handle(self, stanza, lang, accounts):
|
||||||
"""Create subscribe response"""
|
"""Create subscribe response"""
|
||||||
result = []
|
result = []
|
||||||
result.append(Presence(from_jid = stanza.get_to(), \
|
result.append(Presence(from_jid=stanza.get_to(),
|
||||||
to_jid = stanza.get_from(), \
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="unsubscribe"))
|
stanza_type="unsubscribe"))
|
||||||
result.append(Presence(from_jid = stanza.get_to(), \
|
result.append(Presence(from_jid=stanza.get_to(),
|
||||||
to_jid = stanza.get_from(), \
|
to_jid=stanza.get_from(),
|
||||||
stanza_type="unsubscribed"))
|
stanza_type="unsubscribed"))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user