comparison MoinMoin/request/request_wsgi.py @ 3360:b5b49ff88d0c

work around unpythonic WSGI 1.0 read() API, fixing broken xmlrpc putPage with mod_wsgi
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Thu, 20 Mar 2008 18:00:37 +0100
parents b06c048233f2
children 91d38a790d8e
comparison
equal deleted inserted replaced
3359:dd6293254e4f 3360:b5b49ff88d0c
35 form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1) 35 form = cgi.FieldStorage(fp=self.stdin, environ=self.env, keep_blank_values=1)
36 return RequestBase._setup_args_from_cgi_form(self, form) 36 return RequestBase._setup_args_from_cgi_form(self, form)
37 37
38 def read(self, n=None): 38 def read(self, n=None):
39 if n is None: 39 if n is None:
40 return self.stdin.read() 40 # We can't do that, because wsgi 1.0 requires n:
41 #return self.stdin.read()
42 # Thus, if we have no n, we have to simulate the usual behaviour (or
43 # it won't work e.g. with mod_wsgi 1.3 and maybe other wsgi 1.0 servers).
44 # Note: just requesting a extremely large amount (expecting it to never
45 # be reached, but still all data returned) also does not work (mod_wsgi
46 # 1.3 gives a MemoryError when doing that):
47 data = []
48 while True:
49 read_data = self.stdin.read(4000)
50 if not read_data:
51 break
52 data.append(read_data)
53 return ''.join(data)
41 else: 54 else:
42 return self.stdin.read(n) 55 return self.stdin.read(n)
43 56
44 def write(self, *data): 57 def write(self, *data):
45 self.stdout.write(self.encode(data)) 58 self.stdout.write(self.encode(data))