Issue #30 resolved

rc properties create a shared instance of HttpResponse for each thread

Anonymous 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