diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-10-20 09:35:55 +1300 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-10-20 09:35:55 +1300 |
commit | 069119364d6490e52ba26f2d8001c6b2bf50ab7b (patch) | |
tree | a6308ebd4d1337db08784295eba328a8e8f05514 /netlib | |
parent | 7440232f6036bb29d1c142cd32a9bb27458b30d1 (diff) | |
download | mitmproxy-069119364d6490e52ba26f2d8001c6b2bf50ab7b.tar.gz mitmproxy-069119364d6490e52ba26f2d8001c6b2bf50ab7b.tar.bz2 mitmproxy-069119364d6490e52ba26f2d8001c6b2bf50ab7b.zip |
Create mitmproxy.utils hierarchy
- Add mitproxy.utils.lrucache, mitproxy.utils.data
Diffstat (limited to 'netlib')
-rw-r--r-- | netlib/tutils.py | 6 | ||||
-rw-r--r-- | netlib/utils.py | 30 |
2 files changed, 4 insertions, 32 deletions
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}(?<!-)$", re.IGNORECASE) |