<s> import re <EOL> from datetime import timedelta <EOL> from urlparse import urlparse <EOL> from functools import wraps <EOL> from django . core . cache import cache <EOL> from django . utils . importlib import import_module <EOL> from fandjango . settings import FACEBOOK_APPLICATION_CANVAS_URL <EOL> from fandjango . settings import FACEBOOK_APPLICATION_DOMAIN <EOL> from fandjango . settings import FACEBOOK_APPLICATION_NAMESPACE <EOL> from fandjango . settings import DISABLED_PATHS <EOL> from fandjango . settings import ENABLED_PATHS <EOL> from fandjango . settings import AUTHORIZATION_DENIED_VIEW <EOL> from fandjango . settings import FANDJANGO_SITE_URL <EOL> def is_disabled_path ( path ) : <EOL> """<STR_LIT>""" <EOL> for disabled_path in DISABLED_PATHS : <EOL> match = re . search ( disabled_path , path [ <NUM_LIT:1> : ] ) <EOL> if match : <EOL> return True <EOL> return False <EOL> def is_enabled_path ( path ) : <EOL> """<STR_LIT>""" <EOL> for enabled_path in ENABLED_PATHS : <EOL> match = re . search ( enabled_path , path [ <NUM_LIT:1> : ] ) <EOL> if match : <EOL> return True <EOL> return False <EOL> def cached_property ( ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> def decorator ( function ) : <EOL> @ wraps ( function ) <EOL> def wrapper ( self ) : <EOL> key = '<STR_LIT>' % { <EOL> '<STR_LIT>' : self . __class__ . __name__ , <EOL> '<STR_LIT>' : self . pk , <EOL> '<STR_LIT>' : function . __name__ <EOL> } <EOL> cached_value = cache . get ( key ) <EOL> delta = timedelta ( ** kwargs ) <EOL> if cached_value is None : <EOL> value = function ( self ) <EOL> cache . set ( key , value , delta . days * <NUM_LIT> + delta . seconds ) <EOL> else : <EOL> value = cached_value <EOL> return value <EOL> return wrapper <EOL> return decorator <EOL> def authorization_denied_view ( request ) : <EOL> """<STR_LIT>""" <EOL> authorization_denied_module_name = AUTHORIZATION_DENIED_VIEW . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] <EOL> authorization_denied_view_name = AUTHORIZATION_DENIED_VIEW . split ( '<STR_LIT:.>' ) [ - <NUM_LIT:1> ] <EOL> authorization_denied_module = import_module ( authorization_denied_module_name ) <EOL> authorization_denied_view = getattr ( authorization_denied_module , authorization_denied_view_name ) <EOL> return authorization_denied_view ( request ) <EOL> def get_post_authorization_redirect_url ( request , canvas = True ) : <EOL> """<STR_LIT>""" <EOL> path = request . get_full_path ( ) <EOL> if canvas : <EOL> if FACEBOOK_APPLICATION_CANVAS_URL : <EOL> path = path . replace ( urlparse ( FACEBOOK_APPLICATION_CANVAS_URL ) . path , '<STR_LIT>' ) <EOL> redirect_uri = '<STR_LIT>' % { <EOL> '<STR_LIT>' : FACEBOOK_APPLICATION_DOMAIN , <EOL> '<STR_LIT>' : FACEBOOK_APPLICATION_NAMESPACE , <EOL> '<STR_LIT:path>' : path <EOL> } <EOL> else : <EOL> if FANDJANGO_SITE_URL : <EOL> site_url = FANDJANGO_SITE_URL <EOL> path = path . replace ( urlparse ( site_url ) . path , '<STR_LIT>' ) <EOL> else : <EOL> protocol = "<STR_LIT>" if request . is_secure ( ) else "<STR_LIT:http>" <EOL> site_url = "<STR_LIT>" % ( protocol , request . get_host ( ) ) <EOL> redirect_uri = site_url + path <EOL> return redirect_uri <EOL> def get_full_path ( request , remove_querystrings = [ ] ) : <EOL> """<STR_LIT>""" <EOL> path = request . get_full_path ( ) <EOL> for qs in remove_querystrings : <EOL> path = re . sub ( r'<STR_LIT>' + qs + '<STR_LIT>' , '<STR_LIT>' , path ) <EOL> return path </s>
