
_q_exports = ["other"]

from quixote.errors import TraversalError

from quixote.demo.pages import _q_index

def other(request):
    return "Handled by a Python function."

def fact(n):
    f = n*1L
    while n > 1:
        f *= n
        n -= 1
    return f

class IntegerUI:

    _q_exports = ["index", "factorial"]

    def __init__(self, request, component):
        try:
            self.n = int(component)
        except ValueError, exc:
            raise TraversalError(request.get_path(), str(exc))
    
    def factorial(self, request):
        return "%d! = %d" % (self.n, fact(self.n))
        
    def _q_index(self, request):
        return """\
You have selected the integer %d.<p>

Let's compute its <a href="factorial">factorial</a> (%d!)<p>
""" % (self.n, self.n)

def _q_getname(request, component):
    return IntegerUI(request, component)
