diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2016-05-21 11:53:14 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2016-05-21 11:53:14 +1200 |
commit | 123e3b130c87e53092a4f8c66effc8605298e1d0 (patch) | |
tree | f1d7325e37bcee8cc69ff06dd0e0df7610d7e0cb | |
parent | 84144ca0c635f4a42c8ba8a13e779fe127a81d45 (diff) | |
download | mitmproxy-123e3b130c87e53092a4f8c66effc8605298e1d0.tar.gz mitmproxy-123e3b130c87e53092a4f8c66effc8605298e1d0.tar.bz2 mitmproxy-123e3b130c87e53092a4f8c66effc8605298e1d0.zip |
We don't need 3 slightly different implementations of Data
-rw-r--r-- | mitmproxy/utils.py | 23 | ||||
-rw-r--r-- | pathod/utils.py | 23 | ||||
-rw-r--r-- | test/mitmproxy/test_examples.py | 3 | ||||
-rw-r--r-- | test/mitmproxy/tutils.py | 3 | ||||
-rw-r--r-- | test/pathod/tutils.py | 2 |
5 files changed, 11 insertions, 43 deletions
diff --git a/mitmproxy/utils.py b/mitmproxy/utils.py index 5fd062ea..cda5bba6 100644 --- a/mitmproxy/utils.py +++ b/mitmproxy/utils.py @@ -7,6 +7,9 @@ import json import importlib import inspect +import netlib.utils + + def timestamp(): """ Returns a serializable UTC timestamp. @@ -73,25 +76,7 @@ def pretty_duration(secs): return "{:.0f}ms".format(secs * 1000) -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 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 -pkg_data = Data(__name__) +pkg_data = netlib.utils.Data(__name__) class LRUCache: diff --git a/pathod/utils.py b/pathod/utils.py index 1e5bd9a4..d1e2dd00 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -1,5 +1,6 @@ import os import sys +import netlib.utils SIZE_UNITS = dict( @@ -75,27 +76,7 @@ def escape_unprintables(s): return s -class Data(object): - - def __init__(self, name): - m = __import__(name) - dirname, _ = os.path.split(m.__file__) - self.dirname = os.path.abspath(dirname) - - 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 - - -data = Data(__name__) +data = netlib.utils.Data(__name__) def daemonize(stdin='/dev/null', stdout='/dev/null', stderr='/dev/null'): # pragma: no cover diff --git a/test/mitmproxy/test_examples.py b/test/mitmproxy/test_examples.py index c401a6b9..0c117306 100644 --- a/test/mitmproxy/test_examples.py +++ b/test/mitmproxy/test_examples.py @@ -5,11 +5,12 @@ from contextlib import contextmanager from mitmproxy import utils, script from mitmproxy.proxy import config +import netlib.utils from netlib import tutils as netutils from netlib.http import Headers from . import tservers, tutils -example_dir = utils.Data(__name__).path("../../examples") +example_dir = netlib.utils.Data(__name__).path("../../examples") class DummyContext(object): diff --git a/test/mitmproxy/tutils.py b/test/mitmproxy/tutils.py index d51ac185..2dfd710e 100644 --- a/test/mitmproxy/tutils.py +++ b/test/mitmproxy/tutils.py @@ -8,6 +8,7 @@ from contextlib import contextmanager from unittest.case import SkipTest +import netlib.utils import netlib.tutils from mitmproxy import utils, controller from mitmproxy.models import ( @@ -163,4 +164,4 @@ def capture_stderr(command, *args, **kwargs): sys.stderr = out -test_data = utils.Data(__name__) +test_data = netlib.utils.Data(__name__) diff --git a/test/pathod/tutils.py b/test/pathod/tutils.py index 9739afde..f6ed3efb 100644 --- a/test/pathod/tutils.py +++ b/test/pathod/tutils.py @@ -116,7 +116,7 @@ tmpdir = netlib.tutils.tmpdir raises = netlib.tutils.raises -test_data = utils.Data(__name__) +test_data = netlib.utils.Data(__name__) def render(r, settings=language.Settings()): |