From 24eb06ab07e918d1f1a62e4be54c6cbb7252bec6 Mon Sep 17 00:00:00 2001 From: Max Goodman Date: Wed, 4 Sep 2013 14:31:01 -0700 Subject: [PATCH] See you later RewriteMiddleware. This appears to only have been be used for obsolete .js URL forms of widgets. --- r2/r2/config/middleware.py | 24 +++++------------------- r2/r2/config/rewrites.py | 32 -------------------------------- 2 files changed, 5 insertions(+), 51 deletions(-) delete mode 100644 r2/r2/config/rewrites.py diff --git a/r2/r2/config/middleware.py b/r2/r2/config/middleware.py index aa0085a97..1adde7a5b 100644 --- a/r2/r2/config/middleware.py +++ b/r2/r2/config/middleware.py @@ -38,7 +38,6 @@ from pylons.wsgiapp import PylonsApp from routes.middleware import RoutesMiddleware from r2.config.environment import load_environment -from r2.config.rewrites import rewrites from r2.config.extensions import extension_mapping, set_extension from r2.lib.utils import is_subdomain @@ -264,26 +263,14 @@ class ExtensionMiddleware(object): return self.app(environ, start_response) -class RewriteMiddleware(object): +class FullPathMiddleware(object): + # Debt: we have a lot of middleware which (unfortunately) modify the + # global URL PATH_INFO string. To work with the original request URL, we + # save it to a different location here. def __init__(self, app): self.app = app - def rewrite(self, regex, out_template, input): - m = regex.match(input) - out = out_template - if m: - for num, group in enumerate(m.groups('')): - out = out.replace('$%s' % (num + 1), group) - return out - def __call__(self, environ, start_response): - path = environ['PATH_INFO'] - for r in rewrites: - newpath = self.rewrite(r[0], r[1], path) - if newpath: - environ['PATH_INFO'] = newpath - break - environ['FULLPATH'] = environ.get('PATH_INFO') qs = environ.get('QUERY_STRING') if qs: @@ -468,8 +455,7 @@ def make_app(global_conf, full_stack=True, **app_conf): static_cascade.insert(0, plugin_static_apps) app = Cascade(static_cascade) - #add the rewrite rules - app = RewriteMiddleware(app) + app = FullPathMiddleware(app) if not g.config['uncompressedJS'] and g.config['debug']: static_fallback = StaticTestMiddleware(static_app, g.config['static_path'], g.config['static_domain']) diff --git a/r2/r2/config/rewrites.py b/r2/r2/config/rewrites.py deleted file mode 100644 index 2b3f3beb4..000000000 --- a/r2/r2/config/rewrites.py +++ /dev/null @@ -1,32 +0,0 @@ -# The contents of this file are subject to the Common Public Attribution -# License Version 1.0. (the "License"); you may not use this file except in -# compliance with the License. You may obtain a copy of the License at -# http://code.reddit.com/LICENSE. The License is based on the Mozilla Public -# License Version 1.1, but Sections 14 and 15 have been added to cover use of -# software over a computer network and provide for limited attribution for the -# Original Developer. In addition, Exhibit A has been modified to be consistent -# with Exhibit B. -# -# Software distributed under the License is distributed on an "AS IS" basis, -# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for -# the specific language governing rights and limitations under the License. -# -# The Original Code is reddit. -# -# The Original Developer is the Initial Developer. The Initial Developer of -# the Original Code is reddit Inc. -# -# All portions of the code written by reddit are Copyright (c) 2006-2013 reddit -# Inc. All Rights Reserved. -############################################################################### - -import re - -rewrites = (#these first two rules prevent the .embed rewrite from - #breaking other js that should work - ("\A/_(.*)", "/_$1"), - ("\A/static/(.*\.js)", "/static/$1"), - #This next rewrite makes it so that all the embed stuff works. - ("\A(.*)(?