This file is indexed.

/usr/share/pyshared/circuits/web/main.py is in python-circuits 2.1.0-2.

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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""Main

circutis.web Web Server and Testing Tool.
"""

import os
from optparse import OptionParser
from wsgiref.validate import validator
from wsgiref.simple_server import make_server

try:
    import hotshot
    import hotshot.stats
except ImportError:
    hostshot = None

try:
    import psyco
except:
    psyco = None  # NOQA

from circuits.core.pollers import Select
from circuits.tools import inspect, graph
from circuits import Component, Manager, Debugger
from circuits import __version__ as systemVersion
from circuits.web import BaseServer, Server, Controller, Static, wsgi

try:
    from circuits.core.pollers import Poll
except ImportError:
    Poll = None  # NOQA

try:
    from circuits.core.pollers import EPoll
except ImportError:
    EPoll = None  # NOQA


USAGE = "%prog [options] [docroot]"
VERSION = "%prog v" + systemVersion


def parse_options():
    parser = OptionParser(usage=USAGE, version=VERSION)

    parser.add_option(
        "-b", "--bind",
        action="store", type="string", default="0.0.0.0:8000", dest="bind",
        help="Bind to address:[port]"
    )

    if psyco is not None:
        parser.add_option(
            "-j", "--jit",
            action="store_true", default=False, dest="jit",
            help="Use python HIT (psyco)"
        )

    parser.add_option(
        "-m", "--multiprocessing",
        action="store", type="int", default=0, dest="mp",
        help="Specify no. of processes to start (multiprocessing)"
    )

    parser.add_option(
        "-t", "--type",
        action="store", type="string", default="select", dest="type",
        help="Specify type of poller to use"
    )

    parser.add_option(
        "-s", "--server",
        action="store", type="string", default="server", dest="server",
        help="Specify server to use"
    )

    parser.add_option(
        "-p", "--profile",
        action="store_true", default=False, dest="profile",
        help="Enable execution profiling support"
    )

    parser.add_option(
        "-d", "--debug",
        action="store_true", default=False, dest="debug",
        help="Enable debug mode"
    )

    parser.add_option(
        "-v", "--validate",
        action="store_true", default=False, dest="validate",
        help="Enable WSGI validation mode"
    )

    opts, args = parser.parse_args()

    return opts, args


class HelloWorld(Component):

    channel = "web"

    def request(self, request, response):
        return "Hello World!"


class Root(Controller):

    def hello(self):
        return "Hello World!"


def main():
    opts, args = parse_options()

    if psyco and opts.jit:
        psyco.full()

    if ":" in opts.bind:
        address, port = opts.bind.split(":")
        port = int(port)
    else:
        address, port = opts.bind, 8000

    bind = (address, port)

    if opts.validate:
        application = (wsgi.Application() + Root())
        app = validator(application)

        httpd = make_server(address, port, app)
        httpd.serve_forever()

        raise SystemExit(0)

    manager = Manager()

    if opts.debug:
        manager += Debugger()

    poller = opts.type.lower()
    if poller == "poll":
        if Poll is None:
            print("No poll support available - defaulting to Select...")
            Poller = Select
        else:
            Poller = Poll
    elif poller == "epoll":
        if EPoll is None:
            print("No epoll support available - defaulting to Select...")
            Poller = Select
        else:
            Poller = EPoll
    else:
        Poller = Select

    Poller().register(manager)

    if opts.server.lower() == "base":
        BaseServer(bind).register(manager)
        HelloWorld().register(manager)
    else:
        Server(bind).register(manager)
        Root().register(manager)

    docroot = os.getcwd() if not args else args[0]

    Static(docroot=docroot, dirlisting=True).register(manager)

    if opts.profile:
        if hotshot:
            profiler = hotshot.Profile(".profile")
            profiler.start()

    if opts.debug:
        print(graph(manager, name="circuits.web"))
        print()
        print(inspect(manager))

    for i in range(opts.mp):
        manager.start(process=True)

    manager.run()

    if opts.profile and hotshot:
        profiler.stop()
        profiler.close()

        stats = hotshot.stats.load(".profile")
        stats.strip_dirs()
        stats.sort_stats("time", "calls")
        stats.print_stats(20)


if __name__ == "__main__":
    main()