How to use the cbor2.compat.as_unicode function in cbor2

To help you get started, we’ve selected a few cbor2 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github agronholm / cbor2 / cbor2 / encoder.py View on Github external
def encode_regexp(self, value):
        # Semantic tag 35
        self.encode_semantic(CBORTag(35, as_unicode(value.pattern)))
github agronholm / cbor2 / cbor2 / encoder.py View on Github external
def encode_mime(self, value):
        # Semantic tag 36
        self.encode_semantic(CBORTag(36, as_unicode(value.as_string())))
github agronholm / cbor2 / cbor2 / encoder.py View on Github external
if self._timezone:
                value = value.replace(tzinfo=self._timezone)
            else:
                raise CBOREncodeValueError(
                    'naive datetime {!r} encountered and no default timezone '
                    'has been set'.format(value))

        if self.datetime_as_timestamp:
            from calendar import timegm
            if not value.microsecond:
                timestamp = timegm(value.utctimetuple())
            else:
                timestamp = timegm(value.utctimetuple()) + value.microsecond / 1000000
            self.encode_semantic(CBORTag(1, timestamp))
        else:
            datestring = as_unicode(value.isoformat().replace('+00:00', 'Z'))
            self.encode_semantic(CBORTag(0, datestring))