# -*- coding: utf-8 -*-
"""
Describes the authentication protocols and generalizations used to
authenticate access to a resource endpoint.
"""
from __future__ import print_function, unicode_literals
from __future__ import absolute_import, division
from django import http


class Response(http.HttpResponse):
    """Extends django's `HttpResponse` to more closely follow `HTTP/1.1`.
    """

    def __init__(self, *args, **kwargs):
        # Delegate to django to set us up right.
        super(Response, self).__init__(*args, **kwargs)

        if not self.content:
            # No need to specify the default content-type if we don't
            # have a body.
            del self['Content-Type']

    @http.HttpResponse.content.setter
    def content(self, value):
        # Delegate to django to actually set our content
        super(Response, self)._set_content(value)

        if self.content:
            # Hop in and set our content-length automatically because it just
            # feels right
            self['Content-Length'] = len(bytes(self.content))

@@ -266,16 +266,657 @@
 t http%0A%0A
+# Normalize %60http.client%60 and %60httplib%60%0A# TODO: We can remove this when the move to python 3 is done%0Afrom six.moves import http_client as client%0A%0Atry:%0A    # Attempt to get additional status codes (added in python 3.2)%0A    getattr(client, 'PRECONDITION_REQUIRED')%0A    getattr(client, 'TOO_MANY_REQUESTS')%0A    getattr(client, 'REQUEST_HEADER_FIELDS_TOO_LARGE')%0A    getattr(client, 'NETWORK_AUTHENTICATION_REQUIRED')%0A%0Aexcept AttributeError:%0A    # Don't have em; add them%0A    client.PRECONDITION_REQUIRED = 428%0A    client.TOO_MANY_REQUESTS = 429%0A    client.REQUEST_HEADER_FIELDS_TOO_LARGE = 431%0A    client.NETWORK_AUTHENTICATION_REQUIRED = 511%0A%0A
 %0Aclass R

Normalize http.client and httplib for our use case.