File: report.rpy

package info (click to toggle)
twisted 25.5.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 20,560 kB
  • sloc: python: 203,171; makefile: 200; sh: 92; javascript: 36; xml: 31
file content (48 lines) | stat: -rw-r--r-- 1,276 bytes parent folder | download | duplicates (3)
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
# Copyright (c) Twisted Matrix Laboratories.
# See LICENSE for details.

"""
This example demonstrates how to get host information from a request object.

To test the script, copy report.rpy to any directory,
let's say /var/www/html/.

Now, start your Twist web server:
   $ twistd -n web --path /var/www/html/

Then visit http://127.0.0.1:8080/report.rpy in your web browser.
"""

from twisted.web.resource import Resource


class ReportResource(Resource):
    def render_GET(self, request):
        path = request.path
        host = request.getHost().host
        port = request.getHost().port
        url = request.prePathURL()
        uri = request.uri
        secure = (request.isSecure() and "securely") or "insecurely"
        output = """
<HTML>
    <HEAD><TITLE>Welcome To Twisted Python Reporting</title></head>

    <BODY><H1>Welcome To Twisted Python Reporting</H1>
    <UL>
    <LI>The path to me is {path}
    <LI>The host I'm on is {host}
    <LI>The port I'm on is {port}
    <LI>I was accessed {secure}
    <LI>A URL to me is {url}
    <LI>My URI to me is {uri}
    </UL>
    </body>
</html>""".format(
            path=path, host=host, port=port, secure=secure, url=url, uri=uri
        )

        return output.encode("utf8")


resource = ReportResource()