comparison tincan.py @ 53:3a6180c1feea draft

Remove some needless repetition.
author David Barts <n5jrn@me.com>
date Fri, 31 May 2019 08:23:37 -0700
parents 997d0c8c174f
children cb5a6e200c95
comparison
equal deleted inserted replaced
52:243603aaab7e 53:3a6180c1feea
799 799
800 _WINF = "WEB-INF" 800 _WINF = "WEB-INF"
801 _BANNED = set([_WINF]) 801 _BANNED = set([_WINF])
802 _EBANNED = set([_IEXTEN, _TEXTEN, _PEXTEN, _PEXTEN+"c"]) 802 _EBANNED = set([_IEXTEN, _TEXTEN, _PEXTEN, _PEXTEN+"c"])
803 ENCODING = "utf-8" 803 ENCODING = "utf-8"
804 _BITBUCKET = logging.getLogger(__name__)
805 _BITBUCKET.addHandler(logging.NullHandler)
804 806
805 class _Launcher(object): 807 class _Launcher(object):
806 """ 808 """
807 Helper class for launching webapps. 809 Helper class for launching webapps.
808 """ 810 """
816 self.errors = 0 818 self.errors = 0
817 self.debug = False 819 self.debug = False
818 self.encoding = ENCODING 820 self.encoding = ENCODING
819 self.static = False 821 self.static = False
820 self.multithread = multithread 822 self.multithread = multithread
821 self.logger = None 823 self.logger = _BITBUCKET
822 824
823 def launch(self): 825 def launch(self):
824 """ 826 """
825 Does the actual work of launching something. XXX - modifies sys.path 827 Does the actual work of launching something. XXX - modifies sys.path
826 and never un-modifies it. 828 and never un-modifies it.
880 self.logger.error(str(e)) 882 self.logger.error(str(e))
881 self.errors += 1 883 self.errors += 1
882 elif S_ISDIR(etype): 884 elif S_ISDIR(etype):
883 self._launch(subdir + [entry]) 885 self._launch(subdir + [entry])
884 886
885 _BITBUCKET = logging.getLogger(__name__) 887 def launch(fsroot=None, urlroot='/', multithread=True, **kwargs):
886 _BITBUCKET.addHandler(logging.NullHandler)
887
888 def launch(fsroot=None, urlroot='/', logger=_BITBUCKET, encoding=ENCODING,
889 static=False, multithread=True):
890 """ 888 """
891 Launch and return a TinCan webapp. Does not run the app; it is the 889 Launch and return a TinCan webapp. Does not run the app; it is the
892 caller's responsibility to call app.run() 890 caller's responsibility to call app.run()
893 """ 891 """
894 if fsroot is None: 892 if fsroot is None:
895 fsroot = os.getcwd() 893 fsroot = os.getcwd()
896 launcher = _Launcher(fsroot, urlroot, multithread) 894 launcher = _Launcher(fsroot, urlroot, multithread)
897 launcher.logger = logger 895 for i in [ "logger", "encoding", "static" ]:
898 launcher.encoding = encoding 896 if i in kwargs:
899 launcher.static = static 897 setattr(launcher, i, kwargs[i])
900 launcher.launch() 898 launcher.launch()
901 return launcher.app, launcher.errors 899 return launcher.app, launcher.errors
902 900
903 # XXX - We cannot implement a command-line launcher here; see the 901 # XXX - We cannot implement a command-line launcher here; see the
904 # launcher script for why. 902 # launcher script for why.