Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(149)

Side by Side Diff: third_party/twisted_8_1/twisted/protocols/portforward.py

Issue 12261012: Remove third_party/twisted_8_1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/build
Patch Set: Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1
2 # Copyright (c) 2001-2004 Twisted Matrix Laboratories.
3 # See LICENSE for details.
4
5 """
6 A simple port forwarder.
7 """
8
9 # Twisted imports
10 from twisted.internet import protocol
11 from twisted.python import log
12
13 class Proxy(protocol.Protocol):
14 noisy = True
15
16 peer = None
17
18 def setPeer(self, peer):
19 self.peer = peer
20
21 def connectionLost(self, reason):
22 if self.peer is not None:
23 self.peer.transport.loseConnection()
24 self.peer = None
25 elif self.noisy:
26 log.msg("Unable to connect to peer: %s" % (reason,))
27
28 def dataReceived(self, data):
29 self.peer.transport.write(data)
30
31 class ProxyClient(Proxy):
32 def connectionMade(self):
33 self.peer.setPeer(self)
34 # We're connected, everybody can read to their hearts content.
35 self.peer.transport.resumeProducing()
36
37 class ProxyClientFactory(protocol.ClientFactory):
38
39 protocol = ProxyClient
40
41 def setServer(self, server):
42 self.server = server
43
44 def buildProtocol(self, *args, **kw):
45 prot = protocol.ClientFactory.buildProtocol(self, *args, **kw)
46 prot.setPeer(self.server)
47 return prot
48
49 def clientConnectionFailed(self, connector, reason):
50 self.server.transport.loseConnection()
51
52
53 class ProxyServer(Proxy):
54
55 clientProtocolFactory = ProxyClientFactory
56
57 def connectionMade(self):
58 # Don't read anything from the connecting client until we have
59 # somewhere to send it to.
60 self.transport.pauseProducing()
61
62 client = self.clientProtocolFactory()
63 client.setServer(self)
64
65 from twisted.internet import reactor
66 reactor.connectTCP(self.factory.host, self.factory.port, client)
67
68
69 class ProxyFactory(protocol.Factory):
70 """Factory for port forwarder."""
71
72 protocol = ProxyServer
73
74 def __init__(self, host, port):
75 self.host = host
76 self.port = port
OLDNEW
« no previous file with comments | « third_party/twisted_8_1/twisted/protocols/pop3.py ('k') | third_party/twisted_8_1/twisted/protocols/postfix.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698