mitmproxy/libpathod/utils.py

43 lines
1.1 KiB
Python
Raw Normal View History

import os, re
2012-04-29 00:05:38 +00:00
import rparse
2012-06-24 05:47:55 +00:00
def get_header(val, headers):
"""
Header keys may be Values, so we have to "generate" them as we try the match.
"""
for k, v in headers:
if len(k) == len(val) and k[:].lower() == val:
return v
return None
2012-04-29 00:05:38 +00:00
2012-06-24 04:38:32 +00:00
def parse_anchor_spec(s):
2012-04-29 00:05:38 +00:00
"""
2012-06-24 04:38:32 +00:00
Return a tuple, or None on error.
2012-04-29 00:05:38 +00:00
"""
if not "=" in s:
2012-06-24 04:38:32 +00:00
return None
return tuple(s.split("=", 1))
2012-04-29 00:05:38 +00:00
2012-04-28 00:42:03 +00:00
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
data = Data(__name__)