@@ -0,0 +1,1627 @@
+import re%0D%0Aimport itertools%0D%0A%0D%0A_HTML_TYPES = ('text/html', 'application/xhtml+xml')    %0D%0A%0D%0A_SUPPORTED_TRANSFORMS = %5B'PUT', 'DELETE'%5D%0D%0A%0D%0A_FORM_RE = re.compile(r'((%3Cform%5CW%5B%5E%3E%5D*%5Cbmethod=(%5C'%7C%22%7C))(%25s)((%5C'%7C%22%7C)%5Cb%5B%5E%3E%5D*%3E))'%0D%0A        %25 '%7C'.join(_SUPPORTED_TRANSFORMS), re.IGNORECASE)%0D%0A%0D%0A_MIDDLEWARE_KEY = '_method'%0D%0A %0D%0Aclass HttpMethodsMiddleware(object):%0D%0A    def process_request(self, request):%0D%0A        if request.POST and request.POST.has_key(_MIDDLEWARE_KEY):%0D%0A            if request.POST%5B_MIDDLEWARE_KEY%5D.upper() in _SUPPORTED_TRANSFORMS:%0D%0A                request.method = request.POST%5B_MIDDLEWARE_KEY%5D.upper()%0D%0A        return None%0D%0A           %0D%0A    def process_response(self, request, response):%0D%0A        if response%5B'Content-Type'%5D.split(';')%5B0%5D in _HTML_TYPES:%0D%0A            # ensure we don't add the 'id' attribute twice (HTML validity)%0D%0A            idattributes = itertools.chain((%22id='%22 + _MIDDLEWARE_KEY + %22'%22,), %0D%0A                                            itertools.repeat(''))%0D%0A            def add_transform_field(match):%0D%0A                %22%22%22Returns the matched %3Cform%3E tag with a modified method and%0D%0A                the added %3Cinput%3E element%22%22%22%0D%0A                return match.group(2) + %22POST%22 + match.group(5) + %5C%0D%0A                %22%3Cdiv style='display:none;'%3E%22 + %5C%0D%0A                %22%3Cinput type='hidden' %22 + idattributes.next() + %5C%0D%0A                %22 name='%22 + _MIDDLEWARE_KEY + %22' value='%22 + %5C%0D%0A                match.group(4).upper() + %22' /%3E%3C/div%3E%22%0D%0A%0D%0A            # Modify any POST forms%0D%0A            response.content = _FORM_RE.sub(add_transform_field,%0D%0A                    response.content)%0D%0A        return response%0D%0A

Add middleware to use all HTTP verbs in forms.