k4ever/k4ever/api2/helper.py

22 lines
523 B
Python

from decimal import Decimal, InvalidOperation
def getInt(d, key, default):
""" Helper for dict.get to return the default on error. """
try:
return int(d.get(key, default))
except ValueError:
return default
def getDecimal(d, key, default):
""" Helper for dict.get to return the default on error. """
try:
return Decimal(d.get(key, default))
except InvalidOperation:
return default
def getError(err, msg):
""" Get an error, write a message on it an return it. """
err.write("\n%s\n" % (msg,))
return err