# Path: zengine/lib/json_interface.py
# class ZEngineJSONEncoder(json.JSONEncoder):
#     def default(self, o):
#         # If the object is a deferred translation, do the translation now
#         if isinstance(o, LazyProxy):
#             return str(o)
#         # Otherwise, let the default encoder handle the serialization
#         return json.JSONEncoder.default(self, o)
# 
# Path: zengine/log.py



import json
import pika
import time
from pyoko.conf import settings
from pika.exceptions import ConnectionClosed, ChannelClosed
from zengine.lib.json_interface import ZEngineJSONEncoder
from zengine.log import log
                self.connection = pika.BlockingConnection(BLOCKING_MQ_PARAMS)
                self.channel = pika.BlockingConnection(BLOCKING_MQ_PARAMS)
        return self.channel

    def send_to_default_exchange(self, sess_id, message=None):
        """
        Send messages through RabbitMQ's default exchange,
        which will be delivered through routing_key (sess_id).

        This method only used for un-authenticated users, i.e. login process.

        Args:
            sess_id string: Session id
            message dict: Message object.
        """
        msg = json.dumps(message, cls=ZEngineJSONEncoder)
        log.debug("Sending following message to %s queue through default exchange:\n%s" % (
            sess_id, msg))
        self.get_channel().publish(exchange='', routing_key=sess_id, body=msg)

    def send_to_prv_exchange(self, user_id, message=None):
        """
        Send messages through logged in users private exchange.

        Args:
            user_id string: User key
            message dict: Message object

        """
        exchange = 'prv_%s' % user_id.lower()

# Path: zengine/lib/json_interface.py
# class ZEngineJSONEncoder(json.JSONEncoder):
#     def default(self, o):
#         # If the object is a deferred translation, do the translation now
#         if isinstance(o, LazyProxy):
#             return str(o)
#         # Otherwise, let the default encoder handle the serialization
#         return json.JSONEncoder.default(self, o)
# 
# Path: zengine/log.py



# Path: zengine/client_queue.py
import json
import pika
import time
from pyoko.conf import settings
from pika.exceptions import ConnectionClosed, ChannelClosed
from zengine.lib.json_interface import ZEngineJSONEncoder
from zengine.log import log

                self.connection = pika.BlockingConnection(BLOCKING_MQ_PARAMS)
                self.channel = pika.BlockingConnection(BLOCKING_MQ_PARAMS)
        return self.channel

    def send_to_default_exchange(self, sess_id, message=None):
        """
        Send messages through RabbitMQ's default exchange,
        which will be delivered through routing_key (sess_id).

        This method only used for un-authenticated users, i.e. login process.

        Args:
            sess_id string: Session id
            message dict: Message object.
        """
        msg = json.dumps(message, cls=ZEngineJSONEncoder)
        log.debug("Sending following message to %s queue through default exchange:\n%s" % (
            sess_id, msg))
        self.get_channel().publish(exchange='', routing_key=sess_id, body=msg)

    def send_to_prv_exchange(self, user_id, message=None):
        """
        Send messages through logged in users private exchange.

        Args:
            user_id string: User key
            message dict: Message object

        """
        exchange = 'prv_%s' % user_id.lower()

        msg = json.dumps(message, cls=ZEngineJSONEncoder)