diff 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
line wrap: on
line diff
--- a/tincan.py	Thu May 30 22:19:41 2019 -0700
+++ b/tincan.py	Fri May 31 08:23:37 2019 -0700
@@ -801,6 +801,8 @@
 _BANNED = set([_WINF])
 _EBANNED = set([_IEXTEN, _TEXTEN, _PEXTEN, _PEXTEN+"c"])
 ENCODING = "utf-8"
+_BITBUCKET = logging.getLogger(__name__)
+_BITBUCKET.addHandler(logging.NullHandler)
 
 class _Launcher(object):
     """
@@ -818,7 +820,7 @@
         self.encoding = ENCODING
         self.static = False
         self.multithread = multithread
-        self.logger = None
+        self.logger = _BITBUCKET
 
     def launch(self):
         """
@@ -882,11 +884,7 @@
             elif S_ISDIR(etype):
                 self._launch(subdir + [entry])
 
-_BITBUCKET = logging.getLogger(__name__)
-_BITBUCKET.addHandler(logging.NullHandler)
-
-def launch(fsroot=None, urlroot='/', logger=_BITBUCKET, encoding=ENCODING,
-    static=False, multithread=True):
+def launch(fsroot=None, urlroot='/', multithread=True, **kwargs):
     """
     Launch and return a TinCan webapp. Does not run the app; it is the
     caller's responsibility to call app.run()
@@ -894,9 +892,9 @@
     if fsroot is None:
         fsroot = os.getcwd()
     launcher = _Launcher(fsroot, urlroot, multithread)
-    launcher.logger = logger
-    launcher.encoding = encoding
-    launcher.static = static
+    for i in [ "logger", "encoding", "static" ]:
+        if i in kwargs:
+            setattr(launcher, i, kwargs[i])
     launcher.launch()
     return launcher.app, launcher.errors