1. Brodie Rao
  2. django-piston-oauth2

Commits

Brodie Rao  committed 50ef9cc

Fix Django 1.4 compatibility (part 2)

  • Participants
  • Parent commits d33942a
  • Branches default

Comments (0)

Files changed (3)

File piston/resource.py

View file
             status_code = result.status_code
             # Note: We can't use result.content here because that method attempts
             # to convert the content into a string which we don't want.
-            # when _is_string is False _container is the raw data
+            # when _base_content_is_iter is True _container is the raw data
             result = result._container
 
         srl = emitter(result, typemapper, handler, fields, anonymous)

File piston/tests.py

View file
          response = resource(request, emitter_format='json')
 
          self.assertEquals(201, response.status_code)
-         self.assertTrue(response._is_string, "Expected response content to be a string")
+         self.assertFalse(response._base_content_is_iter, "Expected response content to be a string")
 
          # compare the original data dict with the json response 
          # converted to a dict

File piston/utils.py

View file
         except TypeError:
             raise AttributeError(attr)
 
-        class HttpResponseWrapper(HttpResponse):
-            """
-            Wrap HttpResponse and make sure that the internal _is_string 
-            flag is updated when the _set_content method (via the content 
-            property) is called
-            """
-            def _set_content(self, content):
-                """
-                Set the _container and _is_string properties based on the 
-                type of the value parameter. This logic is in the construtor
-                for HttpResponse, but doesn't get repeated when setting 
-                HttpResponse.content although this bug report (feature request)
-                suggests that it should: http://code.djangoproject.com/ticket/9403 
-                """
-                if not isinstance(content, basestring) and hasattr(content, '__iter__'):
-                    self._container = content
-                    self._is_string = False
-                else:
-                    self._container = [content]
-                    self._is_string = True
-
-            content = property(HttpResponse._get_content, _set_content)            
-
-        return HttpResponseWrapper(r, content_type='text/plain', status=c)
+        return HttpResponse(r, content_type='text/plain', status=c)
     
 rc = rc_factory()