aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--netlib/utils.py21
-rw-r--r--test/tutils.py3
2 files changed, 21 insertions, 3 deletions
diff --git a/netlib/utils.py b/netlib/utils.py
index ac42bd53..bee412f9 100644
--- a/netlib/utils.py
+++ b/netlib/utils.py
@@ -1,5 +1,5 @@
from __future__ import (absolute_import, print_function, division)
-
+import os.path
def isascii(s):
try:
@@ -110,3 +110,22 @@ def pretty_size(size):
if x == int(x):
x = int(x)
return str(x) + suf
+
+
+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
diff --git a/test/tutils.py b/test/tutils.py
index 95c8b80a..94139f6f 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -3,9 +3,8 @@ import tempfile
import os
import shutil
from contextlib import contextmanager
-from libpathod import utils
-from netlib import tcp
+from netlib import tcp, utils
def treader(bytes):