def encode_datetime(encoder, value): # Semantic tag 0 if not value.tzinfo: if encoder.timezone: value = value.replace(tzinfo=encoder.timezone) else: raise CBOREncodeError( 'naive datetime encountered and no default timezone has been set') if encoder.datetime_as_timestamp: from calendar import timegm timestamp = timegm(value.utctimetuple()) + value.microsecond // 1000000 encode_semantic(encoder, CBORTag(1, timestamp)) else: datestring = as_unicode(value.isoformat().replace('+00:00', 'Z')) encode_semantic(encoder, CBORTag(0, datestring))
def encode_datetime(encoder, value): # Semantic tag 0 if not value.tzinfo: if encoder.timezone: value = value.replace(tzinfo=encoder.timezone) else: raise CBOREncodeError( 'naive datetime encountered and no default timezone has been set' ) if encoder.datetime_as_timestamp: from calendar import timegm timestamp = timegm(value.utctimetuple()) + value.microsecond // 1000000 encode_semantic(encoder, CBORTag(1, timestamp)) else: datestring = as_unicode(value.isoformat().replace('+00:00', 'Z')) encode_semantic(encoder, CBORTag(0, datestring))
def encode_mime(self, value, fp): # Semantic tag 36 self.encode_semantic(36, as_unicode(value.as_string()), fp)
def encode_regexp(self, value, fp): # Semantic tag 35 self.encode_semantic(35, as_unicode(value.pattern), fp)
def encode_mime(encoder, value): # Semantic tag 36 encode_semantic(encoder, CBORTag(36, as_unicode(value.as_string())))
def encode_regexp(encoder, value): # Semantic tag 35 encode_semantic(encoder, CBORTag(35, as_unicode(value.pattern)))