Issue #30 resolved

rc properties create a shared instance of HttpResponse for each thread

Anonymous avatarAnonymous created an issue

I've provided a backwards-incompatible solution (rc.CREATED() instead of rc.CREATED):

diff -r 23ebc37c78e8 piston/utils.py
--- a/piston/utils.py   Thu Apr 30 11:06:19 2009 +0200
+++ b/piston/utils.py   Fri May 08 11:38:03 2009 -0400
@@ -23,15 +23,41 @@
     """
     Status codes.
     """
-    ALL_OK = create_reply('OK', status=200)
-    CREATED = create_reply('Created', status=201)
-    DELETED = create_reply('', status=204) # 204 says "Don't send a body!"
-    BAD_REQUEST = create_reply('Bad Request', status=400)
-    FORBIDDEN = create_reply('Forbidden', status=401)
-    DUPLICATE_ENTRY = create_reply('Conflict/Duplicate', status=409)
-    NOT_HERE = create_reply('Gone', status=410)
-    NOT_IMPLEMENTED = create_reply('Not Implemented', status=501)
-    THROTTLED = create_reply('Throttled', status=503)
+    @staticmethod
+    def ALL_OK():
+        return create_reply('OK', status=200)
+
+    @staticmethod
+    def CREATED():
+        return create_reply('Created', status=201)
+
+    @staticmethod
+    def DELETED():
+        return create_reply('', status=204)
+
+    @staticmethod
+    def BAD_REQUEST():
+        return create_reply('Bad Request', status=400)
+
+    @staticmethod
+    def FORBIDDEN():
+        return create_reply('Forbidden', status=401)
+
+    @staticmethod
+    def DUPLICATE_ENTRY():
+        return create_reply('Conflict/Duplicate', status=409)
+
+    @staticmethod
+    def NOT_HERE():
+        return create_reply('Gone', status=410)
+
+    @staticmethod
+    def NOT_IMPLEMENTED():
+        return create_reply('Not Implemented', status=501)
+
+    @staticmethod
+    def THROTTLED():
+        return create_reply('Not Implemented', status=501)

 class FormValidationError(Exception):
     def __init__(self, form):

This allows you to do things like:

out = rc.CREATED()
out.write(simplejson.dumps({'success': True, 'id' 1}))
return out

in your handler methods.

Comments (5)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.