permanent_repo_url.py
41 lines
| 1.6 KiB
| text/x-python
|
PythonLexer
Mads Kiilerich
|
r7620 | # -*- coding: utf-8 -*- | ||
# This program is free software: you can redistribute it and/or modify | ||||
# it under the terms of the GNU General Public License as published by | ||||
# the Free Software Foundation, either version 3 of the License, or | ||||
# (at your option) any later version. | ||||
# | ||||
# This program is distributed in the hope that it will be useful, | ||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
# GNU General Public License for more details. | ||||
# | ||||
# You should have received a copy of the GNU General Public License | ||||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
""" | ||||
kallithea.lib.middleware.permanent_repo_url | ||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||||
middleware to handle permanent repo URLs, replacing PATH_INFO '/_123/yada' with | ||||
'/name/of/repo/yada' after looking 123 up in the database. | ||||
""" | ||||
Mads Kiilerich
|
r7909 | from kallithea.lib.utils import fix_repo_id_name | ||
Mads Kiilerich
|
r8078 | from kallithea.lib.utils2 import safe_bytes, safe_str | ||
Mads Kiilerich
|
r7620 | |||
class PermanentRepoUrl(object): | ||||
def __init__(self, app, config): | ||||
self.application = app | ||||
self.config = config | ||||
def __call__(self, environ, start_response): | ||||
Mads Kiilerich
|
r7948 | # Extract path_info as get_path_info does, but do it explicitly because | ||
# we also have to do the reverse operation when patching it back in | ||||
Mads Kiilerich
|
r8082 | path_info = safe_str(environ['PATH_INFO'].encode('latin1')) | ||
Mads Kiilerich
|
r7620 | if path_info.startswith('/'): # it must | ||
Mads Kiilerich
|
r7961 | path_info = '/' + fix_repo_id_name(path_info[1:]) | ||
Mads Kiilerich
|
r8082 | environ['PATH_INFO'] = safe_bytes(path_info).decode('latin1') | ||
Mads Kiilerich
|
r7620 | |||
return self.application(environ, start_response) | ||||