aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/utils.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-23 15:03:56 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-23 15:03:56 +1200
commit1c45f5b05c7e066c28dfd4c9d1cde3b794f8983c (patch)
tree0e0d27af2fff15469824dff159ea034956f5a986 /libpathod/utils.py
parentc7b5faf7dbaab518bbe9942f018861f738ebb2b0 (diff)
downloadmitmproxy-1c45f5b05c7e066c28dfd4c9d1cde3b794f8983c.tar.gz
mitmproxy-1c45f5b05c7e066c28dfd4c9d1cde3b794f8983c.tar.bz2
mitmproxy-1c45f5b05c7e066c28dfd4c9d1cde3b794f8983c.zip
Use policy hook to apply a size limit in pathod, add corresponding cmdline arg.
Diffstat (limited to 'libpathod/utils.py')
-rw-r--r--libpathod/utils.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/libpathod/utils.py b/libpathod/utils.py
index c656a0d0..de83b19a 100644
--- a/libpathod/utils.py
+++ b/libpathod/utils.py
@@ -1,6 +1,28 @@
import os, re
import rparse
+SIZE_UNITS = dict(
+ b = 1024**0,
+ k = 1024**1,
+ m = 1024**2,
+ g = 1024**3,
+ t = 1024**4,
+)
+
+def parse_size(s):
+ try:
+ return int(s)
+ except ValueError:
+ pass
+ for i in SIZE_UNITS.keys():
+ if s.endswith(i):
+ try:
+ return int(s[:-1]) * SIZE_UNITS[i]
+ except ValueError:
+ break
+ raise ValueError("Invalid size specification.")
+
+
def get_header(val, headers):
"""
Header keys may be Values, so we have to "generate" them as we try the match.