def deserialize(self, value): try: value = int(value) except (TypeError, ValueError): msg = self.ERRORS['not_snowflake'] raise SerializationError(msg) from None if value.bit_length() > 64: msg = self.ERRORS['not_snowflake'] raise SerializationError(msg) from None return value
def parse(self, datestring): """ Source: https://bitbucket.org/micktwomey/pyiso8601 """ m = ISO8601_REGEX.match(datestring) if not m: raise SerializationError(self.MESSAGES['unknown_format']) groups = m.groupdict() tz = datetime.timezone.utc groups["second_fraction"] = int( Decimal("0.%s" % (groups["second_fraction"] or 0)) * Decimal("1000000.0")) try: return datetime.datetime( year=self.to_int(groups, "year"), month=self.to_int(groups, "month", default=self.to_int(groups, "monthdash", required=False, default=1)), day=self.to_int(groups, "day", default=self.to_int(groups, "daydash", required=False, default=1)), hour=self.to_int(groups, "hour", default_to_zero=True), minute=self.to_int(groups, "minute", default_to_zero=True), second=self.to_int(groups, "second", default_to_zero=True), microsecond=groups["second_fraction"], tzinfo=tz, ) except Exception as e: raise SerializationError(self.MESSAGES['unknown_format'])
def deserialize(self, value): if value is None: return None if type(value) == datetime.datetime: return value if type(value) == str: return self.parse(value) if type(value) == int: return datetime.datetime.fromtimestamp(value) raise SerializationError(self.MESSAGES['unknown_format'])
def deserialize(self, value): try: return int(value) except (TypeError, ValueError): msg = self.ERRORS['not_integer'] raise SerializationError(msg) from None
def deserialize(self, value): if not self.convert and not isinstance(value, str): msg = self.ERRORS['not_string'].format(value) raise SerializationError(msg) from None return str(value)
def deserialize(self, value): if not isinstance(value, bool): msg = self.ERRORS['not_boolean'] raise SerializationError(msg) from None return value