# Path: xmpp/xml.py
# E = builder.E
# CLARK_NAME = re.compile(r'^{[^}]+}.+$')
# PREFIX_NAME = re.compile(r'^([^:]+):(.+)')
#     PARSE = re.compile('([^@/]+)(?:@([^/]+))?(?:/(.+))?$')
# class Parser(object):
# class jid(object):
#     def __init__(self, target, **kwargs):
#     def start(self):
#     def reset(self):
#     def stop_tokenizing(self):
#     def feed_tokens(self, data):
#     def tokenize(self):
#     def close(self):
# def is_element(obj):
# def tag(elem, default=None):
# def text(elem, default=None):
# def child(elem, nth=0, default=None):
# def clark(obj, ns=None, nsmap=None):
# def clark_path(expr, ns=None, nsmap=None):
#     def __new__(cls, obj, host=None, resource=None):
#     def __init__(self, obj, host=None, resource=None):
#     def __repr__(self):
#     def __unicode__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def bare(self):
#     def full(self):
#     def match_bare(self, other):
#     def _parse(cls, name, host=None, resource=None):
#     def _make_unicode(self):
# def bare(obj):
# def is_full_jid(obj):
# def is_bare_jid(obj):
# def open_tag(elem, encoding='utf-8'):
# def close_tag(elem, encoding='utf-8'):
# def stanza_tostring(root, stanza, encoding='utf-8'):
# 
# Path: xmpp/features.py
# class NoRoute(Exception):
#     """Routes are used to deliver messages.  This exception is raised
#     when no routes can be found for a particular jid."""
# 
# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


import copy
import signal
import time
import traceback
import os
import modes
import roster
import UserManager
import Msg
import Config
import Utmp
import UCache
import Login
import UserInfo
import Util
from lxml import builder
from threading import Thread, Condition
from xmpp import xml
from xmpp.features import NoRoute
from pympler import muppy, summary
from Log import Log
        method = getattr(self, 'recv_%s' % elem.get('type'), None)
        return method and method(conn, elem)

    def recv_subscribe(self, conn, pres):
        return conn.write(pres)

    def recv_subscribed(self, conn, pres):
        roster = self.get(conn)
        contact = xml.jid(pres.get('from')).bare
        self.confirm(conn, roster, roster.subscribe(contact, 'to'))
        pres.set('from', contact)
        pres.set('to', conn.authJID.bare)
        return conn.write(pres)

    def recv_probe(self, conn, pres):
        return self._last(self._get(conn), pres.get('from'), conn)

    def confirm(self, conn, roster, item):
        conn.push(roster, conn.E.query({ 'xmlns': 'jabber:iq:roster' }, item))

    def routes(self, jid):
        return self._resources.routes(xml.jid(jid))

    def transmit(self, to, elem):
        for (fulljid, route) in self.routes(to):
            Log.debug("sending to %s" % fulljid)
            try:
                route.handle(elem)
            except Exception as e:
                Log.error("send error: %r" % e)

# Path: xmpp/xml.py
# E = builder.E
# CLARK_NAME = re.compile(r'^{[^}]+}.+$')
# PREFIX_NAME = re.compile(r'^([^:]+):(.+)')
#     PARSE = re.compile('([^@/]+)(?:@([^/]+))?(?:/(.+))?$')
# class Parser(object):
# class jid(object):
#     def __init__(self, target, **kwargs):
#     def start(self):
#     def reset(self):
#     def stop_tokenizing(self):
#     def feed_tokens(self, data):
#     def tokenize(self):
#     def close(self):
# def is_element(obj):
# def tag(elem, default=None):
# def text(elem, default=None):
# def child(elem, nth=0, default=None):
# def clark(obj, ns=None, nsmap=None):
# def clark_path(expr, ns=None, nsmap=None):
#     def __new__(cls, obj, host=None, resource=None):
#     def __init__(self, obj, host=None, resource=None):
#     def __repr__(self):
#     def __unicode__(self):
#     def __hash__(self):
#     def __eq__(self, other):
#     def __ne__(self, other):
#     def bare(self):
#     def full(self):
#     def match_bare(self, other):
#     def _parse(cls, name, host=None, resource=None):
#     def _make_unicode(self):
# def bare(obj):
# def is_full_jid(obj):
# def is_bare_jid(obj):
# def open_tag(elem, encoding='utf-8'):
# def close_tag(elem, encoding='utf-8'):
# def stanza_tostring(root, stanza, encoding='utf-8'):
# 
# Path: xmpp/features.py
# class NoRoute(Exception):
#     """Routes are used to deliver messages.  This exception is raised
#     when no routes can be found for a particular jid."""
# 
# Path: Log.py
# class Log:
#     HEADER = '\033[95m'
#     OKBLUE = '\033[94m'
#     OKGREEN = '\033[92m'
#     WARNING = '\033[93m'
#     FAIL = '\033[91m'
#     ENDC = '\033[0m'
#     DEBUG = '\033[90m'
# 
#     _debug = True
#     _info = True
#     _warning = True
#     _error = True
# 
#     @staticmethod
#     def debug(msg):
#         if (Log._debug):
#             print Log.DEBUG, "%s [DEBUG]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
#     
#     @staticmethod
#     def error(msg):
#         if (Log._error):
#             print Log.FAIL, "%s [ERROR]" % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             exc_info = sys.exc_info()
#             if exc_info[0] is not None:
#                 # handling exception
#                 traceback.print_exc()
#             sys.stdout.flush()
# 
#     @staticmethod
#     def warn(msg):
#         if (Log._warning):
#             print Log.WARNING, "%s [WARN] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()
# 
#     @staticmethod
#     def info(msg):
#         if (Log._info):
#             print Log.OKGREEN, "%s [INFO] " % time.ctime(), msg.encode('utf-8'), Log.ENDC
#             sys.stdout.flush()


# Path: rosters.py
import copy
import signal
import time
import traceback
import os
import modes
import roster
import UserManager
import Msg
import Config
import Utmp
import UCache
import Login
import UserInfo
import Util
from lxml import builder
from threading import Thread, Condition
from xmpp import xml
from xmpp.features import NoRoute
from pympler import muppy, summary
from Log import Log

        method = getattr(self, 'recv_%s' % elem.get('type'), None)
        return method and method(conn, elem)

    def recv_subscribe(self, conn, pres):
        return conn.write(pres)

    def recv_subscribed(self, conn, pres):
        roster = self.get(conn)
        contact = xml.jid(pres.get('from')).bare
        self.confirm(conn, roster, roster.subscribe(contact, 'to'))
        pres.set('from', contact)
        pres.set('to', conn.authJID.bare)
        return conn.write(pres)

    def recv_probe(self, conn, pres):
        return self._last(self._get(conn), pres.get('from'), conn)

    def confirm(self, conn, roster, item):
        conn.push(roster, conn.E.query({ 'xmlns': 'jabber:iq:roster' }, item))

    def routes(self, jid):
        return self._resources.routes(xml.jid(jid))

    def transmit(self, to, elem):
        for (fulljid, route) in self.routes(to):
            Log.debug("sending to %s" % fulljid)
            try:
                route.handle(elem)
            except Exception as e:
                Log.error("send error: %r" % e)

                Log.error(traceback.format_exc())