# Path: will/abstractions.py
# class Event(Bunch):
#     will_internal_type = "Event"
# 
#     REQUIRED_FIELDS = [
#         "type",
#         "version",
#     ]
# 
#     def __init__(self, *args, **kwargs):
#         super(Event, self).__init__(*args, **kwargs)
#         self.version = 1
# 
#         for f in self.REQUIRED_FIELDS:
#             if not f in kwargs and not hasattr(self, f):
#                 raise Exception("Missing %s in Event construction." % f)
# 
#         if "timestamp" in kwargs:
#             self.timestamp = kwargs["timestamp"]
#         else:
#             self.timestamp = datetime.datetime.now()
# 
#         h = hashlib.md5()
#         h.update(self.timestamp.strftime("%s").encode("utf-8"))
#         h.update(self.type.encode("utf-8"))
#         self.hash = h.hexdigest()
#         if not "original_incoming_event_hash" in kwargs:
#             if hasattr(self, "original_incoming_event") and hasattr(self.original_incoming_event, "hash"):
#                 self.original_incoming_event_hash = self.original_incoming_event.hash
#             else:
#                 self.original_incoming_event_hash = self.hash
# 
# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []


import logging
import os
import redis
import traceback
from six.moves.urllib.parse import urlparse
from will.abstractions import Event
from will import settings
from will.mixins import SettingsMixin, EncryptionMixin
        if reference_message:
            original_incoming_event_hash = None
            if hasattr(reference_message, "original_incoming_event_hash"):
                original_incoming_event_hash = reference_message.original_incoming_event_hash
            elif hasattr(reference_message, "source") and hasattr(reference_message.source, "hash"):
                original_incoming_event_hash = reference_message.source.hash
            elif hasattr(reference_message, "source") and hasattr(reference_message.source, "original_incoming_event_hash"):
                original_incoming_event_hash = reference_message.source.original_incoming_event_hash
            elif hasattr(reference_message, "hash"):
                original_incoming_event_hash = reference_message.hash
            if original_incoming_event_hash:
                e.original_incoming_event_hash = original_incoming_event_hash

        return self.publish_to_backend(
            self._localize_topic(topic),
            self.encrypt(e)
        )

    def unsubscribe(self, topic):
        # This is mostly here for semantic consistency.
        self.do_unsubscribe(topic)

    def _localize_topic(self, topic):
        cleaned_topic = topic
        if type(topic) == type([]):
            cleaned_topic = []
            for t in topic:
                if not t.startswith(settings.SECRET_KEY):
                    cleaned_topic.append("%s.%s" % (settings.SECRET_KEY, t))


# Path: will/abstractions.py
# class Event(Bunch):
#     will_internal_type = "Event"
# 
#     REQUIRED_FIELDS = [
#         "type",
#         "version",
#     ]
# 
#     def __init__(self, *args, **kwargs):
#         super(Event, self).__init__(*args, **kwargs)
#         self.version = 1
# 
#         for f in self.REQUIRED_FIELDS:
#             if not f in kwargs and not hasattr(self, f):
#                 raise Exception("Missing %s in Event construction." % f)
# 
#         if "timestamp" in kwargs:
#             self.timestamp = kwargs["timestamp"]
#         else:
#             self.timestamp = datetime.datetime.now()
# 
#         h = hashlib.md5()
#         h.update(self.timestamp.strftime("%s").encode("utf-8"))
#         h.update(self.type.encode("utf-8"))
#         self.hash = h.hexdigest()
#         if not "original_incoming_event_hash" in kwargs:
#             if hasattr(self, "original_incoming_event") and hasattr(self.original_incoming_event, "hash"):
#                 self.original_incoming_event_hash = self.original_incoming_event.hash
#             else:
#                 self.original_incoming_event_hash = self.hash
# 
# Path: will/settings.py
# def auto_key():
# def import_settings(quiet=True):
#         DEPRECATED_BUT_MAPPED_SETTINGS = {
#             "USERNAME": "HIPCHAT_USERNAME",
#             "PASSWORD": "HIPCHAT_PASSWORD",
#             "V1_TOKEN": "HIPCHAT_V1_TOKEN",
#             "V2_TOKEN": "HIPCHAT_V2_TOKEN",
#             "TOKEN": "HIPCHAT_V1_TOKEN",
#             "ROOMS": "HIPCHAT_ROOMS",
#             "NAME": "HIPCHAT_NAME",
#             "HANDLE": "HIPCHAT_HANDLE",
#             "DEFAULT_ROOM": "HIPCHAT_DEFAULT_ROOM",
#             "SLACK_DEFAULT_ROOM": "SLACK_DEFAULT_CHANNEL",
#         }
#             IO_BACKENDS = []


# Path: will/backends/pubsub/base.py
import logging
import os
import redis
import traceback
from six.moves.urllib.parse import urlparse
from will.abstractions import Event
from will import settings
from will.mixins import SettingsMixin, EncryptionMixin

        if reference_message:
            original_incoming_event_hash = None
            if hasattr(reference_message, "original_incoming_event_hash"):
                original_incoming_event_hash = reference_message.original_incoming_event_hash
            elif hasattr(reference_message, "source") and hasattr(reference_message.source, "hash"):
                original_incoming_event_hash = reference_message.source.hash
            elif hasattr(reference_message, "source") and hasattr(reference_message.source, "original_incoming_event_hash"):
                original_incoming_event_hash = reference_message.source.original_incoming_event_hash
            elif hasattr(reference_message, "hash"):
                original_incoming_event_hash = reference_message.hash
            if original_incoming_event_hash:
                e.original_incoming_event_hash = original_incoming_event_hash

        return self.publish_to_backend(
            self._localize_topic(topic),
            self.encrypt(e)
        )

    def unsubscribe(self, topic):
        # This is mostly here for semantic consistency.
        self.do_unsubscribe(topic)

    def _localize_topic(self, topic):
        cleaned_topic = topic
        if type(topic) == type([]):
            cleaned_topic = []
            for t in topic:
                if not t.startswith(settings.SECRET_KEY):
                    cleaned_topic.append("%s.%s" % (settings.SECRET_KEY, t))


        elif not topic.startswith(settings.SECRET_KEY):