aboutsummaryrefslogtreecommitdiffstats
path: root/netlib
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-20 10:32:09 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-10-20 10:32:09 +1300
commit95551265852e6ff05ab5e5204e1a919f66fa4eae (patch)
treea70edd6e89742e3b744d558a1b91138daa6454e6 /netlib
parenta684585e7cf7099ea61f23b3176b492883f19f00 (diff)
downloadmitmproxy-95551265852e6ff05ab5e5204e1a919f66fa4eae.tar.gz
mitmproxy-95551265852e6ff05ab5e5204e1a919f66fa4eae.tar.bz2
mitmproxy-95551265852e6ff05ab5e5204e1a919f66fa4eae.zip
netlib.utils.BiDi -> mitmproxy.types.bidi.BiDi
Diffstat (limited to 'netlib')
-rw-r--r--netlib/socks.py13
-rw-r--r--netlib/utils.py29
-rw-r--r--netlib/websockets/frame.py5
3 files changed, 10 insertions, 37 deletions
diff --git a/netlib/socks.py b/netlib/socks.py
index 9f1adb98..30fe1c9d 100644
--- a/netlib/socks.py
+++ b/netlib/socks.py
@@ -3,6 +3,7 @@ import array
import ipaddress
from netlib import tcp, utils
+from mitmproxy.types import bidi
class SocksError(Exception):
@@ -10,24 +11,24 @@ class SocksError(Exception):
super().__init__(message)
self.code = code
-VERSION = utils.BiDi(
+VERSION = bidi.BiDi(
SOCKS4=0x04,
SOCKS5=0x05
)
-CMD = utils.BiDi(
+CMD = bidi.BiDi(
CONNECT=0x01,
BIND=0x02,
UDP_ASSOCIATE=0x03
)
-ATYP = utils.BiDi(
+ATYP = bidi.BiDi(
IPV4_ADDRESS=0x01,
DOMAINNAME=0x03,
IPV6_ADDRESS=0x04
)
-REP = utils.BiDi(
+REP = bidi.BiDi(
SUCCEEDED=0x00,
GENERAL_SOCKS_SERVER_FAILURE=0x01,
CONNECTION_NOT_ALLOWED_BY_RULESET=0x02,
@@ -39,14 +40,14 @@ REP = utils.BiDi(
ADDRESS_TYPE_NOT_SUPPORTED=0x08,
)
-METHOD = utils.BiDi(
+METHOD = bidi.BiDi(
NO_AUTHENTICATION_REQUIRED=0x00,
GSSAPI=0x01,
USERNAME_PASSWORD=0x02,
NO_ACCEPTABLE_METHODS=0xFF
)
-USERNAME_PASSWORD_VERSION = utils.BiDi(
+USERNAME_PASSWORD_VERSION = bidi.BiDi(
DEFAULT=0x01
)
diff --git a/netlib/utils.py b/netlib/utils.py
index 12b94d74..779eaa27 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -16,35 +16,6 @@ def getbit(byte, offset):
return bool(byte & mask)
-class BiDi:
-
- """
- A wee utility class for keeping bi-directional mappings, like field
- constants in protocols. Names are attributes on the object, dict-like
- access maps values to names:
-
- CONST = BiDi(a=1, b=2)
- assert CONST.a == 1
- assert CONST.get_name(1) == "a"
- """
-
- def __init__(self, **kwargs):
- self.names = kwargs
- self.values = {}
- for k, v in kwargs.items():
- self.values[v] = k
- if len(self.names) != len(self.values):
- raise ValueError("Duplicate values not allowed.")
-
- def __getattr__(self, k):
- if k in self.names:
- return self.names[k]
- raise AttributeError("No such attribute: %s", k)
-
- def get_name(self, n, default=None):
- return self.values.get(n, default)
-
-
_label_valid = re.compile(b"(?!-)[A-Z\d-]{1,63}(?<!-)$", re.IGNORECASE)
diff --git a/netlib/websockets/frame.py b/netlib/websockets/frame.py
index e022a95c..26303094 100644
--- a/netlib/websockets/frame.py
+++ b/netlib/websockets/frame.py
@@ -6,6 +6,7 @@ from netlib import tcp
from mitmproxy.utils import strutils
from netlib import utils
from mitmproxy.utils import human
+from mitmproxy.types import bidi
from .masker import Masker
@@ -15,7 +16,7 @@ MAX_64_BIT_INT = (1 << 64)
DEFAULT = object()
# RFC 6455, Section 5.2 - Base Framing Protocol
-OPCODE = utils.BiDi(
+OPCODE = bidi.BiDi(
CONTINUE=0x00,
TEXT=0x01,
BINARY=0x02,
@@ -25,7 +26,7 @@ OPCODE = utils.BiDi(
)
# RFC 6455, Section 7.4.1 - Defined Status Codes
-CLOSE_REASON = utils.BiDi(
+CLOSE_REASON = bidi.BiDi(
NORMAL_CLOSURE=1000,
GOING_AWAY=1001,
PROTOCOL_ERROR=1002,