Multiple account types support: disco type listing
Account types are listed, accounts are not yet listed (need tests)
account factory have been replace by account classes naming convention (${type}Account)
darcs-hash:20070131171321-86b55-f1de0bb3e3ddea3b16783a3ec9bf1977bee16d94.gz
This commit is contained in:
@@ -63,7 +63,7 @@ if __name__ == '__main__':
|
|||||||
jcl_suite = unittest.TestSuite()
|
jcl_suite = unittest.TestSuite()
|
||||||
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
# jcl_suite.addTest(FeederComponent_TestCase('test_handle_tick'))
|
||||||
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_set_register_new_field_mandatory'))
|
# jcl_suite.addTest(JCLComponent_TestCase('test_handle_set_register_new_field_mandatory'))
|
||||||
# jcl_suite = unittest.TestSuite((feeder_component_suite))
|
# jcl_suite = unittest.TestSuite((component_suite))
|
||||||
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
# jcl_suite = unittest.TestSuite((presence_account_suite))
|
||||||
jcl_suite = unittest.TestSuite((component_suite, \
|
jcl_suite = unittest.TestSuite((component_suite, \
|
||||||
feeder_component_suite, \
|
feeder_component_suite, \
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ from sqlobject.dbconnection import connectionForURI
|
|||||||
import pyxmpp.error as error
|
import pyxmpp.error as error
|
||||||
from pyxmpp.jid import JID
|
from pyxmpp.jid import JID
|
||||||
from pyxmpp.jabberd.component import Component
|
from pyxmpp.jabberd.component import Component
|
||||||
from pyxmpp.jabber.disco import DiscoInfo, DiscoItems, DiscoItem
|
from pyxmpp.jabber.disco import DiscoInfo, DiscoItems, DiscoItem, DiscoIdentity
|
||||||
from pyxmpp.message import Message
|
from pyxmpp.message import Message
|
||||||
from pyxmpp.presence import Presence
|
from pyxmpp.presence import Presence
|
||||||
|
|
||||||
@@ -88,15 +88,13 @@ class JCLComponent(Component, object):
|
|||||||
self.name = "Jabber Component Library generic component"
|
self.name = "Jabber Component Library generic component"
|
||||||
self.spool_dir = "."
|
self.spool_dir = "."
|
||||||
self.db_connection_str = db_connection_str
|
self.db_connection_str = db_connection_str
|
||||||
self.default_account_class = Account
|
self.account_classes = [Account]
|
||||||
self.account_factory = default_account_factory.create
|
self.account_factory = default_account_factory.create
|
||||||
self.version = VERSION
|
self.version = VERSION
|
||||||
self.accounts = []
|
self.accounts = []
|
||||||
self.time_unit = 60
|
self.time_unit = 60
|
||||||
self.queue = Queue(100)
|
self.queue = Queue(100)
|
||||||
|
|
||||||
self.disco_info.add_feature("jabber:iq:version")
|
|
||||||
self.disco_info.add_feature("jabber:iq:register")
|
|
||||||
self.__logger = logging.getLogger("jcl.jabber.JCLComponent")
|
self.__logger = logging.getLogger("jcl.jabber.JCLComponent")
|
||||||
self.lang = Lang()
|
self.lang = Lang()
|
||||||
self.running = False
|
self.running = False
|
||||||
@@ -104,7 +102,7 @@ class JCLComponent(Component, object):
|
|||||||
|
|
||||||
signal.signal(signal.SIGINT, self.signal_handler)
|
signal.signal(signal.SIGINT, self.signal_handler)
|
||||||
signal.signal(signal.SIGTERM, self.signal_handler)
|
signal.signal(signal.SIGTERM, self.signal_handler)
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Main loop
|
"""Main loop
|
||||||
Connect to Jabber server
|
Connect to Jabber server
|
||||||
@@ -139,7 +137,7 @@ class JCLComponent(Component, 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 \
|
||||||
self.default_account_class.select(clauseTables = ["account"], \
|
self.account_classes[0].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
|
||||||
@@ -229,7 +227,7 @@ class JCLComponent(Component, object):
|
|||||||
self.handle_message)
|
self.handle_message)
|
||||||
current_jid = None
|
current_jid = None
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.default_account_class.select(clauseTables = ["account"], \
|
for _account in self.account_classes[0].select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
if _account.user_jid != current_jid:
|
if _account.user_jid != current_jid:
|
||||||
presence = Presence(from_jid = unicode(self.jid), \
|
presence = Presence(from_jid = unicode(self.jid), \
|
||||||
@@ -253,12 +251,17 @@ class JCLComponent(Component, object):
|
|||||||
"""Discovery get info handler
|
"""Discovery get info handler
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("DISCO_GET_INFO")
|
self.__logger.debug("DISCO_GET_INFO")
|
||||||
|
disco_info = DiscoInfo()
|
||||||
if node is not None:
|
if node is not None:
|
||||||
disco_info = DiscoInfo()
|
|
||||||
disco_info.add_feature("jabber:iq:register")
|
disco_info.add_feature("jabber:iq:register")
|
||||||
return disco_info
|
|
||||||
else:
|
else:
|
||||||
return self.disco_info
|
disco_info.add_feature("jabber:iq:version")
|
||||||
|
if len(self.account_classes) == 1:
|
||||||
|
disco_info.add_feature("jabber:iq:register")
|
||||||
|
DiscoIdentity(disco_info, self.disco_identity.name,
|
||||||
|
self.disco_identity.category,
|
||||||
|
self.disco_identity.type)
|
||||||
|
return disco_info
|
||||||
|
|
||||||
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
|
||||||
@@ -267,14 +270,31 @@ class JCLComponent(Component, object):
|
|||||||
base_from_jid = unicode(info_query.get_from().bare())
|
base_from_jid = unicode(info_query.get_from().bare())
|
||||||
disco_items = DiscoItems()
|
disco_items = DiscoItems()
|
||||||
if not node:
|
if not node:
|
||||||
self.db_connect()
|
if len(self.account_classes) == 1:
|
||||||
for _account in self.default_account_class.select(Account.q.user_jid == \
|
self._list_accounts(disco_items, self.account_classes[0], base_from_jid)
|
||||||
base_from_jid):
|
else:
|
||||||
self.__logger.debug(str(_account))
|
for account_class in self.account_classes:
|
||||||
DiscoItem(disco_items, \
|
regexp_type = re.compile("(.*)Account$")
|
||||||
JID(_account.jid), \
|
match = regexp_type.search(account_class.__name__)
|
||||||
_account.name, _account.long_name)
|
if match is not None:
|
||||||
self.db_disconnect()
|
account_type = match.group(1)
|
||||||
|
DiscoItem(disco_items, \
|
||||||
|
JID(account_type + "@" + unicode(self.jid)), \
|
||||||
|
account_type, \
|
||||||
|
account_type)
|
||||||
|
else:
|
||||||
|
nodes = node.split("/");
|
||||||
|
if len(nodes) == 1 \
|
||||||
|
and len(self.account_classes) > 1:
|
||||||
|
self.__logger.debug("Listing account for " + nodes[0]) # for p1 TODO add type to get_items
|
||||||
|
account_class = self._get_account_class(nodes[0] + "Account")
|
||||||
|
if account_class is not None:
|
||||||
|
self._list_accounts(disco_items, \
|
||||||
|
account_class, \
|
||||||
|
base_from_jid)
|
||||||
|
else:
|
||||||
|
print >> sys.stderr, "Error: " + account_class.__name__ \
|
||||||
|
+ " class not in account_classes"
|
||||||
return disco_items
|
return disco_items
|
||||||
|
|
||||||
def handle_get_version(self, info_query):
|
def handle_get_version(self, info_query):
|
||||||
@@ -300,12 +320,19 @@ class JCLComponent(Component, object):
|
|||||||
query = info_query.new_query("jabber:iq:register")
|
query = info_query.new_query("jabber:iq:register")
|
||||||
if to_jid.node is not None:
|
if to_jid.node is not None:
|
||||||
node_list = to_jid.node.split("/")
|
node_list = to_jid.node.split("/")
|
||||||
if (len(node_list) == 2):
|
name = None
|
||||||
_account_class = globals()[node_list[0] + "Account"]
|
if len(node_list) == 2:
|
||||||
|
_account_class = self._get_account_class(node_list[0] + "Account")
|
||||||
name = node_list[1]
|
name = node_list[1]
|
||||||
else:
|
else:
|
||||||
_account_class = self.default_account_class
|
if len(node_list) == 1:
|
||||||
name = node_list[0]
|
if len(self.account_classes) == 1:
|
||||||
|
_account_class = self.account_classes[0]
|
||||||
|
name = node_list[0]
|
||||||
|
else:
|
||||||
|
_account_class = self._get_account_class(node_list[0] + "Account")
|
||||||
|
self.get_reg_form(lang_class, \
|
||||||
|
_account_class).attach_xml(query)
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in _account_class.select(\
|
for _account in _account_class.select(\
|
||||||
AND(_account_class.q.name == name, \
|
AND(_account_class.q.name == name, \
|
||||||
@@ -315,7 +342,7 @@ class JCLComponent(Component, object):
|
|||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
else:
|
else:
|
||||||
self.get_reg_form(lang_class, \
|
self.get_reg_form(lang_class, \
|
||||||
self.default_account_class).attach_xml(query)
|
self.account_classes[0]).attach_xml(query)
|
||||||
self.stream.send(info_query)
|
self.stream.send(info_query)
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -323,8 +350,8 @@ class JCLComponent(Component, object):
|
|||||||
"""Unsubscribe all accounts associated to 'user_jid' then delete
|
"""Unsubscribe all accounts associated to 'user_jid' then delete
|
||||||
those accounts from the DataBase"""
|
those accounts from the DataBase"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.default_account_class.select(\
|
for _account in self.account_classes[0].select(\
|
||||||
self.default_account_class.q.user_jid == user_jid):
|
self.account_classes[0].q.user_jid == user_jid):
|
||||||
self.__logger.debug("Deleting " + _account.name \
|
self.__logger.debug("Deleting " + _account.name \
|
||||||
+ " for " + user_jid)
|
+ " for " + user_jid)
|
||||||
presence = Presence(from_jid = self.get_jid(_account), \
|
presence = Presence(from_jid = self.get_jid(_account), \
|
||||||
@@ -343,7 +370,7 @@ class JCLComponent(Component, object):
|
|||||||
stanza_type = "unsubscribed")
|
stanza_type = "unsubscribed")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
|
|
||||||
def handle_set_register(self, info_query):
|
def handle_set_register(self, info_query):
|
||||||
"""Handle user registration response
|
"""Handle user registration response
|
||||||
"""
|
"""
|
||||||
@@ -374,14 +401,14 @@ class JCLComponent(Component, object):
|
|||||||
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
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.default_account_class.select(\
|
accounts = Account.select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(Account.q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
Account.q.user_jid == base_from_jid))
|
||||||
accounts_count = accounts.count()
|
accounts_count = accounts.count()
|
||||||
all_accounts = self.default_account_class.select(\
|
all_accounts = Account.select(\
|
||||||
self.default_account_class.q.user_jid == base_from_jid)
|
Account.q.user_jid == base_from_jid)
|
||||||
all_accounts_count = all_accounts.count()
|
all_accounts_count = all_accounts.count()
|
||||||
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
|
||||||
@@ -390,21 +417,27 @@ class JCLComponent(Component, object):
|
|||||||
if accounts_count >= 1:
|
if accounts_count >= 1:
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
else:
|
else:
|
||||||
_account = self.account_factory(\
|
if info_query.get_to().node is None:
|
||||||
user_jid = base_from_jid, \
|
if len(self.account_classes) > 1:
|
||||||
name = name, \
|
print >>sys.stderr, "There should be only one account class declared"
|
||||||
jid = name + u"@" + unicode(self.jid), \
|
new_account_class = self.account_classes[0]
|
||||||
x_data = x_data)
|
else:
|
||||||
|
new_account_class = self._get_account_class(info_query.get_to().node + "Account")
|
||||||
|
_account = new_account_class(user_jid = unicode(base_from_jid), \
|
||||||
|
name = name, \
|
||||||
|
jid = name + u"@" + unicode(self.jid))
|
||||||
field = None
|
field = None
|
||||||
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():
|
||||||
setattr(_account, field, \
|
if field is not None:
|
||||||
x_data.get_field_value(field, \
|
setattr(_account, field, \
|
||||||
field_post_func, \
|
x_data.get_field_value(field, \
|
||||||
field_default_func))
|
field_post_func, \
|
||||||
|
field_default_func))
|
||||||
except FieldError, exception:
|
except FieldError, exception:
|
||||||
_account.destroySelf()
|
_account.destroySelf()
|
||||||
|
print >>sys.stderr, str(exception)
|
||||||
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(None, \
|
||||||
"text", \
|
"text", \
|
||||||
@@ -441,7 +474,7 @@ class JCLComponent(Component, object):
|
|||||||
"""Handle presence availability
|
"""Handle presence availability
|
||||||
if presence sent to the component ('if not name'), presence is sent to
|
if presence sent to the component ('if not name'), presence is sent to
|
||||||
all accounts for current user. Otherwise, send presence from current account.
|
all accounts for current user. Otherwise, send presence from current account.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
self.__logger.debug("PRESENCE_AVAILABLE")
|
self.__logger.debug("PRESENCE_AVAILABLE")
|
||||||
from_jid = stanza.get_from()
|
from_jid = stanza.get_from()
|
||||||
@@ -454,8 +487,8 @@ class JCLComponent(Component, object):
|
|||||||
self.__logger.debug("TO : " + name + " " + base_from_jid)
|
self.__logger.debug("TO : " + name + " " + base_from_jid)
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
self.default_account_class.q.user_jid == base_from_jid)
|
self.account_classes[0].q.user_jid == base_from_jid)
|
||||||
accounts_length = 0
|
accounts_length = 0
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
accounts_length += 1
|
accounts_length += 1
|
||||||
@@ -470,9 +503,9 @@ class JCLComponent(Component, object):
|
|||||||
stanza_type = "available")
|
stanza_type = "available")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
else:
|
else:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(self.account_classes[0].q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
self.account_classes[0].q.user_jid == base_from_jid))
|
||||||
if accounts.count() > 0:
|
if accounts.count() > 0:
|
||||||
self._send_presence_available(accounts[0], show, lang_class)
|
self._send_presence_available(accounts[0], show, lang_class)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
@@ -487,8 +520,8 @@ class JCLComponent(Component, object):
|
|||||||
name = stanza.get_to().node
|
name = stanza.get_to().node
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
self.default_account_class.q.user_jid == base_from_jid)
|
self.account_classes[0].q.user_jid == base_from_jid)
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
_account.status = jcl.model.account.OFFLINE
|
_account.status = jcl.model.account.OFFLINE
|
||||||
presence = Presence(from_jid = _account.jid, \
|
presence = Presence(from_jid = _account.jid, \
|
||||||
@@ -501,14 +534,14 @@ class JCLComponent(Component, object):
|
|||||||
stanza_type = "unavailable")
|
stanza_type = "unavailable")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
else:
|
else:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(self.account_classes[0].q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
self.account_classes[0].q.user_jid == base_from_jid))
|
||||||
if accounts.count() > 0:
|
if accounts.count() > 0:
|
||||||
presence = Presence(from_jid = stanza.get_to(), \
|
presence = Presence(from_jid = stanza.get_to(), \
|
||||||
to_jid = from_jid, \
|
to_jid = from_jid, \
|
||||||
stanza_type = "unavailable")
|
stanza_type = "unavailable")
|
||||||
self.stream.send(presence)
|
self.stream.send(presence)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
@@ -522,12 +555,12 @@ class JCLComponent(Component, object):
|
|||||||
accounts = None
|
accounts = None
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
if not name:
|
if not name:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
self.default_account_class.q.user_jid == base_from_jid)
|
self.account_classes[0].q.user_jid == base_from_jid)
|
||||||
else:
|
else:
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(self.account_classes[0].q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
self.account_classes[0].q.user_jid == base_from_jid))
|
||||||
if (accounts is not None \
|
if (accounts is not None \
|
||||||
and accounts.count() > 0):
|
and accounts.count() > 0):
|
||||||
presence = stanza.make_accept_response()
|
presence = stanza.make_accept_response()
|
||||||
@@ -549,9 +582,9 @@ class JCLComponent(Component, object):
|
|||||||
from_jid = stanza.get_from()
|
from_jid = stanza.get_from()
|
||||||
base_from_jid = unicode(from_jid.bare())
|
base_from_jid = unicode(from_jid.bare())
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(self.account_classes[0].q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
self.account_classes[0].q.user_jid == base_from_jid))
|
||||||
for _account in accounts:
|
for _account in accounts:
|
||||||
presence = Presence(from_jid = _account.jid, \
|
presence = Presence(from_jid = _account.jid, \
|
||||||
to_jid = from_jid, \
|
to_jid = from_jid, \
|
||||||
@@ -584,9 +617,9 @@ class JCLComponent(Component, object):
|
|||||||
name = message.get_to().node
|
name = message.get_to().node
|
||||||
base_from_jid = unicode(message.get_from().bare())
|
base_from_jid = unicode(message.get_from().bare())
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
accounts = self.default_account_class.select(\
|
accounts = self.account_classes[0].select(\
|
||||||
AND(self.default_account_class.q.name == name, \
|
AND(self.account_classes[0].q.name == name, \
|
||||||
self.default_account_class.q.user_jid == base_from_jid))
|
self.account_classes[0].q.user_jid == base_from_jid))
|
||||||
if accounts.count() == 1:
|
if accounts.count() == 1:
|
||||||
_account = list(accounts)[0]
|
_account = list(accounts)[0]
|
||||||
if hasattr(_account, 'password') \
|
if hasattr(_account, 'password') \
|
||||||
@@ -607,6 +640,27 @@ class JCLComponent(Component, object):
|
|||||||
###########################################################################
|
###########################################################################
|
||||||
# Utils
|
# Utils
|
||||||
###########################################################################
|
###########################################################################
|
||||||
|
def _get_account_class(self, account_class_name):
|
||||||
|
"""Return account class definition from declared classes in
|
||||||
|
account_classes from its class name"""
|
||||||
|
self.__logger.debug("Looking for " + account_class_name)
|
||||||
|
for _account_class in self.account_classes:
|
||||||
|
if _account_class.__name__.lower() == account_class_name.lower():
|
||||||
|
self.__logger.debug(account_class_name + " found")
|
||||||
|
return _account_class
|
||||||
|
return None
|
||||||
|
|
||||||
|
def _list_accounts(self, disco_items, _account_class, base_from_jid):
|
||||||
|
"""List accounts in disco_items for given _account_class and user jid"""
|
||||||
|
self.db_connect()
|
||||||
|
for _account in _account_class.select(_account_class.q.user_jid == \
|
||||||
|
base_from_jid):
|
||||||
|
self.__logger.debug(str(_account))
|
||||||
|
DiscoItem(disco_items, \
|
||||||
|
JID(_account.jid), \
|
||||||
|
_account.name, _account.long_name)
|
||||||
|
self.db_disconnect()
|
||||||
|
|
||||||
def _send_presence_available(self, _account, show, lang_class):
|
def _send_presence_available(self, _account, show, lang_class):
|
||||||
"""Send available presence to account's user and ask for password
|
"""Send available presence to account's user and ask for password
|
||||||
if necessary"""
|
if necessary"""
|
||||||
|
|||||||
@@ -58,8 +58,8 @@ class FeederComponent(JCLComponent):
|
|||||||
def handle_tick(self):
|
def handle_tick(self):
|
||||||
"""Implement main feed/send behavior"""
|
"""Implement main feed/send behavior"""
|
||||||
self.db_connect()
|
self.db_connect()
|
||||||
for _account in self.default_account_class.select(clauseTables = ["account"], \
|
for _account in self.account_classes[0].select(clauseTables = ["account"], \
|
||||||
orderBy = "user_jid"):
|
orderBy = "user_jid"):
|
||||||
for data in self.feeder.feed(_account):
|
for data in self.feeder.feed(_account):
|
||||||
self.sender.send(_account, data)
|
self.sender.send(_account, data)
|
||||||
self.db_disconnect()
|
self.db_disconnect()
|
||||||
|
|||||||
@@ -79,6 +79,9 @@ class Lang:
|
|||||||
new_account_message_subject = u"New account '%s' created"
|
new_account_message_subject = u"New account '%s' created"
|
||||||
new_account_message_body = u"New account created"
|
new_account_message_body = u"New account created"
|
||||||
mandatory_field = u"%s is required"
|
mandatory_field = u"%s is required"
|
||||||
|
|
||||||
|
presence_action_0 = u"Do nothing"
|
||||||
|
presence_chat_action_0 = presence_action_0
|
||||||
|
|
||||||
# account_login = u"Login"
|
# account_login = u"Login"
|
||||||
# account_password = u"Password"
|
# account_password = u"Password"
|
||||||
|
|||||||
@@ -188,8 +188,8 @@ class PresenceAccount(Account):
|
|||||||
def _get_register_fields(cls):
|
def _get_register_fields(cls):
|
||||||
""" See Account._get_register_fields """
|
""" See Account._get_register_fields """
|
||||||
def is_action_possible(action):
|
def is_action_possible(action):
|
||||||
if action in cls.possibles_actions:
|
if int(action) in cls.possibles_actions:
|
||||||
return action
|
return int(action)
|
||||||
raise FieldError # TODO : add translated message
|
raise FieldError # TODO : add translated message
|
||||||
|
|
||||||
# TODO : check is_action_possible with presence_actions_fields (see partial eval function)
|
# TODO : check is_action_possible with presence_actions_fields (see partial eval function)
|
||||||
|
|||||||
@@ -316,10 +316,13 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_disco_get_info_node(self):
|
def test_disco_get_info_node(self):
|
||||||
disco_info = self.comp.disco_get_info("node_test", None)
|
disco_info = self.comp.disco_get_info("node_test", None)
|
||||||
self.assertFalse(disco_info.has_feature("jabber:iq:version"))
|
|
||||||
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
||||||
|
|
||||||
def test_disco_get_items_no_node(self):
|
def test_disco_get_info_long_node(self):
|
||||||
|
disco_info = self.comp.disco_get_info("node_type/node_test", None)
|
||||||
|
self.assertTrue(disco_info.has_feature("jabber:iq:register"))
|
||||||
|
|
||||||
|
def test_disco_get_items_1type_no_node(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
account1 = Account(user_jid = "user1@test.com", \
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
name = "account1", \
|
name = "account1", \
|
||||||
@@ -334,7 +337,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEquals(disco_item.get_node(), account1.name)
|
self.assertEquals(disco_item.get_node(), account1.name)
|
||||||
self.assertEquals(disco_item.get_name(), account1.long_name)
|
self.assertEquals(disco_item.get_name(), account1.long_name)
|
||||||
|
|
||||||
def test_disco_get_items_with_node(self):
|
def test_disco_get_items_1type_with_node(self):
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
account1 = Account(user_jid = "user1@test.com", \
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
name = "account1", \
|
name = "account1", \
|
||||||
@@ -345,6 +348,58 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
disco_items = self.comp.disco_get_items("account1", info_query)
|
disco_items = self.comp.disco_get_items("account1", info_query)
|
||||||
self.assertEquals(disco_items.get_items(), [])
|
self.assertEquals(disco_items.get_items(), [])
|
||||||
|
|
||||||
|
# TODO : test get_items with multiple account_classes
|
||||||
|
def test_disco_get_items_2types_no_node(self):
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account1", \
|
||||||
|
jid = "account1@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
info_query = Iq(stanza_type = "get", \
|
||||||
|
from_jid = "user1@test.com")
|
||||||
|
disco_items = self.comp.disco_get_items(None, info_query)
|
||||||
|
self.assertEquals(len(disco_items.get_items()), 1)
|
||||||
|
disco_item = disco_items.get_items()[0]
|
||||||
|
self.assertEquals(disco_item.get_jid(), account1.jid)
|
||||||
|
self.assertEquals(disco_item.get_node(), account1.name)
|
||||||
|
self.assertEquals(disco_item.get_name(), account1.long_name)
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
def test_disco_get_items_2types_with_node(self):
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account1", \
|
||||||
|
jid = "account1@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
info_query = Iq(stanza_type = "get", \
|
||||||
|
from_jid = "user1@test.com")
|
||||||
|
disco_items = self.comp.disco_get_items("account1", info_query)
|
||||||
|
self.assertEquals(disco_items.get_items(), [])
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
def test_disco_get_items_2types_with_long_node(self):
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account1", \
|
||||||
|
jid = "account1@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
info_query = Iq(stanza_type = "get", \
|
||||||
|
from_jid = "user1@test.com")
|
||||||
|
disco_items = self.comp.disco_get_items("type1/account1", info_query)
|
||||||
|
self.assertEquals(disco_items.get_items(), [])
|
||||||
|
|
||||||
|
# TODO
|
||||||
|
def test_disco_get_items_2types_with_long_node2(self):
|
||||||
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
|
account1 = Account(user_jid = "user1@test.com", \
|
||||||
|
name = "account1", \
|
||||||
|
jid = "account1@jcl.test.com")
|
||||||
|
del account.hub.threadConnection
|
||||||
|
info_query = Iq(stanza_type = "get", \
|
||||||
|
from_jid = "user1@test.com")
|
||||||
|
disco_items = self.comp.disco_get_items("type2/account1", info_query)
|
||||||
|
self.assertEquals(disco_items.get_items(), [])
|
||||||
|
|
||||||
def test_handle_get_version(self):
|
def test_handle_get_version(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
@@ -396,7 +451,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
def test_handle_get_register_new_complex(self):
|
def test_handle_get_register_new_complex(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.default_account_class = AccountExample
|
self.comp.account_classes = [AccountExample]
|
||||||
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
self.comp.handle_get_register(Iq(stanza_type = "get", \
|
||||||
from_jid = "user1@test.com", \
|
from_jid = "user1@test.com", \
|
||||||
to_jid = "jcl.test.com"))
|
to_jid = "jcl.test.com"))
|
||||||
@@ -627,9 +682,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -671,10 +726,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
def test_handle_set_register_new_complex(self):
|
def test_handle_set_register_new_complex(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
self.comp.account_classes = [AccountExample]
|
||||||
AccountExample(user_jid = user_jid, \
|
|
||||||
name = name, \
|
|
||||||
jid = jid))
|
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -704,9 +756,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -753,10 +805,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
def test_handle_set_register_new_default_values(self):
|
def test_handle_set_register_new_default_values(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
self.comp.account_classes = [AccountExample]
|
||||||
AccountExample(user_jid = user_jid, \
|
|
||||||
name = name, \
|
|
||||||
jid = jid))
|
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -774,9 +823,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -803,9 +852,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -822,10 +871,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
def test_handle_set_register_new_field_mandatory(self):
|
def test_handle_set_register_new_field_mandatory(self):
|
||||||
self.comp.stream = MockStream()
|
self.comp.stream = MockStream()
|
||||||
self.comp.stream_class = MockStream
|
self.comp.stream_class = MockStream
|
||||||
self.comp.account_factory = (lambda user_jid, name, jid, x_data: \
|
self.comp.account_classes = [AccountExample]
|
||||||
AccountExample(user_jid = user_jid, \
|
|
||||||
name = name, \
|
|
||||||
jid = jid))
|
|
||||||
x_data = DataForm()
|
x_data = DataForm()
|
||||||
x_data.xmlns = "jabber:x:data"
|
x_data.xmlns = "jabber:x:data"
|
||||||
x_data.type = "submit"
|
x_data.type = "submit"
|
||||||
@@ -840,9 +886,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -906,9 +952,9 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account1")
|
and self.comp.account_classes[0].q.name == "account1")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user1@test.com")
|
self.assertEquals(_account.user_jid, "user1@test.com")
|
||||||
@@ -960,11 +1006,11 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.comp.handle_set_register(iq_set)
|
self.comp.handle_set_register(iq_set)
|
||||||
|
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com")
|
self.comp.account_classes[0].q.user_jid == "user1@test.com")
|
||||||
self.assertEquals(accounts.count(), 0)
|
self.assertEquals(accounts.count(), 0)
|
||||||
accounts = self.comp.default_account_class.select(\
|
accounts = self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user2@test.com")
|
self.comp.account_classes[0].q.user_jid == "user2@test.com")
|
||||||
self.assertEquals(accounts.count(), 1)
|
self.assertEquals(accounts.count(), 1)
|
||||||
_account = accounts[0]
|
_account = accounts[0]
|
||||||
self.assertEquals(_account.user_jid, "user2@test.com")
|
self.assertEquals(_account.user_jid, "user2@test.com")
|
||||||
@@ -1495,14 +1541,14 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
self.assertEqual(presence.xpath_eval("@type")[0].get_content(), \
|
self.assertEqual(presence.xpath_eval("@type")[0].get_content(), \
|
||||||
"unsubscribed")
|
"unsubscribed")
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.default_account_class.select(\
|
self.assertEquals(self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com" \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com" \
|
||||||
and self.comp.default_account_class.q.name == "account11").count(), \
|
and self.comp.account_classes[0].q.name == "account11").count(), \
|
||||||
0)
|
0)
|
||||||
self.assertEquals(self.comp.default_account_class.select(\
|
self.assertEquals(self.comp.account_classes[0].select(\
|
||||||
self.comp.default_account_class.q.user_jid == "user1@test.com").count(), \
|
self.comp.account_classes[0].q.user_jid == "user1@test.com").count(), \
|
||||||
1)
|
1)
|
||||||
self.assertEquals(self.comp.default_account_class.select().count(), \
|
self.assertEquals(self.comp.account_classes[0].select().count(), \
|
||||||
2)
|
2)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -1527,7 +1573,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
presence_sent = self.comp.stream.sent
|
presence_sent = self.comp.stream.sent
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.default_account_class.select().count(), \
|
self.assertEquals(self.comp.account_classes[0].select().count(), \
|
||||||
3)
|
3)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
@@ -1553,7 +1599,7 @@ class JCLComponent_TestCase(unittest.TestCase):
|
|||||||
presence_sent = self.comp.stream.sent
|
presence_sent = self.comp.stream.sent
|
||||||
self.assertEqual(len(presence_sent), 0)
|
self.assertEqual(len(presence_sent), 0)
|
||||||
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
account.hub.threadConnection = connectionForURI('sqlite://' + DB_URL)
|
||||||
self.assertEquals(self.comp.default_account_class.select().count(), \
|
self.assertEquals(self.comp.account_classes[0].select().count(), \
|
||||||
3)
|
3)
|
||||||
del account.hub.threadConnection
|
del account.hub.threadConnection
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user