To make sure this code works we have to use six.ensure_text (or 'u' prefix for literals) which make sure that the byte string is converted into a Unicode object using utf-8 encoding.
u'Test: %s' % six.ensure_text('ą')
Plugging Unicode strings into a byte string in LicensePoolDeliveryMechanism.__repr__. It also works only when Unicode strings contain only ASCII symbols, otherwise a UnicodeDecodeError is thrown when Python tries implicitly convert Unicode objects into byte strings.
NOTE: Excessive use of native_string, six.ensure_text may slow down the system a bit.
Description
This PR fixes Unicode problems in
Identifier.__repr__
andLicensePoolDeliveryMechanism.__repr__
.Motivation and Context
There are two problems:
Identifier.__repr__
. This works only when byte strings contain the first half of the ASCII table (the first 128 characters).For example, this line works:
But this one throws
UnicodeDecodeError
:To make sure this code works we have to use
six.ensure_text
(or 'u' prefix for literals) which make sure that the byte string is converted into a Unicode object usingutf-8
encoding.LicensePoolDeliveryMechanism.__repr__
. It also works only when Unicode strings contain only ASCII symbols, otherwise aUnicodeDecodeError
is thrown when Python tries implicitly convert Unicode objects into byte strings.NOTE: Excessive use of
native_string
,six.ensure_text
may slow down the system a bit.How Has This Been Tested?
Checklist: