durusmail: quixote-users: _q_lookup and namespaces
_q_lookup and namespaces
2003-06-10
2003-06-10
Re: _q_lookup and namespaces
2003-06-10
2003-06-11
2003-06-11
2003-06-11
2003-06-13
_q_lookup and namespaces
Titus Brown
2003-06-10
-> I have a question about the best way to do namespace traversal in quixote.
->
-> Sorry for the contrived example, but I think this best illustrates the
-> point.
->
-> Say I have an app that needs to map a URL
->
-> /numbers//
->
-> For example,
-> /numbers/15/binary would return '1111'
-> /numbers/15/octal would return '017'
-> /numbers/15/decimal would return '15'
-> /numbers/15/hexadecimal would return '0xf'
->
-> /numbers is a module, and the namespace is introduced by
-> import numbers
->
-> // is best mapped to a _q_lookup function.
->
-> How are the // best handled, though?

Why not use _q_lookup to instantiate a class that takes the number
in its __init__ and defines binary/octal/decimal/hexadecimal as
functions?

class NumberRepr:
   _q_exports = ['binary', 'octal', 'decimal', 'hexadecimal']

   def __init__(self, n):
      self.n = n

   def binary(self, request):
      return "n is %s in binary" % (binary_string(n),)

etc.

If you need to hang stuff off of binary/octal etc., e.g.

/numbers/15/binary/not

then I'm not sure ;).

--titus

reply