Commit 934feea8 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

wheezy: fix _patch_resolve to comply with Django

Class RegexURLPattern doesn't contain `_get_callback' method any more
and resolve the callback when we try to retrieve it.
parent e4a6a01b
......@@ -35,24 +35,33 @@ from django.core import urlresolvers
from django.views.decorators import csrf
from django.conf.urls.defaults import patterns
def _patch_pattern(regex_pattern):
"""
Patch pattern callback using csrf_exempt. Enforce
Patch pattern callback using csrf_exempt. Enforce
RegexURLPattern callback to get resolved if required.
"""
if not regex_pattern._callback:
# enforce _callback resolving
regex_pattern._get_callback()
if hasattr(regex_pattern, "_get_callback"): # Django==1.2
if not regex_pattern._callback:
# enforce _callback resolving
regex_pattern._get_callback()
regex_pattern._callback = \
regex_pattern._callback = \
csrf.csrf_exempt(regex_pattern._callback)
else:
regex_pattern._callback = \
csrf.csrf_exempt(regex_pattern.callback)
def _patch_resolver(r):
"""
Patch all patterns found in resolver with _patch_pattern
"""
if hasattr(r, '_get_url_patterns'):
if hasattr(r, '_get_url_patterns'): # Django ==1.2
entries = r._get_url_patterns()
elif hasattr(r, 'url_patterns'):
entries = r.url_patterns
else:
# first level view in patterns ?
entries = [r]
......@@ -65,9 +74,10 @@ def _patch_resolver(r):
else:
_patch_pattern(entry)
def api_patterns(*args, **kwargs):
"""
Protect all url patterns from csrf attacks.
Protect all url patterns from csrf attacks.
"""
_patterns = patterns(*args, **kwargs)
for entry in _patterns:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment