def _prepare_single_raw_value(val): if isinstance(val, basestring): return val if isinstance(val, (bool, int, long, float)): return str(val) if isinstance(val, datetime.datetime): return str(datetime_utc_normalize(val)) raise TypeError('unsupported class {} of parameter value {!r}'.format( ascii_str(val.__class__.__name__), val))
def _prepare_single_raw_value(val): if isinstance(val, str): return val if isinstance(val, (bytes, bytearray)): return val.decode('utf-8') if isinstance(val, (bool, int, float)): return str(val) if isinstance(val, datetime.datetime): return str(datetime_utc_normalize(val)) raise TypeError('unsupported class {} of parameter value {!a}'.format( ascii_str(val.__class__.__name__), val))
def clean_result_value(self, value): """ The input `value` should be a :class:`str`/:class:`unicode` string (*ISO-8601*-formatted) or a :class:`datetime.datetime` object (timezone-aware or *naive*). Returns: a :class:`datetime.datetime` object (a *naive* one, i.e. not aware of any timezone). """ value = super(DateTimeField, self).clean_result_value(value) if isinstance(value, datetime.datetime): return datetime_utc_normalize(value) if isinstance(value, basestring): return self._parse_datetime_string(value) raise TypeError('{!r} is neither a str/unicode nor a ' 'datetime.datetime object'.format(value))
def clean_result_value(self, value): """ The input `value` should be a :class:`str`/:class:`unicode` string (*ISO-8601*-formatted) or a :class:`datetime.datetime` object (timezone-aware or *naive*). Returns: a :class:`datetime.datetime` object (a *naive* one, i.e. not aware of any timezone). """ value = super(DateTimeField, self).clean_result_value(value) if isinstance(value, datetime.datetime): return datetime_utc_normalize(value) if isinstance(value, basestring): return self._parse_datetime_string(value) raise TypeError( '{!r} is neither a str/unicode nor a ' 'datetime.datetime object'.format(value))
def clean_result_value(self, value): """ The input `value` should be a :class:`str` (*ISO-8601*-formatted) or a :class:`bytes`/:class:`bytearray` (*ISO-8601*-formatted), or a :class:`datetime.datetime` object (timezone-aware or *naive*). Returns: a :class:`datetime.datetime` object (a *naive* one, i.e. not aware of any timezone). """ value = super(DateTimeField, self).clean_result_value(value) if isinstance(value, datetime.datetime): return datetime_utc_normalize(value) if isinstance(value, (bytes, bytearray)): value = value.decode('utf-8', 'replace') if isinstance(value, (str, unicode)): #3: `unicode`-- return self._parse_datetime_string(value) raise TypeError('{!r} is neither a str/bytes/bytearray nor a ' 'datetime.datetime object'.format(value))
def _datetime_to_str(self, dt): return datetime_utc_normalize(dt).isoformat() + "Z"