<s> from django . utils import simplejson <EOL> from django import http <EOL> from django . conf . urls . defaults import patterns <EOL> from django . conf import settings <EOL> from django . core import urlresolvers <EOL> import sys <EOL> from gitology . config import settings as gsettings <EOL> from gitology . d . views import show_post , show_wiki <EOL> from gitology import utils <EOL> class URLConfMiddleware : <EOL> def __init__ ( self ) : <EOL> self . cache_path = gsettings . LOCAL_REPO_PATH . joinpath ( "<STR_LIT>" ) <EOL> self . old_urlconf = utils . path2obj ( settings . ROOT_URLCONF + "<STR_LIT>" ) <EOL> self . handler500 = utils . path2obj ( settings . ROOT_URLCONF + "<STR_LIT>" ) <EOL> self . handler404 = utils . path2obj ( settings . ROOT_URLCONF + "<STR_LIT>" ) <EOL> def _check_if_urlconf_valid ( self ) : <EOL> if not hasattr ( self , '<STR_LIT>' ) : <EOL> return False <EOL> if self . cache_path . getmtime ( ) != self . cache_path_mtime : <EOL> return False <EOL> return True <EOL> def _load_urlconf ( self ) : <EOL> self . urlpatterns = self . old_urlconf + patterns ( <EOL> * utils . refresh_urlconf_cache ( ) <EOL> ) <EOL> self . cache_path_mtime = self . cache_path . getmtime ( ) <EOL> sys . modules [ "<STR_LIT>" ] = self <EOL> def check_urlconf ( self ) : <EOL> if not self . _check_if_urlconf_valid ( ) : <EOL> self . _load_urlconf ( ) <EOL> def process_request ( self , request ) : <EOL> self . check_urlconf ( ) <EOL> request . urlconf = "<STR_LIT>" <EOL> def process_response ( self , request , response ) : <EOL> if response . status_code != <NUM_LIT> : return response <EOL> if request . path in utils . global_blog_dict : <EOL> return show_post ( request ) <EOL> if request . path in utils . global_wiki_dict : <EOL> try : return show_wiki ( request ) <EOL> except http . Http404 : return response <EOL> if request . path in utils . global_redirect_dict : <EOL> return http . HttpResponsePermanentRedirect ( <EOL> utils . global_redirect_dict [ request . path ] <EOL> ) <EOL> if not request . path . endswith ( "<STR_LIT:/>" ) : <EOL> if "<STR_LIT>" % request . path in utils . global_blog_dict : <EOL> return http . HttpResponsePermanentRedirect ( request . path + "<STR_LIT:/>" ) <EOL> elif "<STR_LIT:.>" not in request . path . rsplit ( "<STR_LIT:/>" , <NUM_LIT:1> ) [ - <NUM_LIT:1> ] : <EOL> try : <EOL> urlresolvers . resolve ( <EOL> request . path_info <EOL> ) <EOL> except urlresolvers . Resolver404 : <EOL> return http . HttpResponseRedirect ( request . path + "<STR_LIT:/>" ) <EOL> else : <EOL> return http . HttpResponsePermanentRedirect ( <EOL> request . path + "<STR_LIT:/>" <EOL> ) <EOL> return response </s>
