comparison tests/objects.py @ 57:cb1898f8c72a

* illustrate another pattern * note future of pyloader casting
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 08 Jun 2011 23:45:11 -0700
parents 49f88cde6219
children 2a1648a53857
comparison
equal deleted inserted replaced
56:ade85970c628 57:cb1898f8c72a
22 return number * self.factor 22 return number * self.factor
23 23
24 class Wrapper(object): 24 class Wrapper(object):
25 def __init__(self, app, **values): 25 def __init__(self, app, **values):
26 self.app = app 26 self.app = app
27 self.values = dict([(int(i), j) for i, j in values]) 27 self.values = dict([(int(i), j) for i, j in values]) # TODO: should be automagically converted ideally via pyloader
28 def __call__(self, *args, **kwargs): 28 def __call__(self, *args, **kwargs):
29 retval = self.app(*args, **kwargs) 29 retval = self.app(*args, **kwargs)
30 values = {1: 'one', 30 values = {1: 'one',
31 2: 'two', 31 2: 'two',
32 3: 'three'} # etc 32 3: 'three'} # etc
38 def wrap(app): 38 def wrap(app):
39 return Wrapper(app) 39 return Wrapper(app)
40 40
41 def fib(n): 41 def fib(n):
42 """return the nth fibonacci term""" 42 """return the nth fibonacci term"""
43 n = int(n) # TODO: should be automagically converted ideally via pyloader
43 sequence = [1,1] 44 sequence = [1,1]
44 while len(sequence) - 1 < n: 45 while len(sequence) - 1 < n:
45 sequence.append(sequence[len(sequence)-1] + sequence[len(sequence)-2]) 46 sequence.append(sequence[len(sequence)-1] + sequence[len(sequence)-2])
46 return sequence[n] 47 return sequence[n]