raise ArgumentFormat("{0} not a hex integer".format(val))
try:
int(val)
- except:
+ except ValueError:
raise ArgumentFormat('can\'t convert {0} to integer'.format(val))
try:
int(bits)
- except:
+ except ValueError:
raise ArgumentFormat('can\'t convert {0} to integer'.format(bits))
self.val = s
# Have an arg; validate it
try:
validate_one(myarg, desc)
- valid = True
except ArgumentError as e:
- valid = False
-
# argument mismatch
if not desc.req:
# if not required, just push back; it might match
# the next arg
- save_exception = [ myarg, e ]
+ save_exception = [myarg, e]
myargs.insert(0, myarg)
break
else:
# (relies on a cmdsig being key,val where val is a list of len 1)
def grade(cmd):
- # prefer optional arguments over required ones
- sigs = cmd['sig']
- return sum(map(lambda sig: sig.req, sigs))
+ # prefer optional arguments over required ones
+ sigs = cmd['sig']
+ return sum(map(lambda sig: sig.req, sigs))
bestcmds_sorted = sorted(bestcmds, key=grade)
if verbose:
return valid_dict
-
def find_cmd_target(childargs):
"""
Using a minimal validation, figure out whether the command
def run_in_thread(func, *args, **kwargs):
- interrupt = False
timeout = kwargs.pop('timeout', 0)
if timeout == 0 or timeout == None:
# python threading module will just get blocked if timeout is `None`,