def __exeute_method(self, method, value): try: result = getattr(self.typeclass(value, self.strict_level), method)() if method == "validate": result = "-" except (TypeError, typepy.TypeConversionError): return '"E"' # for string tests if NullString(result, StrictLevel.MAX).is_type(): return '""' strict_level = StrictLevel.MAX typeobj = Integer(result, strict_level) if typeobj.is_type(): return typeobj.convert() typeobj = RealNumber(result, strict_level) if typeobj.is_type(): return typeobj.convert() if String(result, strict_level).is_type(): return '"{}"'.format(result) if Infinity(result, strict_level).is_type(): return '"inf"' if Nan(result, strict_level).is_type(): return '"nan"' return result
def get_decimal_places(self, value): from typepy import Integer int_type = Integer(value) float_digit_len = 0 if int_type.is_type(): abs_value = abs(int_type.convert()) else: abs_value = abs(float(value)) text_value = text_type(abs_value) float_text = 0 if text_value.find(".") != -1: float_text = text_value.split(".")[1] float_digit_len = len(float_text) elif text_value.find("e-") != -1: float_text = text_value.split("e-")[1] float_digit_len = int(float_text) - 1 abs_digit = self.__min_digit_len for treshold in self.__tresholds: if abs_value < math.pow(10, treshold.pow): abs_digit = treshold.digit_len break return min(abs_digit, float_digit_len)