1 """
2 This file is part of web2py Web Framework (Copyrighted, 2007)
3 Developed by Massimo Di Pierro <mdipierro@cs.depaul.edu>
4 License: GPL v2
5 """
6
7 from storage import Storage
8 from compileapp import run_view_in
9 from streamer import streamer
10 from xmlrpc import handler
11 from contenttype import contenttype
12 from html import xmlescape
13 import sys, cPickle, cStringIO, thread, time, shelve, os, stat
14
15 __all__=['Request','Response','Session']
16
18 """
19 defines the request object and the default values of its members
20 """
30 pass
31
33 """
34 defines the response object and the default values of its members
35 response.write(....) can be used to write in the output html
36 """
38 self.status=200
39 self.headers=Storage()
40 self.body=cStringIO.StringIO()
41 self.session_id=None
42 self.cookies=Storage()
43 self.keywords=''
44 self.description=''
45 self.flash=None
46 self.menu=None
47 self._vars=None
48 self._view_environment=None
49 - def write(self,data,escape=True):
53 if len(a)>1 or (len(a)==1 and not hasattr(a[0],'items')):
54 raise SyntaxError
55 if len(a): self._vars=a[0]
56 else: self._vars={}
57 for key,value in b.items(): self._vars[key]=value
58 for key,value in self._vars.items(): self._view_environment[key]=value
59 run_view_in(self._view_environment)
60 self.body=self.body.getvalue()
61 return self.body
62 - def stream(self,stream,chunk_size=10**6):
63 """
64 if a controller function
65 > return response.stream(file,100)
66 the file content will be streamed at 100 bytes at the time
67 """
68 if hasattr(stream,'name'): filename=stream.name
69 else: filename=None
70 keys=[item.lower() for item in self.headers.keys()]
71 if filename and not 'content-type' in keys:
72 self.headers['Content-Type']=contenttype(filename)
73 if filename and not 'content-length' in keys:
74 self.headers['Content-Length']=os.stat(filename)[stat.ST_SIZE]
75 self.body=streamer(stream,chunk_size)
76 return self.body
77 - def xmlrpc(self,request,methods):
78 """
79 assuming:
80 > def add(a,b): return a+b
81 if a controller function "func"
82 > return response.xmlrpc(request,[add])
83 the controller will be able to handle xmlrpc requests for
84 the add function. Example:
85 > import xmlrpclib
86 > connection=xmlrpclib.ServerProxy('http://hostname/app/contr/func')
87 > print connection.add(3,4)
88 """
89 return handler(request,self,methods)
90
92 """
93 defines the session object and the default values of its members (None)
94 """
95 pass
96