Exemplo n.º 1
0
    def testPipeProxy(self):

        class OhToZero(Pipe):
            def to_client(self, data):
                data = data.replace('o', '0')
                data = data.replace('O', '0')
                return data

        # Start proxy with pipe
        proxy = PlumbingServer('google.com', '80', 'localhost', '8080')
        proxy.add_pipe(OhToZero())
        proxy_thread = threading.Thread(target=proxy.serve_forever)
        proxy_thread.daemon = True
        proxy_thread.start()

        try:
            # Connect to the proxy
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect(('localhost', 8080))
            sock.sendall('GET /index.html\r\n')
            data = sock.recv(1024)
            sock.close()
        finally:
            # Stop proxy
            proxy.shutdown()

        self.assertTrue(data.find('g00gle') != -1)
Exemplo n.º 2
0
 def __init__(self, *args, **kwargs):
     PlumbingServer.__init__(self, *args, **kwargs)
     self.pipes.append(RateLimitPipe())
     self.pipes.append(AudioPipe("horn", open("airhorn.mp3")))
     self.pipes.append(AudioPipe("trumpet", open("trumpet.mp3")))
Exemplo n.º 3
0
 def __init__(self, *args, **kwargs):
     PlumbingServer.__init__(self, *args, **kwargs)
     self.pipes.append(RateLimitPipe())
     self.pipes.append(AudioPipe('horn', open('airhorn.mp3')))
     self.pipes.append(AudioPipe('trumpet', open('trumpet.mp3')))
Exemplo n.º 4
0
 def __init__(self, *args, **kwargs):
     PlumbingServer.__init__(self, *args, **kwargs)
     self.pipes.append(AudioPipe('horn', open('airhorn.mp3')))
     self.pipes.append(AudioPipe('trumpet', open('trumpet.mp3')))