Convert data in responses and resource streams to the right string type.

Review Request #9735 — Created March 4, 2018 and submitted

Information

Djblets
release-2.0.x
fb57865...

Reviewers

HttpResponse returns data as byte strings, and in Python 2.x we could
generally just check against those without problems, but on Python 3.x
the different string types are less compatible. We now convert the
responses to Unicode strings using Django's force_text() (which
intelligently performs a decode when necessary).

We also convert the result of pkg_resources.resource_stream for the
DMARC code, for use in PublicSuffixList. Rather than a straight text
conversion, we need to make use of codecs.getreader(), which will
correctly convert the data in the stream to the right format.

Unit tests pass on Python 2.7, 3.4, 3.5, and 3.6.

Description From Last Updated

Can we break this up a little bit more? We should also prefer "utf-8" to "utf8" for consistency. stream = …

daviddavid
david
  1. 
      
  2. djblets/mail/dmarc.py (Diff revision 1)
     
     
     
    Show all issues

    Can we break this up a little bit more? We should also prefer "utf-8" to "utf8" for consistency.

    stream = pkg_resources.resource_stream('djblets', filename)
    reader = codecs.getreader('utf-8')(stream)
    psl = PublicSuffixList(reader)
    
  3. 
      
chipx86
david
  1. Ship It!
  2. 
      
chipx86
Review request changed

Status: Closed (submitted)

Change Summary:

Pushed to release-2.0.x (50e044f)
Loading...