# Path: swfconduit/session.py
# class Session(object):
#     protocol    = None
#     server      = None
#     session_id  = ""
# 
#     def __init__( self, server, protocol ):
#         """ Initialize a new session """
#         self.server     = server
#         self.protocol   = protocol
#         self.session_id = uuid4()
# 
#     def close( self ):
#         """ Close the session """
#         self.server.closeSession( self )
# 
#     def fireEvent( self, event ):
#         """ Fire off the event to the local server """
#         reply = self.server.fireEvent( event, self )
#         if ( reply is not None ):
#             self.sendEvent( reply )
# 
#     def open( self ):
#         """ Open the session """
#         pass
# 
#     def sendEvent( self, event ):
#         """ Send an event to the remote client """
#         self.protocol.sendEvent( event )
# 
# Path: swfconduit/event.py
# class ErrorEvent( Event ):
#     e = None
#     traceback = ""
# 
#     def __init__( self, e ):
#         self.e = e
#         self.traceback = traceback.format_exc()
# 
#     def fire( self, server, session ):
#         # Can't raise here, we already ARE an error
#         print "Whachotalkingboutwillis?" + self.__repr__()


from swfconduit.session import Session
from swfconduit.event import ErrorEvent
from twisted.internet import reactor
import twisted.internet.protocol
import swfconduit.protocol
import swfconduit.event
import pyamf
import traceback, sys
    callLater   = reactor.callLater

    def __init__( self, cfg=None ):
        """ Init a new Server with the given configuration """
        self.config = cfg

    def openSession( self, protocol ):
        """ Open a user session """
        session = self.session( self, protocol )
        self.sessions[ session.session_id ] = session
        session.open()
        return session

    def closeSession( self, session ):
        """ A session is closing, clean up after it """
        if ( session.session_id in self.sessions ):
            del( self.sessions[ session.session_id ] )
        if ( session.protocol.transport is not None ):
            # Could be none in the case of tests
            session.protocol.transport.loseConnection()
        pass

    def fireEvent( self, event, session ):
        """ Fire the event """
        try:
            #print event
            return event.fire( self, session )
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            # Send back an error message to the client

# Path: swfconduit/session.py
# class Session(object):
#     protocol    = None
#     server      = None
#     session_id  = ""
# 
#     def __init__( self, server, protocol ):
#         """ Initialize a new session """
#         self.server     = server
#         self.protocol   = protocol
#         self.session_id = uuid4()
# 
#     def close( self ):
#         """ Close the session """
#         self.server.closeSession( self )
# 
#     def fireEvent( self, event ):
#         """ Fire off the event to the local server """
#         reply = self.server.fireEvent( event, self )
#         if ( reply is not None ):
#             self.sendEvent( reply )
# 
#     def open( self ):
#         """ Open the session """
#         pass
# 
#     def sendEvent( self, event ):
#         """ Send an event to the remote client """
#         self.protocol.sendEvent( event )
# 
# Path: swfconduit/event.py
# class ErrorEvent( Event ):
#     e = None
#     traceback = ""
# 
#     def __init__( self, e ):
#         self.e = e
#         self.traceback = traceback.format_exc()
# 
#     def fire( self, server, session ):
#         # Can't raise here, we already ARE an error
#         print "Whachotalkingboutwillis?" + self.__repr__()


# Path: swfconduit/server.py
from swfconduit.session import Session
from swfconduit.event import ErrorEvent
from twisted.internet import reactor
import twisted.internet.protocol
import swfconduit.protocol
import swfconduit.event
import pyamf
import traceback, sys

    callLater   = reactor.callLater

    def __init__( self, cfg=None ):
        """ Init a new Server with the given configuration """
        self.config = cfg

    def openSession( self, protocol ):
        """ Open a user session """
        session = self.session( self, protocol )
        self.sessions[ session.session_id ] = session
        session.open()
        return session

    def closeSession( self, session ):
        """ A session is closing, clean up after it """
        if ( session.session_id in self.sessions ):
            del( self.sessions[ session.session_id ] )
        if ( session.protocol.transport is not None ):
            # Could be none in the case of tests
            session.protocol.transport.loseConnection()
        pass

    def fireEvent( self, event, session ):
        """ Fire the event """
        try:
            #print event
            return event.fire( self, session )
        except Exception as e:
            traceback.print_exc(file=sys.stdout)
            # Send back an error message to the client

            reply = event.reply( ErrorEvent, e )