/usr/share/pyshared/quixote/demo/integers.ptl is in python-quixote 2.7~b2-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 | import sys
from quixote import get_response, redirect
from quixote.directory import Directory
from quixote.errors import TraversalError
def fact(n):
f = 1L
while n > 1:
f *= n
n -= 1
return f
class IntegerUI(Directory):
_q_exports = ["", "factorial", "prev", "next"]
def __init__(self, component):
try:
self.n = int(component)
except ValueError, exc:
raise TraversalError(str(exc))
def factorial(self):
if self.n > 10000:
sys.stderr.write("warning: possible denial-of-service attack "
"(request for factorial(%d))\n" % self.n)
get_response().set_content_type("text/plain")
return "%d! = %d\n" % (self.n, fact(self.n))
def _q_index(self):
return """\
<html>
<head><title>The Number %d</title></head>
<body>
You have selected the integer %d.<p>
You can compute its <a href="factorial">factorial</a> (%d!)<p>
Or, you can visit the web page for the
<a href="../%d/">previous</a> or
<a href="../%d/">next</a> integer.<p>
Or, you can use redirects to visit the
<a href="prev">previous</a> or
<a href="next">next</a> integer. This makes
it a bit easier to generate this HTML code, but
it's less efficient -- your browser has to go through
two request/response cycles. And someone still
has to generate the URLs for the previous/next
pages -- only now it's done in the <code>prev()</code>
and <code>next()</code> methods for this integer.<p>
</body>
</html>
""" % (self.n, self.n, self.n, self.n-1, self.n+1)
def prev(self):
return redirect("../%d/" % (self.n-1))
def next(self):
return redirect("../%d/" % (self.n+1))
|