                      if isinstance(field, serializers.HiddenField):
                          data.pop(name, None)
                  content = renderer.render(data, accepted, context)
                  # Renders returns bytes, but CharField expects a str.
                  content = content.decode('utf-8')
              else:
                  content = None
  
              # Generate a generic form that includes a content type field,
              # and a content field.
 
</s> remove         # On python 2.x json.dumps() returns bytestrings if ensure_ascii=True,
        # but if ensure_ascii=False, the return type is underspecified,
        # and may (or may not) be unicode.
        # On python 3.x json.dumps() returns unicode strings.
        if isinstance(ret, str):
            # We always fully escape \u2028 and \u2029 to ensure we output JSON
            # that is a strict javascript subset. If bytes were returned
            # by json.dumps() then we don't have these characters in any case.
            # See: http://timelessrepo.com/json-isnt-a-javascript-subset
            ret = ret.replace('\u2028', '\\u2028').replace('\u2029', '\\u2029')
            return bytes(ret.encode('utf-8'))
        return ret
 </s> add         # We always fully escape \u2028 and \u2029 to ensure we output JSON
        # that is a strict javascript subset.
        # See: http://timelessrepo.com/json-isnt-a-javascript-subset
        ret = ret.replace('\u2028', '\\u2028').replace('\u2029', '\\u2029')
        return ret.encode() </s> remove     assert re.search(r'\bcsrfToken: ""', result.content.decode('utf-8'))
 </s> add     assert re.search(r'\bcsrfToken: ""', result.content.decode()) </s> remove             # On python 2.x the return type for json.dumps() is underspecified.
            # On python 3.x json.dumps() returns unicode strings.
            if isinstance(value, str):
                value = bytes(value.encode('utf-8'))
 </s> add             value = value.encode() </s> remove             return obj.decode('utf-8')
 </s> add             return obj.decode() </s> remove         content = response.content.decode('utf8')
 </s> add         content = response.content.decode()
                content = content.decode()
                      if isinstance(field, serializers.HiddenField):
                          data.pop(name, None)
                  content = renderer.render(data, accepted, context)
                  # Renders returns bytes, but CharField expects a str.
                content = content.decode()
              else:
                  content = None
  
              # Generate a generic form that includes a content type field,
              # and a content field.
keep keep keep keep replace keep keep keep keep keep
 Drop default 'utf-8' to .encode()/.decode() (#6633)

A Python 3 cleanup that allows for less noise in the code.

https://docs.python.org/3/library/stdtypes.html#bytes.decode
https://docs.python.org/3/library/stdtypes.html#str.encode 
rest_framework/renderers.py