r47165 - move _exc to _exceptions

glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org Tue, 5 Apr 2016 16:43:16 -0600 (MDT)
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: glyph
Date: Tue Apr  5 16:43:10 2016
New Revision: 47165

Added:
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exceptions.py
      - copied, changed from r47164, /branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exc.py
Removed:
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exc.py
Modified:
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v1parser.py
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v2parser.py
   branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v1parser.py

Log:
move _exc to _exceptions

(does Windows have a problem with this name?)

Copied: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exceptions.py (from r47164, /branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exc.py)
==============================================================================
--- /branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exc.py	(original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_exceptions.py	Tue Apr  5 16:43:10 2016
@@ -47,9 +47,6 @@
     @type targetType: L{Exception}
     """
     try:
-
         yield None
-
     except sourceType:
-
         compat.reraise(targetType(), sys.exc_info()[-1])

Modified: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v1parser.py
==============================================================================
--- branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v1parser.py	(original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v1parser.py	Tue Apr  5 16:43:10 2016
@@ -10,7 +10,10 @@
 from zope.interface import implementer
 from twisted.internet import address
 
-from . import _exc
+from ._exceptions import (
+    convertError, InvalidProxyHeader, InvalidNetworkProtocol,
+    MissingAddressData
+)
 from . import _info
 from . import _interfaces
 
@@ -58,7 +61,7 @@
         """
         self.buffer += data
         if len(self.buffer) > 107 and self.NEWLINE not in self.buffer:
-            raise _exc.InvalidProxyHeader()
+            raise InvalidProxyHeader()
         lines = (self.buffer).split(self.NEWLINE, 1)
         if not len(lines) > 1:
             return (None, None)
@@ -97,40 +100,32 @@
         destAddr = None
         destPort = None
 
-        with _exc.convertError(ValueError, _exc.InvalidProxyHeader):
-
+        with convertError(ValueError, InvalidProxyHeader):
             proxyStr, line = line.split(b' ', 1)
 
         if proxyStr != cls.PROXYSTR:
+            raise InvalidProxyHeader()
 
-            raise _exc.InvalidProxyHeader()
-
-        with _exc.convertError(ValueError, _exc.InvalidNetworkProtocol):
-
+        with convertError(ValueError, InvalidNetworkProtocol):
             networkProtocol, line = line.split(b' ', 1)
 
         if networkProtocol not in cls.ALLOWED_NET_PROTOS:
-
-            raise _exc.InvalidNetworkProtocol()
+            raise InvalidNetworkProtocol()
 
         if networkProtocol == cls.UNKNOWN_PROTO:
 
             return _info.ProxyInfo(originalLine, None, None)
 
-        with _exc.convertError(ValueError, _exc.MissingAddressData):
-
+        with convertError(ValueError, MissingAddressData):
             sourceAddr, line = line.split(b' ', 1)
 
-        with _exc.convertError(ValueError, _exc.MissingAddressData):
-
+        with convertError(ValueError, MissingAddressData):
             destAddr, line = line.split(b' ', 1)
 
-        with _exc.convertError(ValueError, _exc.MissingAddressData):
-
+        with convertError(ValueError, MissingAddressData):
             sourcePort, line = line.split(b' ', 1)
 
-        with _exc.convertError(ValueError, _exc.MissingAddressData):
-
+        with convertError(ValueError, MissingAddressData):
             destPort = line.split(b' ')[0]
 
         if networkProtocol == cls.TCP4_PROTO:

Modified: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v2parser.py
==============================================================================
--- branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v2parser.py	(original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/_v2parser.py	Tue Apr  5 16:43:10 2016
@@ -15,7 +15,10 @@
 from twisted.internet import address
 from twisted.python import compat
 
-from . import _exc
+from ._exceptions import (
+    convertError, InvalidProxyHeader, InvalidNetworkProtocol,
+    MissingAddressData
+)
 from . import _info
 from . import _interfaces
 
@@ -81,7 +84,7 @@
         """
         self.buffer += data
         if len(self.buffer) < 16:
-            raise _exc.InvalidProxyHeader()
+            raise InvalidProxyHeader()
 
         size = struct.unpack('!H', self.buffer[14:16])[0] + 16
         if len(self.buffer) < size:
@@ -147,25 +150,25 @@
         """
         prefix = line[:12]
         addrInfo = None
-        with _exc.convertError(IndexError, _exc.InvalidProxyHeader):
+        with convertError(IndexError, InvalidProxyHeader):
             # Use single value slices to ensure bytestring values are returned
             # instead of int in PY3.
             versionCommand = ord(line[12:13])
             familyProto = ord(line[13:14])
 
         if prefix != cls.PREFIX:
-            raise _exc.InvalidProxyHeader()
+            raise InvalidProxyHeader()
 
         version, command = versionCommand & _HIGH, versionCommand & _LOW
         if version not in cls.VERSIONS or command not in cls.COMMANDS:
-            raise _exc.InvalidProxyHeader()
+            raise InvalidProxyHeader()
 
         if cls.COMMANDS[command] == _LOCALCOMMAND:
             return _info.ProxyInfo(line, None, None)
 
         family, netproto = familyProto & _HIGH, familyProto & _LOW
         if family not in cls.NETFAMILIES or netproto not in cls.NETPROTOCOLS:
-            raise _exc.InvalidNetworkProtocol()
+            raise InvalidNetworkProtocol()
 
         if (
                 cls.NETFAMILIES[family] == socket.AF_UNSPEC or
@@ -176,7 +179,7 @@
         addressFormat = cls.ADDRESSFORMATS[familyProto]
         addrInfo = line[16:16+struct.calcsize(addressFormat)]
         if cls.NETFAMILIES[family] == socket.AF_UNIX:
-            with _exc.convertError(struct.error, _exc.MissingAddressData):
+            with convertError(struct.error, MissingAddressData):
                 source, dest = struct.unpack(addressFormat, addrInfo)
             return _info.ProxyInfo(
                 line,
@@ -193,7 +196,7 @@
             addrCls = address.IPv6Address
             addrParser = cls._bytesToIPv6
 
-        with _exc.convertError(struct.error, _exc.MissingAddressData):
+        with convertError(struct.error, MissingAddressData):
             info = struct.unpack(addressFormat, addrInfo)
             source, dest, sPort, dPort = info
 

Modified: branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v1parser.py
==============================================================================
--- branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v1parser.py	(original)
+++ branches/haproxy-endpoint-8203-2/twisted/protocols/haproxy/test/test_v1parser.py	Tue Apr  5 16:43:10 2016
@@ -8,7 +8,9 @@
 from twisted.trial import unittest
 from twisted.internet import address
 
-from .. import _exc
+from .._exceptions import (
+    InvalidProxyHeader, InvalidNetworkProtocol, MissingAddressData
+)
 from .. import _v1parser
 
 
@@ -22,7 +24,7 @@
         Test that an exception is raised when the PROXY header is missing.
         """
         self.assertRaises(
-            _exc.InvalidProxyHeader,
+            InvalidProxyHeader,
             _v1parser.V1Parser.parse,
             b'NOTPROXY ',
         )
@@ -33,7 +35,7 @@
         Test that an exception is raised when the proto is not TCP or UNKNOWN.
         """
         self.assertRaises(
-            _exc.InvalidNetworkProtocol,
+            InvalidNetworkProtocol,
             _v1parser.V1Parser.parse,
             b'PROXY WUTPROTO ',
         )
@@ -44,7 +46,7 @@
         Test that an exception is raised when the proto has no source data.
         """
         self.assertRaises(
-            _exc.MissingAddressData,
+            MissingAddressData,
             _v1parser.V1Parser.parse,
             b'PROXY TCP4 ',
         )
@@ -55,7 +57,7 @@
         Test that an exception is raised when the proto has no destination.
         """
         self.assertRaises(
-            _exc.MissingAddressData,
+            MissingAddressData,
             _v1parser.V1Parser.parse,
             b'PROXY TCP4 127.0.0.1 8080 8888',
         )
@@ -132,7 +134,7 @@
         self.assertFalse(info)
         self.assertFalse(remaining)
         self.assertRaises(
-            _exc.InvalidProxyHeader,
+            InvalidProxyHeader,
             parser.feed,
             b' ' * 100,
         )