some pylint cleaning

darcs-hash:20061110082407-86b55-344fcaf1a5b2057e9917f2d54d34cf40c8a5eb8b.gz
This commit is contained in:
David Rousselie
2006-11-10 09:24:07 +01:00
parent b2fca94692
commit 521f3cd892
4 changed files with 55 additions and 63 deletions

View File

@@ -43,12 +43,12 @@ from pyxmpp.jabberd.component import Component
from pyxmpp.jabber.disco import DiscoInfo, DiscoItems, DiscoItem from pyxmpp.jabber.disco import DiscoInfo, DiscoItems, DiscoItem
from pyxmpp.message import Message from pyxmpp.message import Message
from pyxmpp.presence import Presence from pyxmpp.presence import Presence
from pyxmpp.streambase import StreamError, FatalStreamError
import jcl import jcl
from jcl.jabber.x import X from jcl.jabber.x import DataForm
from jcl.jabber.error import FieldError
from jcl.model import account from jcl.model import account
from jcl.model.account import * from jcl.model.account import Account
from jcl.lang import Lang from jcl.lang import Lang
VERSION = "0.1" VERSION = "0.1"
@@ -137,10 +137,10 @@ class JCLComponent(Component, object):
self.stream.loop_iter(JCLComponent.timeout) self.stream.loop_iter(JCLComponent.timeout)
if self.queue.qsize(): if self.queue.qsize():
raise self.queue.get(0) raise self.queue.get(0)
except Exception, e: except Exception, exception:
#self.__logger.exception("Exception cought:") #self.__logger.exception("Exception cought:")
# put Exception in queue to be use by unit tests # put Exception in queue to be use by unit tests
self.queue.put(e) self.queue.put(exception)
raise raise
finally: finally:
if self.stream and not self.stream.eof \ if self.stream and not self.stream.eof \
@@ -160,31 +160,22 @@ class JCLComponent(Component, object):
to_jid = _account.user_jid, \ to_jid = _account.user_jid, \
stanza_type = "unavailable")) stanza_type = "unavailable"))
self.db_disconnect() self.db_disconnect()
# threads = threading.enumerate()
timer_thread.join(JCLComponent.timeout) timer_thread.join(JCLComponent.timeout)
# for _thread in threads:
# try:
# _thread.join(10 * JCLComponent.timeout)
# except:
# pass
# for _thread in threads:
# try:
# _thread.join(JCLComponent.timeout)
# except:
# pass
self.disconnect() self.disconnect()
self.__logger.debug("Exitting normally") self.__logger.debug("Exitting normally")
# TODO : terminate SQLObject
################# #################
# SQlite connections are not multi-threaded # SQlite connections are not multi-threaded
# Utils workaround methods # Utils workaround methods
################# #################
def db_connect(self): def db_connect(self):
"""Create a new connection to the DataBase (SQLObject use connection
pool) associated to the current thread"""
account.hub.threadConnection = \ account.hub.threadConnection = \
connectionForURI(self.db_connection_str) connectionForURI(self.db_connection_str)
def db_disconnect(self): def db_disconnect(self):
"""Delete connection associated to the current thread"""
del account.hub.threadConnection del account.hub.threadConnection
@@ -202,8 +193,8 @@ class JCLComponent(Component, object):
self.handle_tick() self.handle_tick()
self.__logger.debug("Resetting alarm signal") self.__logger.debug("Resetting alarm signal")
time.sleep(self.time_unit) time.sleep(self.time_unit)
except Exception, e: except Exception, exception:
self.queue.put(e) self.queue.put(exception)
raise raise
def authenticated(self): def authenticated(self):
@@ -242,15 +233,15 @@ 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.account_class.select(orderBy = "user_jid"): for _account in self.account_class.select(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), \
to_jid = account.user_jid, \ to_jid = _account.user_jid, \
stanza_type = "probe") stanza_type = "probe")
self.stream.send(presence) self.stream.send(presence)
current_jid = account.user_jid current_jid = _account.user_jid
presence = Presence(from_jid = self.get_jid(account), \ presence = Presence(from_jid = _account.jid, \
to_jid = account.user_jid, \ to_jid = _account.user_jid, \
stanza_type = "probe") stanza_type = "probe")
self.stream.send(presence) self.stream.send(presence)
self.db_disconnect() self.db_disconnect()
@@ -324,6 +315,8 @@ class JCLComponent(Component, object):
return 1 return 1
def remove_all_accounts(self, user_jid): def remove_all_accounts(self, user_jid):
"""Unsubscribe all accounts associated to 'user_jid' then delete
those accounts from the DataBase"""
self.db_connect() self.db_connect()
for _account in self.account_class.select(\ for _account in self.account_class.select(\
self.account_class.q.user_jid == user_jid): self.account_class.q.user_jid == user_jid):
@@ -361,7 +354,7 @@ class JCLComponent(Component, object):
return 1 return 1
query = info_query.get_query() query = info_query.get_query()
x_data = X() x_data = DataForm()
x_data.from_xml(query.children) x_data.from_xml(query.children)
name = x_data.get_field_value("name") name = x_data.get_field_value("name")
if name is None: if name is None:
@@ -380,7 +373,7 @@ class JCLComponent(Component, object):
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
print >>sys.stderr, "There might not exist 2 accounts for " + \ print >> sys.stderr, "There might not exist 2 accounts for " + \
base_from_jid + " and named " + name base_from_jid + " and named " + name
if accounts_count >= 1: if accounts_count >= 1:
_account = list(accounts)[0] _account = list(accounts)[0]
@@ -395,9 +388,9 @@ class JCLComponent(Component, object):
x_data.get_field_value(field, \ x_data.get_field_value(field, \
field_post_func, \ field_post_func, \
field_default_func)) field_default_func))
except FieldError, e: except FieldError, exception:
_account.destroySelf() _account.destroySelf()
# TODO: get correct error from e # TODO: get correct error from exception
info_query = info_query.make_error_response("resource-constraint") info_query = info_query.make_error_response("resource-constraint")
self.stream.send(info_query) self.stream.send(info_query)
self.db_disconnect() self.db_disconnect()
@@ -445,7 +438,7 @@ class JCLComponent(Component, object):
# TODO: Translate # TODO: Translate
accounts_length = 0 accounts_length = 0
for _account in accounts: for _account in accounts:
++accounts_length accounts_length += 1
self._send_presence_available(_account, show, lang_class) self._send_presence_available(_account, show, lang_class)
presence = Presence(from_jid = self.jid, \ presence = Presence(from_jid = self.jid, \
to_jid = from_jid, \ to_jid = from_jid, \
@@ -472,10 +465,10 @@ class JCLComponent(Component, object):
base_from_jid = unicode(from_jid.bare()) base_from_jid = unicode(from_jid.bare())
if stanza.get_to() == unicode(self.jid): if stanza.get_to() == unicode(self.jid):
self.db_connect() self.db_connect()
for account in self.account_class.select(\ for _account in self.account_class.select(\
self.account_class.q.user_jid == base_from_jid): self.account_class.q.user_jid == base_from_jid):
account.status = jcl.model.account.OFFLINE _account.status = jcl.model.account.OFFLINE
presence = Presence(from_jid = account.jid, \ presence = Presence(from_jid = _account.jid, \
to_jid = from_jid, \ to_jid = from_jid, \
stanza_type = "unavailable") stanza_type = "unavailable")
self.stream.send(presence) self.stream.send(presence)
@@ -558,10 +551,10 @@ class JCLComponent(Component, object):
and re.compile("\[PASSWORD\]").search(message.get_subject()) \ and re.compile("\[PASSWORD\]").search(message.get_subject()) \
is not None \ is not None \
and accounts.count() == 1: and accounts.count() == 1:
account = list(accounts)[0] _account = list(accounts)[0]
account.password = message.get_body() _account.password = message.get_body()
account.waiting_password_reply = False _account.waiting_password_reply = False
msg = Message(from_jid = account.jid, \ msg = Message(from_jid = _account.jid, \
to_jid = message.get_from(), \ to_jid = message.get_from(), \
stanza_type = "normal", \ stanza_type = "normal", \
subject = lang_class.password_saved_for_session, \ subject = lang_class.password_saved_for_session, \
@@ -579,15 +572,14 @@ class JCLComponent(Component, object):
_account.default_lang_class = lang_class _account.default_lang_class = lang_class
old_status = _account.status old_status = _account.status
if show is None: if show is None:
_account.status = account.ONLINE # TODO get real status = (not show) _account.status = account.ONLINE
else: else:
_account.status = show _account.status = show
p = Presence(from_jid = _account.jid, \ self.stream.send(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"))
self.stream.send(p)
if hasattr(self.account_class, 'store_password') \ if hasattr(self.account_class, 'store_password') \
and hasattr(self.account_class, 'password') \ and hasattr(self.account_class, 'password') \
and _account.store_password == False \ and _account.store_password == False \
@@ -619,7 +611,7 @@ class JCLComponent(Component, object):
def get_reg_form(self, lang_class): def get_reg_form(self, lang_class):
"""Return register form based on language and account class """Return register form based on language and account class
""" """
reg_form = X() reg_form = DataForm()
reg_form.xmlns = "jabber:x:data" reg_form.xmlns = "jabber:x:data"
reg_form.title = lang_class.register_title reg_form.title = lang_class.register_title
reg_form.instructions = lang_class.register_instructions reg_form.instructions = lang_class.register_instructions
@@ -645,15 +637,15 @@ class JCLComponent(Component, object):
## TODO : get default value if any ## TODO : get default value if any
return reg_form return reg_form
def get_reg_form_init(self, lang_class, account): def get_reg_form_init(self, lang_class, _account):
"""Return register form for an existing account (update) """Return register form for an existing account (update)
""" """
reg_form = self.get_reg_form(lang_class) reg_form = self.get_reg_form(lang_class)
reg_form.fields["name"].value = account.name reg_form.fields["name"].value = _account.name
reg_form.fields["name"].type = "hidden" reg_form.fields["name"].type = "hidden"
for (field_name, field) in reg_form.fields.items(): for (field_name, field) in reg_form.fields.items():
if hasattr(self.account_class, field_name): if hasattr(self.account_class, field_name):
field.value = str(getattr(account, field_name)) field.value = str(getattr(_account, field_name))
return reg_form return reg_form
########################################################################### ###########################################################################

View File

@@ -20,7 +20,7 @@
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
## ##
"""X -- X data handling """X -- Data Form handling
""" """
__revision__ = "$Id: x.py,v 1.3 2005/09/18 20:24:07 dax Exp $" __revision__ = "$Id: x.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
@@ -85,8 +85,8 @@ class Field(object):
option.get_xml(field) option.get_xml(field)
return field return field
class X(object): class DataForm(object):
"""Jabber Xdata form """Jabber Data Form
""" """
def __init__(self): def __init__(self):
self.fields = {} self.fields = {}

View File

@@ -27,7 +27,7 @@
__revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $" __revision__ = "$Id: account.py,v 1.3 2005/09/18 20:24:07 dax Exp $"
from sqlobject.main import SQLObject from sqlobject.main import SQLObject
from sqlobject.col import StringCol, BoolCol from sqlobject.col import StringCol
from sqlobject.dbconnection import ConnectionHub from sqlobject.dbconnection import ConnectionHub
from jcl.lang import Lang from jcl.lang import Lang
@@ -103,12 +103,12 @@ class Account(SQLObject):
if hasattr(self.__class__, 'waiting_password_reply') \ if hasattr(self.__class__, 'waiting_password_reply') \
and hasattr(self.__class__, 'store_password') \ and hasattr(self.__class__, 'store_password') \
and hasattr(self.__class__, 'password'): and hasattr(self.__class__, 'password'):
self.waiting_password_reply = False setattr(self.__class__, 'waiting_password_reply', False)
if not self.store_password: if not getattr(self.__class__, 'store_password'):
self.password = None setattr(self.__class__, 'password', None)
else: else:
# TODO seems a bug : first_check = True only if previous status # TODO seems to be a bug : first_check = True only
# was OFFLINE # if previous status was OFFLINE
self.first_check = True self.first_check = True
self.__status = status self.__status = status

View File

@@ -41,7 +41,7 @@ from jcl.jabber.component import JCLComponent
from jcl.model import account from jcl.model import account
from jcl.model.account import Account from jcl.model.account import Account
from jcl.lang import Lang from jcl.lang import Lang
from jcl.jabber.x import X from jcl.jabber.x import DataForm
from tests.jcl.model.account import AccountExample from tests.jcl.model.account import AccountExample
@@ -557,7 +557,7 @@ class JCLComponent_TestCase(unittest.TestCase):
def test_handle_set_register_new(self): def test_handle_set_register_new(self):
self.comp.stream = MockStream() self.comp.stream = MockStream()
self.comp.stream_class = MockStream self.comp.stream_class = MockStream
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
x_data.add_field(field_type = "text-single", \ x_data.add_field(field_type = "text-single", \
@@ -616,7 +616,7 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.account_class = AccountExample self.comp.account_class = AccountExample
self.comp.stream = MockStream() self.comp.stream = MockStream()
self.comp.stream_class = MockStream self.comp.stream_class = MockStream
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
x_data.add_field(field_type = "text-single", \ x_data.add_field(field_type = "text-single", \
@@ -695,7 +695,7 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.account_class = AccountExample self.comp.account_class = AccountExample
self.comp.stream = MockStream() self.comp.stream = MockStream()
self.comp.stream_class = MockStream self.comp.stream_class = MockStream
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
x_data.add_field(field_type = "text-single", \ x_data.add_field(field_type = "text-single", \
@@ -731,7 +731,7 @@ class JCLComponent_TestCase(unittest.TestCase):
self.comp.account_class = AccountExample self.comp.account_class = AccountExample
self.comp.stream = MockStream() self.comp.stream = MockStream()
self.comp.stream_class = MockStream self.comp.stream_class = MockStream
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
iq_set = Iq(stanza_type = "set", \ iq_set = Iq(stanza_type = "set", \
@@ -751,13 +751,13 @@ class JCLComponent_TestCase(unittest.TestCase):
stanza_sent = self.comp.stream.sent stanza_sent = self.comp.stream.sent
self.assertEquals(len(stanza_sent), 1) self.assertEquals(len(stanza_sent), 1)
self.assertTrue(isinstance(stanza_sent[0], Iq)) self.assertTrue(isinstance(stanza_sent[0], Iq))
# TODO : add more assertions # TODO : add more assertions need to find the correct exception
def test_handle_set_register_new_field_mandatory(self): def test_handle_set_register_new_field_mandatory(self):
self.comp.account_class = AccountExample self.comp.account_class = AccountExample
self.comp.stream = MockStream() self.comp.stream = MockStream()
self.comp.stream_class = MockStream self.comp.stream_class = MockStream
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
x_data.add_field(field_type = "text-single", \ x_data.add_field(field_type = "text-single", \
@@ -780,7 +780,7 @@ class JCLComponent_TestCase(unittest.TestCase):
stanza_sent = self.comp.stream.sent stanza_sent = self.comp.stream.sent
self.assertEquals(len(stanza_sent), 1) self.assertEquals(len(stanza_sent), 1)
self.assertTrue(isinstance(stanza_sent[0], Iq)) self.assertTrue(isinstance(stanza_sent[0], Iq))
# TODO : add more assertions # TODO : add more assertions need to find the correct exception
def test_handle_set_register_update_complex(self): def test_handle_set_register_update_complex(self):
self.comp.account_class = AccountExample self.comp.account_class = AccountExample
@@ -804,7 +804,7 @@ class JCLComponent_TestCase(unittest.TestCase):
test_enum = "choice1", \ test_enum = "choice1", \
test_int = 21) test_int = 21)
del account.hub.threadConnection del account.hub.threadConnection
x_data = X() x_data = DataForm()
x_data.xmlns = "jabber:x:data" x_data.xmlns = "jabber:x:data"
x_data.type = "submit" x_data.type = "submit"
x_data.add_field(field_type = "text-single", \ x_data.add_field(field_type = "text-single", \