This file is indexed.

/usr/share/pyshared/gluon/http.py is in python-gluon 1.99.7-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""
This file is part of the web2py Web Framework
Copyrighted by Massimo Di Pierro <mdipierro@cs.depaul.edu>
License: LGPLv3 (http://www.gnu.org/licenses/lgpl.html)
"""

__all__ = ['HTTP', 'redirect']

defined_status = {
    200: 'OK',
    201: 'CREATED',
    202: 'ACCEPTED',
    203: 'NON-AUTHORITATIVE INFORMATION',
    204: 'NO CONTENT',
    205: 'RESET CONTENT',
    206: 'PARTIAL CONTENT',
    301: 'MOVED PERMANENTLY',
    302: 'FOUND',
    303: 'SEE OTHER',
    304: 'NOT MODIFIED',
    305: 'USE PROXY',
    307: 'TEMPORARY REDIRECT',
    400: 'BAD REQUEST',
    401: 'UNAUTHORIZED',
    403: 'FORBIDDEN',
    404: 'NOT FOUND',
    405: 'METHOD NOT ALLOWED',
    406: 'NOT ACCEPTABLE',
    407: 'PROXY AUTHENTICATION REQUIRED',
    408: 'REQUEST TIMEOUT',
    409: 'CONFLICT',
    410: 'GONE',
    411: 'LENGTH REQUIRED',
    412: 'PRECONDITION FAILED',
    413: 'REQUEST ENTITY TOO LARGE',
    414: 'REQUEST-URI TOO LONG',
    415: 'UNSUPPORTED MEDIA TYPE',
    416: 'REQUESTED RANGE NOT SATISFIABLE',
    417: 'EXPECTATION FAILED',
    500: 'INTERNAL SERVER ERROR',
    501: 'NOT IMPLEMENTED',
    502: 'BAD GATEWAY',
    503: 'SERVICE UNAVAILABLE',
    504: 'GATEWAY TIMEOUT',
    505: 'HTTP VERSION NOT SUPPORTED',
    }

# If web2py is executed with python2.4 we need
# to use Exception instead of BaseException

try:
    BaseException
except NameError:
    BaseException = Exception


class HTTP(BaseException):

    def __init__(
        self,
        status,
        body='',
        **headers
        ):
        self.status = status
        self.body = body
        self.headers = headers

    def to(self, responder):
        if self.status in defined_status:
            status = '%d %s' % (self.status, defined_status[self.status])
        else:
            status = str(self.status) + ' '
        if not 'Content-Type' in self.headers:
            self.headers['Content-Type'] = 'text/html; charset=UTF-8'
        body = self.body
        if status[:1] == '4':
            if not body:
                body = status
            if isinstance(body, str):
                if len(body)<512 and self.headers['Content-Type'].startswith('text/html'):
                    body += '<!-- %s //-->' % ('x'*512) ### trick IE
                self.headers['Content-Length'] = len(body)
        headers = []
        for (k, v) in self.headers.items():
            if isinstance(v, list):
                for item in v:
                    headers.append((k, str(item)))
            else:
                headers.append((k, str(v)))
        responder(status, headers)
        if hasattr(body, '__iter__') and not isinstance(self.body, str):
            return body
        return [str(body)]

    @property
    def message(self):
        '''
        compose a message describing this exception

        "status defined_status [web2py_error]"

        message elements that are not defined are omitted
        '''
        msg = '%(status)d'
        if self.status in defined_status:
            msg = '%(status)d %(defined_status)s'
        if 'web2py_error' in self.headers:
            msg += ' [%(web2py_error)s]'
        return msg % dict(status=self.status,
                          defined_status=defined_status.get(self.status),
                          web2py_error=self.headers.get('web2py_error'))

    def __str__(self):
        "stringify me"
        return self.message


def redirect(location, how=303):
    if not location:
        return
    location = location.replace('\r', '%0D').replace('\n', '%0A')
    raise HTTP(how,
               'You are being redirected <a href="%s">here</a>' % location,
               Location=location)