aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/utils.py23
-rw-r--r--pathod/utils.py23
-rw-r--r--test/mitmproxy/test_examples.py3
-rw-r--r--test/mitmproxy/tutils.py3
-rw-r--r--test/pathod/tutils.py2
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()):