comparison tincan.py @ 44:7261459351fa draft

More multithread support, remove debug writes.
author David Barts <n5jrn@me.com>
date Thu, 30 May 2019 11:23:26 -0700
parents 0bd9b9ae9998
children 969f515b505b
comparison
equal deleted inserted replaced
43:0bd9b9ae9998 44:7261459351fa
435 self._type += "; charset=" + launcher.encoding 435 self._type += "; charset=" + launcher.encoding
436 else: 436 else:
437 self._encoding = None 437 self._encoding = None
438 438
439 def launch(self): 439 def launch(self):
440 print("adding static route:", self._urlpath) # debug 440 # print("adding static route:", self._urlpath) # debug
441 self._app.route(self._urlpath, 'GET', self) 441 self._app.route(self._urlpath, 'GET', self)
442 442
443 def _parse_date(self, ims): 443 def _parse_date(self, ims):
444 """ 444 """
445 Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch. 445 Parse rfc1123, rfc850 and asctime timestamps and return UTC epoch.
617 else: 617 else:
618 methods = [ i.upper() for i in self._header.methods.split() ] 618 methods = [ i.upper() for i in self._header.methods.split() ]
619 if not methods: 619 if not methods:
620 raise TinCanError("{0}: no #methods specified".format(self._urlpath)) 620 raise TinCanError("{0}: no #methods specified".format(self._urlpath))
621 # Register this thing with Bottle 621 # Register this thing with Bottle
622 print("adding route:", self._origin, '('+','.join(methods)+')') # debug 622 # print("adding route:", self._origin, '('+','.join(methods)+')') # debug
623 self._app.route(self._origin, methods, self) 623 self._app.route(self._origin, methods, self)
624 624
625 def _splitpath(self, unsplit): 625 def _splitpath(self, unsplit):
626 return _normpath(self._subdir, unsplit) 626 return _normpath(self._subdir, unsplit)
627 627
884 884
885 def _logger(message): 885 def _logger(message):
886 sys.stderr.write(message) 886 sys.stderr.write(message)
887 sys.stderr.write('\n') 887 sys.stderr.write('\n')
888 888
889 def launch(fsroot=None, urlroot='/', logger=_logger, debug=False, encoding=ENCODING, static=False): 889 def launch(fsroot=None, urlroot='/', logger=_logger, debug=False,
890 encoding=ENCODING, static=False, multithread=True):
890 """ 891 """
891 Launch and return a TinCan webapp. Does not run the app; it is the 892 Launch and return a TinCan webapp. Does not run the app; it is the
892 caller's responsibility to call app.run() 893 caller's responsibility to call app.run()
893 """ 894 """
894 if fsroot is None: 895 if fsroot is None:
895 fsroot = os.getcwd() 896 fsroot = os.getcwd()
896 launcher = _Launcher(fsroot, urlroot, logger) 897 launcher = _Launcher(fsroot, urlroot, logger, multithread=multithread)
897 launcher.debug = debug 898 launcher.debug = debug
898 launcher.encoding = encoding 899 launcher.encoding = encoding
899 launcher.static = static 900 launcher.static = static
900 launcher.launch() 901 launcher.launch()
901 return launcher.app, launcher.errors 902 return launcher.app, launcher.errors