File tree 2 files changed +24
-1
lines changed 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -30,3 +30,15 @@ consider this variant that the module also supports:
30
30
> def f(request):
31
31
> print request
32
32
> return "whatevz!"
33
+
34
+ The "serve" function is quite generous in what it accepts for its first
35
+ argument. Assuming you have defined 'f' and 'g' as consumers as before you can
36
+ create a server from both consumers at once using syntax like this:
37
+
38
+ > serve({'letter_f':f,'letter_g':g})
39
+
40
+ or simply
41
+
42
+ > serve([f,g])
43
+
44
+ if you' like '/f' to be handled by f and '/g' to be handled by g.
Original file line number Diff line number Diff line change @@ -5,11 +5,22 @@ def consumer(f):
5
5
class R (resource .Resource ):
6
6
isLeaf = True
7
7
R .render = lambda res , req : f (req )
8
+ R .tag = f .__name__
8
9
return R ()
9
10
10
11
def serve (res , port ):
12
+ if type (res ) is dict :
13
+ root = resource .Resource ()
14
+ for k ,v in res .iteritems ():
15
+ root .putChild (k ,v )
16
+ res = root
17
+ if type (res ) is list :
18
+ root = resource .Resource ()
19
+ for r in res :
20
+ root .putChild (r .tag , r )
21
+ res = root
11
22
reactor .listenTCP (port , server .Site (res ))
12
23
reactor .run ()
13
24
14
- def easy_consume (port ):
25
+ def easy_consume (port = 80 ):
15
26
return lambda f : serve (consumer (f ),port )
You can’t perform that action at this time.
0 commit comments