Example #1
0
 def __args_to_instance(args):
     if len(args) == 0:
         return gnc_numeric_zero()
     elif len(args) == 1:
         arg = args[0]
         if isinstance(arg, int):
             return gnc_numeric_create(arg ,1)
         elif isinstance(arg, float):
             return double_to_gnc_numeric(arg, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER)
         elif isinstance(arg, str):
             instance = gnc_numeric_zero()
             if not string_to_gnc_numeric(arg, instance):
                 raise TypeError('Failed to convert to GncNumeric: ' + str(args))
             return instance
         else:
             raise TypeError('Only single int/float/str allowed: ' + str(args))
     elif len(args) == 2:
         if isinstance(args[0], int) and isinstance(args[1], int):
             return gnc_numeric_create(*args)
         else:
             raise TypeError('Only two ints allowed: ' + str(args))
     elif len(args) == 3:
         if isinstance(args[0], float) \
             and isinstance(args[1], int) \
             and type(args[2]) == type(GNC_HOW_DENOM_FIXED):
             return double_to_gnc_numeric(*args)
         else:
             raise TypeError('Only (float, int, GNC_HOW_RND_*) allowed: ' + str(args))
     else:
         raise TypeError('Required single int/float/str or two ints: ' + str(args))
Example #2
0
 def __args_to_instance(args):
     if len(args) == 0:
         return gnc_numeric_zero()
     elif len(args) == 1:
         arg = args[0]
         if isinstance(arg, int):
             return gnc_numeric_create(arg ,1)
         elif isinstance(arg, float):
             return double_to_gnc_numeric(arg, GNC_DENOM_AUTO, GNC_HOW_DENOM_FIXED | GNC_HOW_RND_NEVER)
         elif isinstance(arg, str):
             instance = gnc_numeric_zero()
             if not string_to_gnc_numeric(arg, instance):
                 raise TypeError('Failed to convert to GncNumeric: ' + str(args))
             return instance
         else:
             raise TypeError('Only single int/float/str allowed: ' + str(args))
     elif len(args) == 2:
         if isinstance(args[0], int) and isinstance(args[1], int):
             return gnc_numeric_create(*args)
         else:
             raise TypeError('Only two ints allowed: ' + str(args))
     elif len(args) == 3:
         if isinstance(args[0], float) \
             and isinstance(args[1], int) \
             and type(args[2]) == type(GNC_HOW_DENOM_FIXED):
             return double_to_gnc_numeric(*args)
         else:
             raise TypeError('Only (float, int, GNC_HOW_RND_*) allowed: ' + str(args))
     else:
         raise TypeError('Required single int/float/str or two ints: ' + str(args))