From 1c45f5b05c7e066c28dfd4c9d1cde3b794f8983c Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 23 Jul 2012 15:03:56 +1200 Subject: Use policy hook to apply a size limit in pathod, add corresponding cmdline arg. --- libpathod/utils.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'libpathod/utils.py') 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. -- cgit v1.2.3