# Path: karmabot/core/signal.py

# 
# Path: karmabot/core/subject.py
# class Subject(object):
#     def __init__(self, key, name):
#         self.key = key
#         self.name = name
#         self.data = {"name": name,
#                      "+facets": [],
#                      "-facets": []}
#         self.facets = {}
#         facet_registry.attach(self, set(self.data["-facets"]))
# 
#     def add_facet(self, facet):
#         if str(facet) in self.facets:
#             return
#         if isinstance(facet, str):
#             facet = facet_registry[facet](self)
#         self.facets[str(facet)] = facet
# 
#     def remove_facet(self, facet):
#         del self.facets[str(facet)]
# 
#     def iter_commands(self):
#         for facet in self.facets.itervalues():
#             for command_set in (facet.commands, facet.listens):
#                 if command_set:
#                     for cmd in command_set:
#                         yield cmd
# 
#     def describe(self, context):
#         final_txt = u""
#         sorted_facets = sorted(self.facets.itervalues(),
#                                key=lambda x: x.display_key)
#         for facet in sorted_facets:
#             final_txt += facet.present(context)
#         return final_txt


import cPickle
from redis import Redis
from .signal import post_connection
from .subject import Subject


db = None


@post_connection.connect
def load_catalog(sender):
    global db
    db = Catalog()


class Catalog(dict):
    def __init__(self, host='localhost', port=6379, db=0):
        self.redis = Redis(host=host, port=port, db=db)
        self.save = self.redis.save


# Path: karmabot/core/signal.py

# 
# Path: karmabot/core/subject.py
# class Subject(object):
#     def __init__(self, key, name):
#         self.key = key
#         self.name = name
#         self.data = {"name": name,
#                      "+facets": [],
#                      "-facets": []}
#         self.facets = {}
#         facet_registry.attach(self, set(self.data["-facets"]))
# 
#     def add_facet(self, facet):
#         if str(facet) in self.facets:
#             return
#         if isinstance(facet, str):
#             facet = facet_registry[facet](self)
#         self.facets[str(facet)] = facet
# 
#     def remove_facet(self, facet):
#         del self.facets[str(facet)]
# 
#     def iter_commands(self):
#         for facet in self.facets.itervalues():
#             for command_set in (facet.commands, facet.listens):
#                 if command_set:
#                     for cmd in command_set:
#                         yield cmd
# 
#     def describe(self, context):
#         final_txt = u""
#         sorted_facets = sorted(self.facets.itervalues(),
#                                key=lambda x: x.display_key)
#         for facet in sorted_facets:
#             final_txt += facet.present(context)
#         return final_txt


# Path: karmabot/core/storage.py
import cPickle
from redis import Redis
from .signal import post_connection
from .subject import Subject



db = None


@post_connection.connect
def load_catalog(sender):
    global db
    db = Catalog()


class Catalog(dict):
    def __init__(self, host='localhost', port=6379, db=0):
        self.redis = Redis(host=host, port=port, db=db)
        self.save = self.redis.save


    def __len__(self):