# Path: kittystore/events.py
# def subscribe(target, eventclass):
# def notify(event):
# def subscribe_to(eventclass):
#     def wrapper(f):
# def reset():
# 
# Path: kittystore/utils.py
# def get_mailman_client(settings):
#     try:
#         mm_client = mailmanclient.Client('%s/3.0' %
#                         settings.MAILMAN_REST_SERVER,
#                         settings.MAILMAN_API_USER,
#                         settings.MAILMAN_API_PASS)
#     except (HTTPError, mailmanclient.MailmanConnectionError), e:
#         raise HTTPError(e)
#     return mm_client


from urllib2 import HTTPError
from uuid import UUID
from kittystore import events
from kittystore.utils import get_mailman_client
import mailmanclient
import logging



logger = logging.getLogger(__name__)


_MAILMAN_CLIENT = None


def get_user_id(store, sender):
    global _MAILMAN_CLIENT
    if _MAILMAN_CLIENT is None:
        _MAILMAN_CLIENT = get_mailman_client(store.settings)
    try:
        mm_user = _MAILMAN_CLIENT.get_user(sender.email)
    except HTTPError, e:
        if e.code == 404:
            return None
        else:
            raise
    except ValueError:
        return None
    else:
        user_id = mm_user.user_id
        if user_id is None:
            return None
        else:
            return UUID(int=user_id)



# Path: kittystore/events.py
# def subscribe(target, eventclass):
# def notify(event):
# def subscribe_to(eventclass):
#     def wrapper(f):
# def reset():
# 
# Path: kittystore/utils.py
# def get_mailman_client(settings):
#     try:
#         mm_client = mailmanclient.Client('%s/3.0' %
#                         settings.MAILMAN_REST_SERVER,
#                         settings.MAILMAN_API_USER,
#                         settings.MAILMAN_API_PASS)
#     except (HTTPError, mailmanclient.MailmanConnectionError), e:
#         raise HTTPError(e)
#     return mm_client


# Path: kittystore/caching/mailman_user.py
from urllib2 import HTTPError
from uuid import UUID
from kittystore import events
from kittystore.utils import get_mailman_client
import mailmanclient
import logging




logger = logging.getLogger(__name__)


_MAILMAN_CLIENT = None


def get_user_id(store, sender):
    global _MAILMAN_CLIENT
    if _MAILMAN_CLIENT is None:
        _MAILMAN_CLIENT = get_mailman_client(store.settings)
    try:
        mm_user = _MAILMAN_CLIENT.get_user(sender.email)
    except HTTPError, e:
        if e.code == 404:
            return None
        else:
            raise
    except ValueError:
        return None
    else:
        user_id = mm_user.user_id
        if user_id is None:
            return None
        else:
            return UUID(int=user_id)



@events.subscribe_to(events.NewMessage)