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 ...@@ -35,24 +35,33 @@ from django.core import urlresolvers
from django.views.decorators import csrf from django.views.decorators import csrf
from django.conf.urls.defaults import patterns from django.conf.urls.defaults import patterns
def _patch_pattern(regex_pattern): 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. RegexURLPattern callback to get resolved if required.
""" """
if not regex_pattern._callback: if hasattr(regex_pattern, "_get_callback"): # Django==1.2
# enforce _callback resolving if not regex_pattern._callback:
regex_pattern._get_callback() # enforce _callback resolving
regex_pattern._get_callback()
regex_pattern._callback = \ regex_pattern._callback = \
csrf.csrf_exempt(regex_pattern._callback) csrf.csrf_exempt(regex_pattern._callback)
else:
regex_pattern._callback = \
csrf.csrf_exempt(regex_pattern.callback)
def _patch_resolver(r): def _patch_resolver(r):
""" """
Patch all patterns found in resolver with _patch_pattern 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() entries = r._get_url_patterns()
elif hasattr(r, 'url_patterns'):
entries = r.url_patterns
else: else:
# first level view in patterns ? # first level view in patterns ?
entries = [r] entries = [r]
...@@ -65,9 +74,10 @@ def _patch_resolver(r): ...@@ -65,9 +74,10 @@ def _patch_resolver(r):
else: else:
_patch_pattern(entry) _patch_pattern(entry)
def api_patterns(*args, **kwargs): def api_patterns(*args, **kwargs):
""" """
Protect all url patterns from csrf attacks. Protect all url patterns from csrf attacks.
""" """
_patterns = patterns(*args, **kwargs) _patterns = patterns(*args, **kwargs)
for entry in _patterns: 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