'Write data by portions'

def upstream_recv(self, data):

    packets = data.read()
    packets = (struct.pack('>I', len(packets)) + packets)
    for part in [packets[i:(i + self.mtu)] for i in xrange(0, len(packets), self.mtu)]:
        self.downstream.write(part)
