From 069119364d6490e52ba26f2d8001c6b2bf50ab7b Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Thu, 20 Oct 2016 09:35:55 +1300 Subject: Create mitmproxy.utils hierarchy - Add mitproxy.utils.lrucache, mitproxy.utils.data --- netlib/tutils.py | 6 ++++-- netlib/utils.py | 30 ------------------------------ 2 files changed, 4 insertions(+), 32 deletions(-) (limited to 'netlib') diff --git a/netlib/tutils.py b/netlib/tutils.py index d22fdd1c..6fa2d7b6 100644 --- a/netlib/tutils.py +++ b/netlib/tutils.py @@ -6,7 +6,9 @@ import shutil from contextlib import contextmanager import sys -from netlib import utils, tcp, http +from mitmproxy.utils import data +from netlib import tcp +from netlib import http def treader(bytes): @@ -87,7 +89,7 @@ class RaisesContext: return True -test_data = utils.Data(__name__) +test_data = data.Data(__name__) # FIXME: Temporary workaround during repo merge. test_data.dirname = os.path.join(test_data.dirname, "..", "test", "netlib") diff --git a/netlib/utils.py b/netlib/utils.py index 8cd9ba6e..12b94d74 100644 --- a/netlib/utils.py +++ b/netlib/utils.py @@ -1,7 +1,4 @@ -import os.path import re -import importlib -import inspect def setbit(byte, offset, value): @@ -48,33 +45,6 @@ class BiDi: return self.values.get(n, default) -class Data: - - def __init__(self, name): - m = importlib.import_module(name) - dirname = os.path.dirname(inspect.getsourcefile(m)) - self.dirname = os.path.abspath(dirname) - - def push(self, subpath): - """ - Change the data object to a path relative to the module. - """ - self.dirname = os.path.join(self.dirname, subpath) - return self - - def path(self, path): - """ - Returns a path to the package data housed at 'path' under this - module.Path can be a path to a file, or to a directory. - - This function will raise ValueError if the path does not exist. - """ - fullpath = os.path.join(self.dirname, path) - if not os.path.exists(fullpath): - raise ValueError("dataPath: %s does not exist." % fullpath) - return fullpath - - _label_valid = re.compile(b"(?!-)[A-Z\d-]{1,63}(?