This file is indexed.

/usr/lib/python2.7/dist-packages/zope/testing/server.py is in python-zope.testing 4.1.2-0ubuntu7.

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
##############################################################################
#
# Copyright (c) 2007 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Functional test server to interactively inspect the state of the application.

You can run it in a functional test by adding a line like this:

  startServer(http, url, "username", "password")

http is an instance of HTTPCaller, url is the url that will be opened
in the browser, the username and password are optional. When you're
done with inspecting the application press Ctrl+C to continue with the
functional test.
"""
import urlparse
import webbrowser
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
import sys


def makeRequestHandler(http, user=None, password=None):
    class FunctionalTestRequestHandler(BaseHTTPRequestHandler):

        def do_GET(self):
            request = self.raw_requestline
            if user and password:
                # Authentication is built in, as there is no fluent
                # way of transferring session from functional test to
                # the real browser
                request += "Authorization: Basic %s:%s\r\n" % (user, password)

            # Write headers to the request
            for header in self.headers.headers:
                request += header
            request += '\r\n'

            if self.headers.get('Content-Length'):
                data = self.rfile.read(int(self.headers.get('Content-Length')))
                request += data
            else:
                # if no content-length was set - read until the last
                # char, then finish
                self.request.setblocking(0)
                while True:
                    try:
                        char = self.rfile.read()
                    except:
                        break
                    request += char

            response = http(request)
            self.wfile.write(response)

        do_POST = do_GET

    return FunctionalTestRequestHandler


def addPortToURL(url, port):
    """Add a port number to the url.

        >>> addPortToURL('http://localhost/foo/bar/baz.html', 3000)
        'http://localhost:3000/foo/bar/baz.html'
        >>> addPortToURL('http://foo.bar.com/index.html?param=some-value', 555)
        'http://foo.bar.com:555/index.html?param=some-value'

        >>> addPortToURL('http://localhost:666/index.html', 555)
        'http://localhost:555/index.html'

    """
    (scheme, netloc, url, query, fragment) = urlparse.urlsplit(url)
    netloc = netloc.split(':')[0]
    netloc = "%s:%s" % (netloc, port)
    url = urlparse.urlunsplit((scheme, netloc, url, query, fragment))
    return url


def startServer(http, url, user=None, password=None, port=8000):
    try:
        server_address = ('', port)
        requestHandler = makeRequestHandler(http, user, password)
        url = addPortToURL(url, port)
        httpd = HTTPServer(server_address, requestHandler)
        # XXX we rely on browser being slower than our server
        webbrowser.open(url)
        print >> sys.stderr, 'Starting HTTP server...'
        httpd.serve_forever()
    except KeyboardInterrupt:
        print >> sys.stderr, 'Stopped HTTP server.'