def _type_check_datetime(self, value): try: parse_to_aware_datetime(value) return True except (TypeError, ValueError, AttributeError): # Yes, dateutil can sometimes raise an AttributeError # when parsing timestamps. return False
def _convert_header_value(self, shape, value): if shape.type_name == 'timestamp': datetime_obj = parse_to_aware_datetime(value) timestamp = calendar.timegm(datetime_obj.utctimetuple()) return self._timestamp_rfc822(timestamp) else: return value
def _convert_timestamp_to_str(self, value, timestamp_format=None): if timestamp_format is None: timestamp_format = self.TIMESTAMP_FORMAT timestamp_format = timestamp_format.lower() datetime_obj = parse_to_aware_datetime(value) converter = getattr(self, '_timestamp_%s' % timestamp_format) final_value = converter(datetime_obj) return final_value
def _convert_header_value(self, shape, value): if shape.type_name == 'timestamp': datetime_obj = parse_to_aware_datetime(value) timestamp = calendar.timegm(datetime_obj.utctimetuple()) timestamp_format = shape.serialization.get( 'timestampFormat', self.HEADER_TIMESTAMP_FORMAT) return self._convert_timestamp_to_str(timestamp, timestamp_format) elif is_json_value_header(shape): # Serialize with no spaces after separators to save space in # the header. return self._get_base64(json.dumps(value, separators=(',', ':'))) else: return value
def _to_timestamp(self, datetime_obj): obj = utils.parse_to_aware_datetime(datetime_obj) return obj.strftime('%Y-%m-%dT%H:%M:%SZ')
def _convert_timestamp_to_str(self, value): datetime_obj = parse_to_aware_datetime(value) converter = getattr(self, '_timestamp_%s' % self.TIMESTAMP_FORMAT.lower()) final_value = converter(datetime_obj) return final_value