<commit_before># -*- test-case-name: go.apps.sna.test_handlers -*-
from twisted.internet.defer import inlineCallbacks, returnValue

from go.vumitools.opt_out import OptOutStore
from go.vumitools.contact import ContactStore, ContactError
from go.vumitools.handler import EventHandler

from vumi import log

from vxpolls.manager import PollManager


class SNAEventHandler(EventHandler):

    @inlineCallbacks
    def find_contact(self, account_key, msisdn):
        try:
            contact_store = ContactStore(
                self.dispatcher.vumi_api.manager, account_key)
            contact = yield contact_store.contact_for_addr('ussd', msisdn)
            returnValue(contact)
        except ContactError:
            returnValue(None)


class USSDOptOutHandler(SNAEventHandler):

    def setup_handler(self):
        self.pm_prefix = self.config['poll_manager_prefix']
        self.vumi_api = self.dispatcher.vumi_api<commit_msg>SNAEventHandler.find_contact() does not need ContactStore to be guarded for ContactError, moved out of try-catch block<commit_after># -*- test-case-name: go.apps.sna.test_handlers -*-
from twisted.internet.defer import inlineCallbacks, returnValue

from go.vumitools.opt_out import OptOutStore
from go.vumitools.contact import ContactStore, ContactError
from go.vumitools.handler import EventHandler

from vumi import log

from vxpolls.manager import PollManager


class SNAEventHandler(EventHandler):

    @inlineCallbacks
    def find_contact(self, account_key, msisdn):
        contact_store = ContactStore(
            self.dispatcher.vumi_api.manager, account_key)
        try:
            contact = yield contact_store.contact_for_addr('ussd', msisdn)
            returnValue(contact)
        except ContactError:
            returnValue(None)


class USSDOptOutHandler(SNAEventHandler):

    def setup_handler(self):
        self.pm_prefix = self.config['poll_manager_prefix']
        self.vumi_api = self.dispatcher.vumi_api
{'fraction_non_alphanumeric': 0.07676664972038638, 'fraction_numerical': 0.0, 'mean_word_length': 3.67458432304038, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4590141', 'n_tokens_mistral': 579, 'n_tokens_neox': 575, 'n_words': 127}