Description: Add Django 1.11 support
 Add's support for Django 1.11.
Forwarded: http://lists.example.com/oct-2006/1234.html
Bug-Ubuntu: https://bugs.launchpad.net/bugs/1702062
Author: Danilo Segan <danilo.segan@canonical.com>

Index: django-piston3-0.3~rc2/piston/emitters.py
===================================================================
--- django-piston3-0.3~rc2.orig/piston/emitters.py	2017-07-03 11:52:16.820835027 -0400
+++ django-piston3-0.3~rc2/piston/emitters.py	2017-07-03 11:53:43.909498375 -0400
@@ -19,7 +19,7 @@
 from django.utils.xmlutils import SimplerXMLGenerator
 from django.utils.encoding import smart_text
 from django.core.urlresolvers import reverse, NoReverseMatch
-from django.core.serializers.json import DateTimeAwareJSONEncoder
+from django.core.serializers.json import DjangoJSONEncoder
 from django.http import HttpResponse
 from django.core import serializers
 
@@ -408,7 +408,7 @@
     """
     def render(self, request):
         cb = request.GET.get('callback', None)
-        seria = json.dumps(self.construct(), cls=DateTimeAwareJSONEncoder, ensure_ascii=False, indent=4)
+        seria = json.dumps(self.construct(), cls=DjangoJSONEncoder, ensure_ascii=False, indent=4)
 
         # Callback
         if cb and is_valid_jsonp_callback_value(cb):
Index: django-piston3-0.3~rc2/piston/authentication.py
===================================================================
--- django-piston3-0.3~rc2.orig/piston/authentication.py	2015-06-12 10:45:09.000000000 -0400
+++ django-piston3-0.3~rc2/piston/authentication.py	2017-07-03 11:54:16.409744745 -0400
@@ -311,9 +311,10 @@
         is_in = lambda l: all([ (p in l) for p in must_have ])
 
         auth_params = request.META.get("HTTP_AUTHORIZATION", "")
-        req_params = request.REQUEST
-             
-        return is_in(auth_params) or is_in(req_params)
+        get_params = request.GET
+        post_params = request.POST
+
+        return is_in(auth_params) or is_in(get_params) or is_in(post_params)
         
     @staticmethod
     def validate_token(request, check_timestamp=True, check_nonce=True):
Index: django-piston3-0.3~rc2/piston/utils.py
===================================================================
--- django-piston3-0.3~rc2.orig/piston/utils.py	2014-02-12 13:03:29.000000000 -0500
+++ django-piston3-0.3~rc2/piston/utils.py	2017-07-03 11:56:09.742599031 -0400
@@ -12,7 +12,6 @@
 from django.conf import settings
 from django.utils.translation import ugettext as _
 from django.template import loader, TemplateDoesNotExist
-from django.contrib.sites.models import Site
 from .decorator import decorator
 
 from datetime import datetime, timedelta
@@ -257,12 +256,13 @@
         `request.data` instead, and the handler will have to read from
         there.
         
-        It will also set `request.content_type` so the handler has an easy
-        way to tell what's going on. `request.content_type` will always be
-        None for form-encoded and/or multipart form data (what your browser sends.)
+        It will also set `request.piston_content_type` so the handler has an
+        easy way to tell what's going on. `request.piston_content_type` will
+        always be None for form-encoded and/or multipart form data
+        (what your browser sends.)
         """    
         ctype = self.content_type()
-        self.request.content_type = ctype
+        self.request.piston_content_type = ctype
         
         if not self.is_multipart() and ctype:
             loadee = self.loader_for_type(ctype)
@@ -330,6 +330,9 @@
     try:
         subject = settings.PISTON_OAUTH_EMAIL_SUBJECTS[consumer.status]
     except AttributeError:
+        # Import Site late to avoid depending on Django configuration
+        # for the rest of the code.
+        from django.contrib.sites.models import Site
         subject = "Your API Consumer for %s " % Site.objects.get_current().name
         if consumer.status == "accepted":
             subject += "was accepted!"
Index: django-piston3-0.3~rc2/piston/doc.py
===================================================================
--- django-piston3-0.3~rc2.orig/piston/doc.py	2014-02-06 11:19:24.000000000 -0500
+++ django-piston3-0.3~rc2/piston/doc.py	2017-07-03 11:55:30.338302845 -0400
@@ -4,6 +4,7 @@
 from .handler import typemapper
 from .handler import handler_tracker
 
+from django.core.exceptions import ViewDoesNotExist
 from django.core.urlresolvers import get_resolver, get_callable, get_script_prefix
 from django.shortcuts import render_to_response
 from django.template import RequestContext
@@ -152,12 +153,17 @@
                 components[i] = value
         
             lookup_view, args, kwargs = components
-            lookup_view = get_callable(lookup_view, True)
+            try:
+                lookup_view = get_callable(lookup_view)
+            except (ImportError, ViewDoesNotExist):
+                # Django 1.11 drops the can_fail argument on get_callable,
+                # so we ignore failures here..
+                pass
 
             possibilities = get_resolver(None).reverse_dict.getlist(lookup_view)
             
-            for possibility, pattern in possibilities:
-                for result, params in possibility:
+            for possibility in possibilities:
+                for result, params in possibility[0]:
                     if args:
                         if len(args) != len(params):
                             continue
