Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / web / examples / report.rpy.py
1 # Copyright (c) Twisted Matrix Laboratories.
2 # See LICENSE for details.
3
4 """
5 This example demostrates how to get host information from a request object.
6
7 To test the script, rename the file to report.rpy, and move it to any directory,
8 let's say /var/www/html/.
9
10 Now, start your Twist web server:
11    $ twistd -n web --path /var/www/html/
12
13 Then visit http://127.0.0.1:8080/report.rpy in your web browser.
14 """
15
16 from twisted.web.resource import Resource
17
18
19 class ReportResource(Resource):
20
21     def render_GET(self, request):
22         path = request.path
23         host = request.getHost().host
24         port = request.getHost().port
25         url = request.prePathURL()
26         uri = request.uri
27         secure = (request.isSecure() and "securely") or "insecurely"
28         return ("""\
29 <HTML>
30     <HEAD><TITLE>Welcome To Twisted Python Reporting</title></head>
31
32     <BODY><H1>Welcome To Twisted Python Reporting</H1>
33     <UL>
34     <LI>The path to me is %(path)s
35     <LI>The host I'm on is %(host)s
36     <LI>The port I'm on is %(port)s
37     <LI>I was accessed %(secure)s
38     <LI>A URL to me is %(url)s
39     <LI>My URI to me is %(uri)s
40     </UL>
41     </body>
42 </html>""" % vars())
43
44 resource = ReportResource()