From b2f63458fcda7878d5cf674c2f1e9ca7db5bf3ce Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Tue, 31 May 2016 19:32:08 +1200 Subject: Move human-friendly format functions to netlib.human, remove redundant implementations --- pathod/language/base.py | 6 +++--- pathod/pathod_cmdline.py | 4 ++-- pathod/utils.py | 23 ----------------------- 3 files changed, 5 insertions(+), 28 deletions(-) (limited to 'pathod') diff --git a/pathod/language/base.py b/pathod/language/base.py index 54ca6492..97111ed6 100644 --- a/pathod/language/base.py +++ b/pathod/language/base.py @@ -5,8 +5,8 @@ import pyparsing as pp from six.moves import reduce from netlib.utils import escaped_str_to_bytes, bytes_to_escaped_str +from netlib import human -from .. import utils from . import generators, exceptions @@ -158,7 +158,7 @@ class TokValueGenerate(Token): self.usize, self.unit, self.datatype = usize, unit, datatype def bytes(self): - return self.usize * utils.SIZE_UNITS[self.unit] + return self.usize * human.SIZE_UNITS[self.unit] def get_generator(self, settings_): return generators.RandomGenerator(self.datatype, self.bytes()) @@ -173,7 +173,7 @@ class TokValueGenerate(Token): u = reduce( operator.or_, - [pp.Literal(i) for i in utils.SIZE_UNITS.keys()] + [pp.Literal(i) for i in human.SIZE_UNITS.keys()] ).leaveWhitespace() e = e + pp.Optional(u, default=None) diff --git a/pathod/pathod_cmdline.py b/pathod/pathod_cmdline.py index a7cd2495..a4f05faf 100644 --- a/pathod/pathod_cmdline.py +++ b/pathod/pathod_cmdline.py @@ -4,7 +4,7 @@ import os import os.path import re -from netlib import tcp +from netlib import tcp, human from . import pathod, version, utils @@ -205,7 +205,7 @@ def args_pathod(argv, stdout_=sys.stdout, stderr_=sys.stderr): sizelimit = None if args.sizelimit: try: - sizelimit = utils.parse_size(args.sizelimit) + sizelimit = human.parse_size(args.sizelimit) except ValueError as v: return parser.error(v) args.sizelimit = sizelimit diff --git a/pathod/utils.py b/pathod/utils.py index 8c6d6290..fe12f541 100644 --- a/pathod/utils.py +++ b/pathod/utils.py @@ -5,15 +5,6 @@ import netlib.utils from netlib.utils import bytes_to_escaped_str -SIZE_UNITS = dict( - b=1024 ** 0, - k=1024 ** 1, - m=1024 ** 2, - g=1024 ** 3, - t=1024 ** 4, -) - - class MemBool(object): """ @@ -28,20 +19,6 @@ class MemBool(object): return bool(v) -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 parse_anchor_spec(s): """ Return a tuple, or None on error. -- cgit v1.2.3