comparison roundup/cgi/client.py @ 5673:6b6bc8d31caf

Merged
author Ralf Schlatterbeck <rsc@runtux.com>
date Mon, 25 Mar 2019 19:47:29 +0100
parents f60c44563c3a
children b67636bc87d0
comparison
equal deleted inserted replaced
5672:a7211712b110 5673:6b6bc8d31caf
235 235
236 cgi.FieldStorage must save all data as binary/bytes. This is 236 cgi.FieldStorage must save all data as binary/bytes. This is
237 needed for handling json and xml data blobs under python 237 needed for handling json and xml data blobs under python
238 3. Under python 2, str and binary are interchangable, not so 238 3. Under python 2, str and binary are interchangable, not so
239 under 3. 239 under 3.
240
241 Note that there may be places where this should support text mode.
242 (e.g. a large text file upload??). None are known, but this could be
243 a problem.
244 ''' 240 '''
245 def make_file(self, mode=None): 241 def make_file(self, mode=None):
246 ''' work around https://bugs.python.org/issue27777 ''' 242 ''' work around https://bugs.python.org/issue27777 '''
247 import tempfile 243 import tempfile
248 return tempfile.TemporaryFile("wb+") 244 if self.length >= 0:
245 return tempfile.TemporaryFile("wb+")
246 return super().make_file()
249 247
250 class Client: 248 class Client:
251 """Instantiate to handle one CGI request. 249 """Instantiate to handle one CGI request.
252 250
253 See inner_main for request processing. 251 See inner_main for request processing.
525 # Set the charset and language 523 # Set the charset and language
526 self.determine_charset() 524 self.determine_charset()
527 self.determine_language() 525 self.determine_language()
528 # Open the database as the correct user. 526 # Open the database as the correct user.
529 # TODO: add everything to RestfulDispatcher 527 # TODO: add everything to RestfulDispatcher
530 self.determine_user() 528 try:
529 self.determine_user()
530 except LoginError as err:
531 self.response_code = http_.client.UNAUTHORIZED
532 output = b"Invalid Login\n"
533 self.setHeader("Content-Length", str(len(output)))
534 self.setHeader("Content-Type", "text/plain")
535 self.write(output)
536 return
537
531 self.check_anonymous_access() 538 self.check_anonymous_access()
532 539
533 # Call rest library to handle the request 540 # Call rest library to handle the request
534 handler = rest.RestfulInstance(self, self.db) 541 handler = rest.RestfulInstance(self, self.db)
535 output = handler.dispatch(self.env['REQUEST_METHOD'], self.path, 542 output = handler.dispatch(self.env['REQUEST_METHOD'], self.path,

Roundup Issue Tracker: http://roundup-tracker.org/