# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply


import pyamf
from twisted.internet.protocol import Protocol
from swfconduit.event import Event
    def connectionLost( self, reason ):
        """ Deinit a session """
        self.session.close()

    def dataReceived( self, data ):
        """ Read an event from the data """
        # Add the data to the input stream
        self.istream.append( data )
        self.istream.seek( self.ipos )

        # Read all the objects from the data
        while ( not self.istream.at_eof() ):
            # Read the element from the decoder
            try:
                # Always clear before a read
                self.decoder.context.clear()
                event = self.decoder.readElement()
                self.ipos = self.istream.tell()
            except IOError as error:
                #print "IOError: Need more. Only got %i" % ( self.istream.remaining() )
                return # Not enough, wait for another dataReceived
            except pyamf.EOStream:
                #print "EOStream: Need more. Only got %i" % ( self.istream.remaining() )
                #print "Previous byte: %s" % ( self.istream.peek(-1) )
                return # Not enough, wait for another dataReceived
            except pyamf.DecodeError:
                print "Invalid data: %s" % ( self.istream.getvalue() )
                self.istream.truncate()
                return


# Path: swfconduit/event.py
# class Event( object ):
#     id = 0
#     timestamp = None
# 
#     def __init__( self ):
#         self.id         = getrandbits(29) # Size of an AMF3 integer field
#         self.timestamp  = datetime.now()
#         pass
# 
#     def fire( self, server, session ):
#         """ Perform the event's task """
#         pass
# 
#     # Tried this for AS3 readObject problem. May need in future
#     #def __readamf__( self, input ):
#     #    self.timestamp = input.readObject()
#     #    self.payload   = input.readObject()
#     #
#     #def __writeamf__( self, output ):
#     #    output.writeObject( self.timestamp )
#     #    output.writeObject( self.payload )
# 
#     def reply( self, cls, *args ):
#         """ Create a reply with the given class. Will set the reply's id field appropriately """
#         reply = cls(*args)
#         reply.id = self.id
#         return reply


# Path: swfconduit/protocol.py
import pyamf
from twisted.internet.protocol import Protocol
from swfconduit.event import Event

    def connectionLost( self, reason ):
        """ Deinit a session """
        self.session.close()

    def dataReceived( self, data ):
        """ Read an event from the data """
        # Add the data to the input stream
        self.istream.append( data )
        self.istream.seek( self.ipos )

        # Read all the objects from the data
        while ( not self.istream.at_eof() ):
            # Read the element from the decoder
            try:
                # Always clear before a read
                self.decoder.context.clear()
                event = self.decoder.readElement()
                self.ipos = self.istream.tell()
            except IOError as error:
                #print "IOError: Need more. Only got %i" % ( self.istream.remaining() )
                return # Not enough, wait for another dataReceived
            except pyamf.EOStream:
                #print "EOStream: Need more. Only got %i" % ( self.istream.remaining() )
                #print "Previous byte: %s" % ( self.istream.peek(-1) )
                return # Not enough, wait for another dataReceived
            except pyamf.DecodeError:
                print "Invalid data: %s" % ( self.istream.getvalue() )
                self.istream.truncate()
                return


            if not isinstance( event, Event ):