404

[ Avaa Bypassed ]




Upload:

Command:

botdev@3.16.28.251: ~ $
# -*- test-case-name: twisted.test.test_stateful -*-

# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.


from twisted.internet import protocol

from io import BytesIO

class StatefulProtocol(protocol.Protocol):
    """A Protocol that stores state for you.

    state is a pair (function, num_bytes). When num_bytes bytes of data arrives
    from the network, function is called. It is expected to return the next
    state or None to keep same state. Initial state is returned by
    getInitialState (override it).
    """
    _sful_data = None, None, 0

    def makeConnection(self, transport):
        protocol.Protocol.makeConnection(self, transport)
        self._sful_data = self.getInitialState(), BytesIO(), 0

    def getInitialState(self):
        raise NotImplementedError

    def dataReceived(self, data):
        state, buffer, offset = self._sful_data
        buffer.seek(0, 2)
        buffer.write(data)
        blen = buffer.tell() # how many bytes total is in the buffer
        buffer.seek(offset)
        while blen - offset >= state[1]:
            d = buffer.read(state[1])
            offset += state[1]
            next = state[0](d)
            if self.transport.disconnecting: # XXX: argh stupid hack borrowed right from LineReceiver
                return # dataReceived won't be called again, so who cares about consistent state
            if next:
                state = next
        if offset != 0:
            b = buffer.read()
            buffer.seek(0)
            buffer.truncate()
            buffer.write(b)
            offset = 0
        self._sful_data = state, buffer, offset


Filemanager

Name Type Size Permission Actions
__pycache__ Folder 0755
haproxy Folder 0755
test Folder 0755
__init__.py File 572 B 0644
amp.py File 95.83 KB 0644
basic.py File 31.26 KB 0644
dict.py File 10.52 KB 0644
finger.py File 1.19 KB 0644
ftp.py File 103.64 KB 0644
htb.py File 9.11 KB 0644
ident.py File 7.6 KB 0644
loopback.py File 11.65 KB 0644
memcache.py File 23.14 KB 0644
pcp.py File 6.92 KB 0644
policies.py File 20.72 KB 0644
portforward.py File 2.33 KB 0644
postfix.py File 3.65 KB 0644
sip.py File 36.91 KB 0644
socks.py File 7.63 KB 0644
stateful.py File 1.6 KB 0644
tls.py File 31.73 KB 0644
wire.py File 2.5 KB 0644