~ubuntu-branches/ubuntu/saucy/edubuntu-server/saucy-proposed

« back to all changes in this revision

Viewing changes to manager/libs/common.py

  • Committer: Package Import Robot
  • Author(s): Stéphane Graber
  • Date: 2013-08-27 16:20:40 UTC
  • Revision ID: package-import@ubuntu.com-20130827162040-91ku1e00b1syaz8p
Tags: 13.08.1
Initial release

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
 
 
3
# Copyright (C) 2012-2013 Stéphane Graber
 
4
# Author: Stéphane Graber <stgraber@ubuntu.com>
 
5
 
 
6
# This program is free software; you can redistribute it and/or modify
 
7
# it under the terms of the GNU General Public License as published by
 
8
# the Free Software Foundation; either version 2 of the License, or
 
9
# (at your option) any later version.
 
10
#
 
11
# This program is distributed in the hope that it will be useful,
 
12
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
# GNU General Public License for more details.
 
15
#
 
16
# You can find the license on Debian systems in the file
 
17
# /usr/share/common-licenses/GPL-2
 
18
 
 
19
from flask import url_for
 
20
from werkzeug.urls import uri_to_iri
 
21
 
 
22
 
 
23
class ReverseProxied(object):
 
24
    def __init__(self, app, prefix):
 
25
        self.app = app
 
26
        if prefix[0] != "/":
 
27
            self.prefix = "/%s" % prefix
 
28
        else:
 
29
            self.prefix = prefix
 
30
 
 
31
    def __call__(self, environ, start_response):
 
32
        script_name = self.prefix
 
33
        environ['SCRIPT_NAME'] = script_name
 
34
        path_info = environ['PATH_INFO']
 
35
        if path_info.startswith(script_name):
 
36
            environ['PATH_INFO'] = path_info[len(script_name):]
 
37
 
 
38
        return self.app(environ, start_response)
 
39
 
 
40
 
 
41
def iri_for(endpoint, **values):
 
42
    """
 
43
        Wrapper to url_for for utf-8 URLs.
 
44
    """
 
45
    return uri_to_iri(url_for(endpoint, **values))