r46858 - Apply proxy-protocol-8203-2.patch.

adiroiban-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: adiroiban
Date: Sat Feb 27 10:40:56 2016
New Revision: 46858

Added:
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/__init__.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_exc.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_info.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_interfaces.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_v1parser.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_v2parser.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/_wrapper.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/test/
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/test/__init__.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/test/test_v1parser.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/test/test_v2parser.py
   branches/haproxy-endpoint-8203/twisted/protocols/haproxy/test/test_wrapper.py
   branches/haproxy-endpoint-8203/twisted/topfiles/8203.feature
Modified:
   branches/haproxy-endpoint-8203/twisted/internet/endpoints.py
   branches/haproxy-endpoint-8203/twisted/plugins/twisted_core.py

Log:
Apply proxy-protocol-8203-2.patch.

Modified: branches/haproxy-endpoint-8203/twisted/internet/endpoints.py
==============================================================================
--- branches/haproxy-endpoint-8203/twisted/internet/endpoints.py	(original)
+++ branches/haproxy-endpoint-8203/twisted/internet/endpoints.py	Sat Feb 27 10:40:56 2016
@@ -34,6 +34,7 @@
 from twisted.internet.stdio import StandardIO, PipeAddress
 from twisted.internet.task import LoopingCall
 from twisted.plugin import IPlugin, getPlugins
+from twisted.protocols import haproxy
 from twisted.python import log
 from twisted.python.compat import nativeString, unicode, _matchingString
 from twisted.python.components import proxyForInterface
@@ -41,6 +42,7 @@
 from twisted.python.failure import Failure
 from twisted.python.filepath import FilePath
 from twisted.python.compat import iterbytes
+from twisted.python.compat import iteritems
 from twisted.python.systemd import ListenFDs
 
 
@@ -1283,6 +1285,41 @@
 
 
 
+@implementer(IPlugin, IStreamServerEndpointStringParser)
+class _HAProxyServerParser(object):
+    """
+    Stream server endpoint string parser for the HAProxyServerEndpoint type.
+
+    @ivar prefix: See L{IStreamServerEndpointStringParser.prefix}.
+    """
+    prefix = "haproxy"
+
+    def _parseServer(self, reactor, *args, **kwargs):
+        """
+        Internal parser function.
+
+        @param reactor: An L{IReactorTCP} provider.
+
+        @param wrapped: The name of the endpoint to wrap. Ex: tcp6.
+        @type wrapped: str
+        """
+        # Rebuild the description to re-dispatch the request.
+        description = ':'.join(str(arg) for arg in args)
+        description += ':'.join(
+            '%s=%s' % (str(key), quoteStringArgument(str(value)))
+            for key, value in iteritems(kwargs)
+        )
+        return _WrapperServerEndpoint(
+            serverFromString(reactor, description),
+            haproxy.HAProxyFactory,
+        )
+
+
+    def parseStreamServer(self, reactor, *args, **kwargs):
+        return self._parseServer(reactor, *args, **kwargs)
+
+
+
 _serverParsers = {"tcp": _parseTCP,
                   "unix": _parseUNIX,
                   "ssl": _parseSSL,
@@ -1906,6 +1943,30 @@
 
 
 
+@implementer(interfaces.IStreamServerEndpoint)
+class _WrapperServerEndpoint(object):
+    """
+    A server endpoint that wraps another server endpoint.
+    """
+
+    def __init__(self, wrappedEndpoint, wrapperFactory):
+        """
+        Construct a L{_WrapperServerEndpoint}.
+        """
+        self._wrappedEndpoint = wrappedEndpoint
+        self._wrapperFactory = wrapperFactory
+
+
+    def listen(self, protocolFactory):
+        """
+        Connect the given protocol factory and unwrap its result.
+        """
+        return self._wrappedEndpoint.listen(
+            self._wrapperFactory(protocolFactory)
+        )
+
+
+
 def wrapClientTLS(connectionCreator, wrappedEndpoint):
     """
     Wrap an endpoint which upgrades to TLS as soon as the connection is
@@ -2027,6 +2088,3 @@
         @rtype: L{IStreamClientEndpoint}
         """
         return _parseClientTLS(reactor, *args, **kwargs)
-
-
-

Modified: branches/haproxy-endpoint-8203/twisted/plugins/twisted_core.py
==============================================================================
--- branches/haproxy-endpoint-8203/twisted/plugins/twisted_core.py	(original)
+++ branches/haproxy-endpoint-8203/twisted/plugins/twisted_core.py	Sat Feb 27 10:40:56 2016
@@ -4,10 +4,10 @@
 
 from twisted.internet.endpoints import (
     _SystemdParser, _TCP6ServerParser, _StandardIOParser,
-    _TLSClientEndpointParser)
+    _TLSClientEndpointParser, _HAProxyServerParser)
 
 systemdEndpointParser = _SystemdParser()
 tcp6ServerEndpointParser = _TCP6ServerParser()
 stdioEndpointParser = _StandardIOParser()
 tlsClientEndpointParser = _TLSClientEndpointParser()
-
+haProxyServerEndpointParser = _HAProxyServerParser()
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.