<s> import inspect <EOL> from functools import wraps <EOL> from django . http import * <EOL> import re <EOL> import sys <EOL> from django . utils . safestring import SafeUnicode <EOL> import warnings <EOL> from django_url_framework . helper import ApplicationHelper <EOL> from django . utils . translation import ugettext as _ <EOL> from django . conf . urls import url , include <EOL> from django import VERSION <EOL> if VERSION [ <NUM_LIT:1> ] < <NUM_LIT:9> : <EOL> from django . conf . urls import patterns <EOL> from django_url_framework . exceptions import InvalidActionError <EOL> from django_url_framework . exceptions import InvalidControllerError <EOL> def get_controller_name ( controller_class , with_prefix = True ) : <EOL> controller_name = getattr ( controller_class , '<STR_LIT>' , None ) <EOL> if controller_name is None : <EOL> name_ = [ controller_class . __name__ [ <NUM_LIT:0> ] ] <EOL> prev = '<STR_LIT>' <EOL> for l in re . sub ( r"<STR_LIT>" , '<STR_LIT>' , controller_class . __name__ [ <NUM_LIT:1> : ] ) : <EOL> if l . isupper ( ) and prev . islower ( ) : <EOL> name_ . append ( '<STR_LIT:_>' + l ) <EOL> else : <EOL> name_ . append ( l ) <EOL> prev = l <EOL> controller_name = '<STR_LIT>' . join ( name_ ) . lower ( ) <EOL> controller_prefix = getattr ( controller_class , '<STR_LIT>' , None ) <EOL> if with_prefix and controller_prefix not in ( None , '<STR_LIT>' ) : <EOL> controller_name = controller_class . controller_prefix + controller_name <EOL> return controller_name <EOL> def autoview_function ( site , request , controller_name , controller_class , action_name = '<STR_LIT:index>' , * args , ** kwargs ) : <EOL> error_msg = None <EOL> try : <EOL> if action_name in get_actions ( controller_class ) : <EOL> helper = ApplicationHelper <EOL> kwargs_all = kwargs . copy ( ) <EOL> if hasattr ( controller_class , '<STR_LIT>' ) : <EOL> if type ( controller_class . consume_urlconf_keyword_arguments ) not in ( list , tuple ) : <EOL> controller_class . consume_urlconf_keyword_arguments = [ ] <EOL> for kwarg in controller_class . consume_urlconf_keyword_arguments : <EOL> if kwarg in kwargs : <EOL> del ( kwargs [ kwarg ] ) <EOL> return controller_class ( site , request , helper , url_params = kwargs_all ) . _call_action ( action_name , * args , ** kwargs ) <EOL> else : <EOL> raise InvalidActionError ( action_name ) <EOL> except InvalidActionError , e : <EOL> error_msg = _ ( "<STR_LIT>" ) % { '<STR_LIT>' : e . message , '<STR_LIT>' : controller_name } <EOL> raise Http404 ( error_msg ) <EOL> def _get_arg_name_and_default ( action_func ) : <EOL> arg_spec = inspect . getargspec ( action_func ) <EOL> arguments = arg_spec . args <EOL> has_default = True <EOL> if len ( arguments ) == <NUM_LIT:3> : <EOL> has_default = arg_spec . defaults and len ( arg_spec . defaults ) > <NUM_LIT:0> <EOL> return arguments [ <NUM_LIT:2> ] , has_default <EOL> return None , has_default <EOL> def _patterns ( * args ) : <EOL> if VERSION [ <NUM_LIT:1> ] >= <NUM_LIT:9> : <EOL> return list ( args ) <EOL> else : <EOL> from django . conf . urls import patterns <EOL> return patterns ( '<STR_LIT>' , * args ) <EOL> def get_controller_urlconf ( controller_class , site = None ) : <EOL> controller_name = get_controller_name ( controller_class ) <EOL> actions = get_actions ( controller_class ) <EOL> urlpatterns = _patterns ( ) <EOL> urlpatterns_with_args = _patterns ( ) <EOL> def wrap_call ( _controller_name , _action_name , _action_func ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( * args , ** kwargs ) : <EOL> request , args = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> : ] <EOL> return autoview_function ( site , request , _controller_name , controller_class , _action_name , * args , ** kwargs ) <EOL> return wraps ( _action_func ) ( wrapper ) <EOL> for action_name , action_func in actions . items ( ) : <EOL> named_url = '<STR_LIT>' % ( get_controller_name ( controller_class , with_prefix = False ) , get_action_name ( action_func ) ) <EOL> named_url = getattr ( action_func , '<STR_LIT>' , named_url ) <EOL> replace_dict = { '<STR_LIT:action>' : action_name . replace ( "<STR_LIT>" , "<STR_LIT:/>" ) } <EOL> wrapped_call = wrap_call ( controller_name , action_name , action_func ) <EOL> urlconf_prefix = getattr ( controller_class , '<STR_LIT>' , None ) <EOL> action_urlpatterns = _patterns ( ) <EOL> index_action_with_args_urlconf = _patterns ( ) <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> """<STR_LIT>""" <EOL> for new_urlconf in action_func . urlconf : <EOL> action_urlpatterns += _patterns ( url ( new_urlconf , wrapped_call , name = named_url ) ) <EOL> if getattr ( action_func , '<STR_LIT>' , False ) == False : <EOL> """<STR_LIT>""" <EOL> if action_name == '<STR_LIT:index>' : <EOL> object_id_arg_name , has_default = _get_arg_name_and_default ( action_func ) <EOL> if object_id_arg_name is not None : <EOL> replace_dict [ '<STR_LIT>' ] = object_id_arg_name <EOL> index_action_with_args_urlconf += _patterns ( url ( r'<STR_LIT>' % replace_dict , wrapped_call , name = named_url ) ) <EOL> if has_default : <EOL> action_urlpatterns += _patterns ( url ( r'<STR_LIT>' , wrapped_call , name = named_url ) ) <EOL> else : <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> arguments = action_func . url_parameters <EOL> replace_dict [ '<STR_LIT>' ] = arguments <EOL> action_urlpatterns += _patterns ( url ( r'<STR_LIT>' % replace_dict , wrapped_call , name = named_url ) ) <EOL> else : <EOL> object_id_arg_name , has_default = _get_arg_name_and_default ( action_func ) <EOL> if object_id_arg_name is not None : <EOL> replace_dict [ '<STR_LIT>' ] = object_id_arg_name <EOL> action_urlpatterns += _patterns ( url ( r'<STR_LIT>' % replace_dict , wrapped_call , name = named_url ) ) <EOL> if has_default : <EOL> action_urlpatterns += _patterns ( url ( r'<STR_LIT>' % replace_dict , wrapped_call , name = named_url ) ) <EOL> if urlconf_prefix : <EOL> action_urlpatterns_with_prefix = _patterns ( ) <EOL> for _urlconf in urlconf_prefix : <EOL> action_urlpatterns_with_prefix += _patterns ( url ( _urlconf , include ( action_urlpatterns ) ) ) <EOL> urlpatterns += action_urlpatterns_with_prefix <EOL> action_urlpatterns_with_args_with_prefix = _patterns ( ) <EOL> for _urlconf in urlconf_prefix : <EOL> action_urlpatterns_with_args_with_prefix += _patterns ( url ( _urlconf , include ( action_urlpatterns_with_args_with_prefix ) ) ) <EOL> urlpatterns_with_args += action_urlpatterns_with_args_with_prefix <EOL> else : <EOL> urlpatterns += action_urlpatterns <EOL> urlpatterns_with_args += index_action_with_args_urlconf <EOL> return urlpatterns + urlpatterns_with_args <EOL> CACHED_ACTIONS = { } <EOL> def get_action_name ( func , with_prefix = False ) : <EOL> if callable ( func ) : <EOL> func_name = func . func_name <EOL> if not re . match ( r'<STR_LIT>' , func_name [ <NUM_LIT:0> ] ) : <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> func_name = func . action_name <EOL> if with_prefix and hasattr ( func , '<STR_LIT>' ) : <EOL> func_name = func . action_prefix + func_name <EOL> return func_name <EOL> raise InvalidActionError ( func . func_name ) <EOL> def get_actions ( controller , with_prefix = True ) : <EOL> if isinstance ( controller , ActionController ) : <EOL> controller_cache_key = controller . __class__ . __name__ + str ( with_prefix ) <EOL> controller = controller . __class__ <EOL> else : <EOL> controller_cache_key = controller . __name__ + str ( with_prefix ) <EOL> if controller_cache_key not in CACHED_ACTIONS : <EOL> actions = { } <EOL> for func_name in dir ( controller ) : <EOL> func = getattr ( controller , func_name ) <EOL> if not re . match ( r'<STR_LIT>' , func_name [ <NUM_LIT:0> ] ) and callable ( func ) : <EOL> if hasattr ( func , '<STR_LIT>' ) : <EOL> func_name = func . action_name <EOL> if with_prefix and hasattr ( func , '<STR_LIT>' ) : <EOL> func_name = func . action_prefix + func_name <EOL> actions [ func_name ] = func <EOL> CACHED_ACTIONS [ controller_cache_key ] = actions <EOL> return CACHED_ACTIONS [ controller_cache_key ] <EOL> def get_action_wrapper ( site , controller_class , action_name ) : <EOL> """<STR_LIT>""" <EOL> controller_name = get_controller_name ( controller_class ) <EOL> actions = get_actions ( controller_class ) <EOL> def wrap_call ( controller_name , action_name , action_func ) : <EOL> """<STR_LIT>""" <EOL> def wrapper ( * args , ** kwargs ) : <EOL> request , args = args [ <NUM_LIT:0> ] , args [ <NUM_LIT:1> : ] <EOL> return autoview_function ( site , request , controller_name , controller_class , action_name , * args , ** kwargs ) <EOL> return wraps ( action_func ) ( wrapper ) <EOL> if action_name in actions : <EOL> wrapped_call = wrap_call ( controller_name , action_name , actions [ action_name ] ) <EOL> return wrapped_call <EOL> else : <EOL> raise InvalidActionError ( action_name ) <EOL> class ActionController ( object ) : <EOL> """<STR_LIT>""" <EOL> template_extension = "<STR_LIT:html>" <EOL> template_prefix = None <EOL> no_subdirectories = False <EOL> no_ajax_prefix = False <EOL> controller_prefix = None <EOL> controller_name = None <EOL> consume_urlconf_keyword_arguments = None <EOL> urlconf_prefix = None <EOL> def __init__ ( self , site , request , helper_class , url_params ) : <EOL> self . _site = site <EOL> self . _helper = helper_class ( self ) <EOL> self . _request = request <EOL> self . _response = HttpResponse ( ) <EOL> self . _action_name = None <EOL> self . _action_name_sans_prefix = None <EOL> self . _action_func = None <EOL> self . _controller_name = get_controller_name ( self . __class__ ) <EOL> self . _controller_name_sans_prefix = get_controller_name ( self . __class__ , with_prefix = False ) <EOL> self . _flash_cache = None <EOL> self . _template_context = { } <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> self . _no_ajax_prefix = getattr ( self , '<STR_LIT>' , False ) <EOL> else : <EOL> self . _no_ajax_prefix = getattr ( self , '<STR_LIT>' , False ) <EOL> self . _is_ajax = request . is_ajax ( ) <EOL> self . _url_params = url_params <EOL> self . _template_extension = getattr ( self , '<STR_LIT>' , '<STR_LIT:html>' ) <EOL> if getattr ( self , '<STR_LIT>' ) is not None : <EOL> self . _template_prefix = getattr ( self , '<STR_LIT>' ) <EOL> else : <EOL> self . _template_prefix = self . _controller_name_sans_prefix <EOL> if getattr ( self , '<STR_LIT>' , False ) : <EOL> self . _template_string = "<STR_LIT>" <EOL> self . _ajax_template_string = "<STR_LIT>" <EOL> else : <EOL> self . _template_string = "<STR_LIT>" <EOL> self . _ajax_template_string = "<STR_LIT>" <EOL> self . _actions = get_actions ( self , with_prefix = True ) <EOL> self . _actions_by_name = get_actions ( self , with_prefix = False ) <EOL> def _get_params ( self , all_params = False ) : <EOL> if self . _request . method == "<STR_LIT:POST>" : <EOL> return self . _request . POST <EOL> else : <EOL> return self . _request . REQUEST <EOL> _params = property ( _get_params ) <EOL> def _call_action ( self , action_name , * args , ** kwargs ) : <EOL> if action_name in self . _actions : <EOL> action_func = self . _actions [ action_name ] <EOL> action_func = getattr ( self , action_func . func_name ) <EOL> return self . _view_wrapper ( action_func , * args , ** kwargs ) <EOL> else : <EOL> raise InvalidActionError ( action_name ) <EOL> def _has_action ( self , action_name , with_prefix = False ) : <EOL> return ( action_name in get_actions ( action_name , with_prefix = with_prefix ) ) <EOL> def _get_action_name ( self , action_func , with_prefix = True ) : <EOL> if not re . match ( r'<STR_LIT>' , action_func . func_name [ <NUM_LIT:0> ] ) and callable ( action_func ) : <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> func_name = action_func . action_name <EOL> else : <EOL> func_name = action_func . func_name <EOL> if with_prefix and hasattr ( action_func , '<STR_LIT>' ) : <EOL> func_name = action_func . action_prefix + func_name <EOL> return func_name <EOL> raise InvalidActionError ( action_func . func_name ) <EOL> def _view_wrapper ( self , action_func , * args , ** kwargs ) : <EOL> self . _action_name = self . _get_action_name ( action_func ) <EOL> self . _action_func = action_func <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> warnings . warn ( "<STR_LIT>" , DeprecationWarning ) <EOL> self . _no_ajax_prefix = self . _no_ajax_prefix or getattr ( action_func , '<STR_LIT>' , False ) <EOL> else : <EOL> self . _no_ajax_prefix = self . _no_ajax_prefix or getattr ( action_func , '<STR_LIT>' , False ) <EOL> self . _action_name_sans_prefix = self . _get_action_name ( action_func , with_prefix = False ) <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> if type ( action_func . allowed_methods ) not in ( list , tuple ) : <EOL> allowed_methods = [ action_func . allowed_methods . upper ( ) ] <EOL> else : <EOL> allowed_methods = [ i . upper ( ) for i in action_func . allowed_methods ] <EOL> if self . _request . method . upper ( ) not in allowed_methods : <EOL> return HttpResponseNotAllowed ( allowed_methods ) <EOL> send_args = { } <EOL> if hasattr ( action_func , '<STR_LIT>' ) : <EOL> send_args [ '<STR_LIT>' ] = action_func . mimetype <EOL> try : <EOL> response = self . __wrap_before_filter ( action_func , * args , ** kwargs ) <EOL> if type ( response ) is dict : <EOL> return self . __wrap_after_filter ( self . __wrapped_render , response , ** send_args ) <EOL> elif type ( response ) in ( str , unicode , SafeUnicode ) : <EOL> return self . __wrap_after_filter ( self . __wrapped_print , response , ** send_args ) <EOL> else : <EOL> return response <EOL> except Exception , exception : <EOL> response = self . _on_exception ( request = self . _request , exception = exception ) <EOL> if response is None : <EOL> raise exception , None , sys . exc_info ( ) [ - <NUM_LIT:1> ] <EOL> else : <EOL> if type ( response ) is dict : <EOL> return self . __wrapped_render ( dictionary = response , template_name = self . _get_error_template_path ( ) ) <EOL> elif type ( response ) in ( str , unicode , SafeUnicode ) : <EOL> return self . __wrapped_print ( text = response , ** send_args ) <EOL> else : <EOL> return response <EOL> def __wrap_before_filter ( self , wrapped_func , * args , ** kwargs ) : <EOL> if getattr ( self , '<STR_LIT>' , False ) == False and getattr ( self . _action_func , '<STR_LIT>' , False ) == False : <EOL> self . _before_filter_runonce = True <EOL> if self . _before_filter . func_code . co_argcount >= <NUM_LIT:2> : <EOL> filter_response = self . _before_filter ( self . _request ) <EOL> else : <EOL> filter_response = self . _before_filter ( ) <EOL> if type ( filter_response ) is dict : <EOL> self . _template_context . update ( filter_response ) <EOL> elif filter_response is not None : <EOL> return filter_response <EOL> if hasattr ( self , '<STR_LIT>' ) : <EOL> action_response = wrapped_func ( * args , ** kwargs ) <EOL> else : <EOL> action_response = wrapped_func ( self . _request , * args , ** kwargs ) <EOL> if type ( action_response ) is dict : <EOL> self . _template_context . update ( action_response ) <EOL> return self . _template_context <EOL> return action_response <EOL> def __wrap_after_filter ( self , wrapped_func , * args , ** kwargs ) : <EOL> if getattr ( self , '<STR_LIT>' , False ) == False and getattr ( self . _action_func , '<STR_LIT>' , False ) == False : <EOL> self . _after_filter_runonce = True <EOL> if self . _after_filter . func_code . co_argcount >= <NUM_LIT:2> : <EOL> filter_response = self . _after_filter ( request = self . _request ) <EOL> else : <EOL> filter_response = self . _after_filter ( ) <EOL> if type ( filter_response ) is dict : <EOL> self . _template_context . update ( filter_response ) <EOL> elif filter_response is not None : <EOL> return filter_response <EOL> return wrapped_func ( * args , ** kwargs ) <EOL> def _before_filter ( self , request ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def _after_filter ( self , request ) : <EOL> return None <EOL> def _before_render ( self , request = None ) : <EOL> return None <EOL> def _on_exception ( self , request , exception ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def _set_cookie ( self , * args , ** kwargs ) : <EOL> self . _response . set_cookie ( * args , ** kwargs ) <EOL> def _delete_cookie ( self , * args , ** kwargs ) : <EOL> self . _response . delete_cookie ( * args , ** kwargs ) <EOL> def _set_mimetype ( self , mimetype , charset = None ) : <EOL> if mimetype is not None : <EOL> if charset is None : <EOL> charset = self . _response . _charset <EOL> self . _response [ '<STR_LIT>' ] = "<STR_LIT>" % ( mimetype , charset ) <EOL> def _as_json ( self , data , status_code = <NUM_LIT:200> , default = None , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import json <EOL> if self . _is_ajax and '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT:application/json>' <EOL> self . _template_context = data <EOL> response = self . __wrap_after_filter ( json . dumps , self . _template_context , default = default ) <EOL> if type ( response ) in ( str , unicode , SafeUnicode ) : <EOL> return self . __wrapped_print ( response , status_code = status_code , * args , ** kwargs ) <EOL> else : <EOL> return response <EOL> def _as_yaml ( self , data , default_flow_style = True , status_code = <NUM_LIT:200> , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> import yaml <EOL> if self . _is_ajax and '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' ; <EOL> return self . _print ( yaml . dump ( data , default_flow_style = default_flow_style ) , status_code = status_code , * args , ** kwargs ) <EOL> def __wrapped_print ( self , text , mimetype = '<STR_LIT>' , charset = None , status_code = <NUM_LIT:200> ) : <EOL> """<STR_LIT>""" <EOL> self . _before_render ( ) <EOL> self . _set_mimetype ( mimetype , charset ) <EOL> if self . _response . status_code == <NUM_LIT:200> : <EOL> self . _response . status_code = status_code <EOL> self . _response . content = text <EOL> return self . _response <EOL> def _print ( self , text , mimetype = '<STR_LIT>' , charset = None ) : <EOL> return self . __wrap_after_filter ( self . __wrapped_print , text = text , mimetype = mimetype , charset = charset ) <EOL> def _get_flash ( self ) : <EOL> if self . _flash_cache is None : <EOL> from django_url_framework . flash import FlashManager <EOL> self . _flash_cache = FlashManager ( self . _request ) <EOL> return self . _flash_cache <EOL> _flash = property ( _get_flash ) <EOL> def _get_error_template_path ( self ) : <EOL> """<STR_LIT>""" <EOL> template_name = None <EOL> if self . _is_ajax and self . _no_ajax_prefix == False and hasattr ( self . _on_exception , '<STR_LIT>' ) : <EOL> template_name = self . _on_exception . ajax_template_name <EOL> elif hasattr ( self . _on_exception , '<STR_LIT>' ) : <EOL> template_name = self . _on_exception . template_name <EOL> if template_name is None : <EOL> if getattr ( self . _on_exception , '<STR_LIT>' , False ) == False : <EOL> if self . _is_ajax and self . _no_ajax_prefix == False : <EOL> template_name = "<STR_LIT>" <EOL> else : <EOL> template_name = "<STR_LIT>" <EOL> else : <EOL> template_name_data = { '<STR_LIT>' : self . _template_prefix , <EOL> '<STR_LIT:action>' : self . _action_name + "<STR_LIT>" , <EOL> '<STR_LIT>' : self . _template_extension } <EOL> if self . _is_ajax and self . _no_ajax_prefix == False : <EOL> template_name = self . _ajax_template_string % template_name_data <EOL> else : <EOL> template_name = self . _template_string % template_name_data <EOL> return template_name <EOL> def __wrapped_render ( self , dictionary = { } , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> from django . template import loader <EOL> from django . template . context import RequestContext <EOL> dictionary . update ( { <EOL> '<STR_LIT>' : self . _request , <EOL> '<STR_LIT>' : self . _controller_name , <EOL> '<STR_LIT>' : self . _actions . keys ( ) , <EOL> '<STR_LIT>' : self . _action_name , <EOL> '<STR_LIT>' : self . _helper , <EOL> '<STR_LIT>' : self . _flash , <EOL> } ) <EOL> mimetype = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if mimetype : <EOL> self . _response [ '<STR_LIT>' ] = ( '<STR_LIT:Content-Type>' , mimetype ) <EOL> if '<STR_LIT>' not in kwargs : <EOL> template_replacement_data = { '<STR_LIT>' : self . _template_prefix , <EOL> '<STR_LIT:action>' : self . _action_name , <EOL> '<STR_LIT>' : self . _template_extension } <EOL> if self . _is_ajax and self . _no_ajax_prefix == False : <EOL> if hasattr ( self . _action_func , '<STR_LIT>' ) : <EOL> template_name = self . _action_func . ajax_template_name <EOL> else : <EOL> template_name = self . _ajax_template_string % template_replacement_data <EOL> elif hasattr ( self . _action_func , '<STR_LIT>' ) : <EOL> template_name = self . _action_func . template_name <EOL> else : <EOL> template_name = self . _template_string % template_replacement_data <EOL> kwargs [ '<STR_LIT>' ] = template_name <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = RequestContext ( self . _request ) <EOL> self . _template_context . update ( dictionary ) <EOL> if getattr ( self , '<STR_LIT>' , False ) == False and getattr ( self . _action_func , '<STR_LIT>' , False ) == False : <EOL> self . _before_render_runonce = True <EOL> before_render_response = self . _before_render ( ) <EOL> if type ( before_render_response ) is dict : <EOL> self . _template_context . update ( before_render_response ) <EOL> elif before_render_response is not None : <EOL> return before_render_response <EOL> self . _response . content = loader . render_to_string ( dictionary = self . _template_context , * args , ** kwargs ) <EOL> return self . _response <EOL> _render = __wrapped_render <EOL> def __wrapped_redirect ( self , to_url , * args , ** kwargs ) : <EOL> if to_url is None : <EOL> to_url = self . _helper . url_for ( * args , ** kwargs ) <EOL> return HttpResponseRedirect ( to_url ) <EOL> def __wrapped_permanent_redirect ( self , to_url , * args , ** kwargs ) : <EOL> if to_url is None : <EOL> to_url = self . _helper . url_for ( * args , ** kwargs ) <EOL> return HttpResponsePermanentRedirect ( to_url ) <EOL> def _redirect ( self , to_url = None , * args , ** kwargs ) : <EOL> return self . __wrap_after_filter ( self . __wrapped_redirect , to_url , * args , ** kwargs ) <EOL> _go = _redirect <EOL> def _permanent_redirect ( self , to_url , * args , ** kwargs ) : <EOL> return self . __wrap_after_filter ( self . __wrapped_permanent_redirect , to_url , * args , ** kwargs ) </s>
