aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-28 12:42:03 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-28 12:42:03 +1200
commitb4105be21e967f79d819749c44eff6ed4311f65d (patch)
tree723857cc38b59c5ebd35ab6c5b32d72e3a05c9a4 /libpathod/utils.py
downloadmitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.tar.gz
mitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.tar.bz2
mitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.zip
Initial checkin.
Diffstat (limited to 'libpathod/utils.py')
-rw-r--r--libpathod/utils.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/libpathod/utils.py b/libpathod/utils.py
new file mode 100644
index 00000000..104ee148
--- /dev/null
+++ b/libpathod/utils.py
@@ -0,0 +1,31 @@
+import copy, os
+
+class Data:
+ 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
+
+ def read(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.
+ """
+ p = self.path(path)
+ return open(p).read()
+
+data = Data(__name__)