diff options
author | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-15 09:42:08 +0200 |
---|---|---|
committer | Duda Dornelles <ddornell@thoughtworks.com> | 2014-10-15 09:42:08 +0200 |
commit | 89d26f3cd389f41b83d27ea225944a0ff8bc2e95 (patch) | |
tree | 31275a0e7c350fd2b9acc2d1210d972bb9a0d3c8 /service/pixelated/adapter | |
parent | 6d08b8e65d2c1679d4b489ac196116847f91b3a7 (diff) |
Getting rid of singletons and optimizing imports
Diffstat (limited to 'service/pixelated/adapter')
-rw-r--r-- | service/pixelated/adapter/listener.py | 9 | ||||
-rw-r--r-- | service/pixelated/adapter/mail_service.py | 6 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mail_sender.py | 1 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailbox.py | 6 | ||||
-rw-r--r-- | service/pixelated/adapter/pixelated_mailboxes.py | 19 | ||||
-rw-r--r-- | service/pixelated/adapter/soledad_querier.py | 18 | ||||
-rw-r--r-- | service/pixelated/adapter/tag_index.py | 1 | ||||
-rw-r--r-- | service/pixelated/adapter/tag_service.py | 7 |
8 files changed, 18 insertions, 49 deletions
diff --git a/service/pixelated/adapter/listener.py b/service/pixelated/adapter/listener.py index 1ed546fd..67d75df7 100644 --- a/service/pixelated/adapter/listener.py +++ b/service/pixelated/adapter/listener.py @@ -13,7 +13,6 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.soledad_querier import SoledadQuerier class MailboxListener(object): @@ -22,14 +21,14 @@ class MailboxListener(object): SEARCH_ENGINE = None @classmethod - def listen(cls, account, mailbox_name): - listener = MailboxListener(mailbox_name) + def listen(cls, account, mailbox_name, soledad_querier): + listener = MailboxListener(mailbox_name, soledad_querier) if listener not in account.getMailbox(mailbox_name).listeners: account.getMailbox(mailbox_name).addListener(listener) - def __init__(self, mailbox_name): + def __init__(self, mailbox_name, soledad_querier): self.mailbox_name = mailbox_name - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier def newMessages(self, exists, recent): indexed_idents = set(self.SEARCH_ENGINE.search('tag:' + self.mailbox_name.lower())) diff --git a/service/pixelated/adapter/mail_service.py b/service/pixelated/adapter/mail_service.py index 9e29b0c3..e908feb7 100644 --- a/service/pixelated/adapter/mail_service.py +++ b/service/pixelated/adapter/mail_service.py @@ -13,17 +13,15 @@ # # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.tag_service import TagService -from pixelated.adapter.soledad_querier import SoledadQuerier class MailService: __slots__ = ['leap_session', 'account', 'mailbox_name'] - def __init__(self, mailboxes, mail_sender, tag_service=TagService.get_instance()): + def __init__(self, mailboxes, mail_sender, tag_service, soledad_querier): self.tag_service = tag_service self.mailboxes = mailboxes - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier self.mail_sender = mail_sender def all_mails(self): diff --git a/service/pixelated/adapter/pixelated_mail_sender.py b/service/pixelated/adapter/pixelated_mail_sender.py index 4189517d..cf30779f 100644 --- a/service/pixelated/adapter/pixelated_mail_sender.py +++ b/service/pixelated/adapter/pixelated_mail_sender.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. import smtplib + from pixelated.support.functional import flatten diff --git a/service/pixelated/adapter/pixelated_mailbox.py b/service/pixelated/adapter/pixelated_mailbox.py index 0ad79b11..283567db 100644 --- a/service/pixelated/adapter/pixelated_mailbox.py +++ b/service/pixelated/adapter/pixelated_mailbox.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. -from pixelated.adapter.soledad_querier import SoledadQuerier - class PixelatedMailbox: @@ -51,5 +49,5 @@ class PixelatedMailbox: self.querier.remove_mail(mail) @classmethod - def create(cls, mailbox_name='INBOX'): - return PixelatedMailbox(mailbox_name, SoledadQuerier.get_instance()) + def create(cls, mailbox_name, soledad_querier): + return PixelatedMailbox(mailbox_name, soledad_querier) diff --git a/service/pixelated/adapter/pixelated_mailboxes.py b/service/pixelated/adapter/pixelated_mailboxes.py index 1025f58e..79c007cb 100644 --- a/service/pixelated/adapter/pixelated_mailboxes.py +++ b/service/pixelated/adapter/pixelated_mailboxes.py @@ -14,24 +14,23 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from pixelated.adapter.pixelated_mailbox import PixelatedMailbox -from pixelated.adapter.soledad_querier import SoledadQuerier from pixelated.adapter.listener import MailboxListener class PixelatedMailBoxes(): - def __init__(self, account): + def __init__(self, account, soledad_querier): self.account = account - self.querier = SoledadQuerier.get_instance() + self.querier = soledad_querier for mailbox_name in account.mailboxes: - MailboxListener.listen(self.account, mailbox_name) + MailboxListener.listen(self.account, mailbox_name, soledad_querier) def _create_or_get(self, mailbox_name): mailbox_name = mailbox_name.upper() if mailbox_name not in self.account.mailboxes: self.account.addMailbox(mailbox_name) - MailboxListener.listen(self.account, mailbox_name) - return PixelatedMailbox.create(mailbox_name) + MailboxListener.listen(self.account, mailbox_name, self.querier) + return PixelatedMailbox.create(mailbox_name, self.querier) def inbox(self): return self._create_or_get('INBOX') @@ -45,14 +44,12 @@ class PixelatedMailBoxes(): def sent(self): return self._create_or_get('SENT') - @property def mailboxes(self): - return [PixelatedMailbox.create(leap_mailbox_name) for leap_mailbox_name in - self.account.mailboxes] + return [self._create_or_get(leap_mailbox_name) for leap_mailbox_name in self.account.mailboxes] def mails_by_tag(self, query_tags): mails = [] - for mailbox in self.mailboxes: + for mailbox in self.mailboxes(): mails.extend(mailbox.mails_by_tags(query_tags)) return mails @@ -65,7 +62,7 @@ class PixelatedMailBoxes(): return mail def mail(self, mail_id): - for mailbox in self.mailboxes: + for mailbox in self.mailboxes(): mail = mailbox.mail(mail_id) if mail: return mail diff --git a/service/pixelated/adapter/soledad_querier.py b/service/pixelated/adapter/soledad_querier.py index 35c8780f..f121a463 100644 --- a/service/pixelated/adapter/soledad_querier.py +++ b/service/pixelated/adapter/soledad_querier.py @@ -16,29 +16,11 @@ from pixelated.adapter.pixelated_mail import PixelatedMail -def get_soledad_querier_instance(cls, soledad=None): - if not cls.instance: - if not soledad: - raise Exception("Need a soledad for the first time you call this") - cls.instance = SoledadQuerier(soledad) - return cls.instance - - class SoledadQuerier: - instance = None - def __init__(self, soledad): self.soledad = soledad - @classmethod - def get_instance(cls, soledad=None): - return get_soledad_querier_instance(cls, soledad) - - @classmethod - def reset(cls): - cls.instance = None - def all_mails(self): fdocs_chash = [(fdoc, fdoc.content['chash']) for fdoc in self.soledad.get_from_index('by-type', 'flags')] if len(fdocs_chash) == 0: diff --git a/service/pixelated/adapter/tag_index.py b/service/pixelated/adapter/tag_index.py index 2a0955ef..5b9bda51 100644 --- a/service/pixelated/adapter/tag_index.py +++ b/service/pixelated/adapter/tag_index.py @@ -16,6 +16,7 @@ # import dbm import atexit + import os from pixelated.adapter.tag import Tag diff --git a/service/pixelated/adapter/tag_service.py b/service/pixelated/adapter/tag_service.py index fa70231e..54b88622 100644 --- a/service/pixelated/adapter/tag_service.py +++ b/service/pixelated/adapter/tag_service.py @@ -14,7 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with Pixelated. If not, see <http://www.gnu.org/licenses/>. from pixelated.adapter.tag import Tag -from pixelated.adapter.tag_index import TagIndex class TagService: @@ -25,9 +24,3 @@ class TagService: @classmethod def extract_reserved(cls, tags): return {tag.name for tag in cls.SPECIAL_TAGS if tag.name in tags} - - @classmethod - def get_instance(cls): - if not cls.instance: - cls.instance = TagService() - return cls.instance |