Commits

Kristian Bendiksen  committed 1c1c6b8

Fixes for django 1.4 compatibility.

  • Participants
  • Parent commits d4bc0f8

Comments (0)

Files changed (2)

File piston/resource.py

         `Resource` subclass.
         """
         resp = rc.BAD_REQUEST
-        resp.write(' '+str(e.form.errors))
+        resp.write(u' '+unicode(e.form.errors))
         return resp
 
     @property
         # If we're looking at a response object which contains non-string
         # content, then assume we should use the emitter to format that 
         # content
-        if isinstance(result, HttpResponse) and not result._is_string:
+        if self._use_emitter(result):
             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 it True _container is the raw data
             result = result._container
      
         srl = emitter(result, typemapper, handler, fields, anonymous)
             return e.response
 
     @staticmethod
+    def _use_emitter(result):
+        """True iff result is a HttpResponse and contains non-string content."""
+        if not isinstance(result, HttpResponse):
+            return False
+        elif django.VERSION >= (1, 4):
+            return not result._base_content_is_iter
+        else:
+            return result._is_string
+
+
+    @staticmethod
     def cleanup_request(request):
         """
         Removes `oauth_` keys from various dicts on the

File piston/utils.py

                 if not isinstance(content, basestring) and hasattr(content, '__iter__'):
                     self._container = content
                     self._is_string = False
+                    self._base_content_iter = True
                 else:
                     self._container = [content]
                     self._is_string = True
+                    self._base_content_iter = False
 
             content = property(HttpResponse._get_content, _set_content)