# HG changeset patch # User David Barts # Date 1557788411 25200 # Node ID 57ec65f527e98315a9501b7d2bd630eaf3c08eba # Parent a3823da7bb4597ebfce879426507eec2355b25b1 Eliminate a stat() call, allow no code-behind on pages. diff -r a3823da7bb45 -r 57ec65f527e9 tincan.py --- a/tincan.py Mon May 13 15:18:02 2019 -0700 +++ b/tincan.py Mon May 13 16:00:11 2019 -0700 @@ -398,15 +398,24 @@ raise TinCanError("{0}: bad #errors code".format(self._urlpath)) self._app.error_handler[error] = route # XXX + def _gettime(self, path): + try: + return os.stat(path).st_mtime + except FileNotFoundError: + return 0 + def _getclass(self): pypath = os.path.normpath(os.path.join(self._fsroot, *self._splitpath(self._python))) + # Give 'em a default code-behind if they don't furnish one + pytime = self._gettime(pypath) + if not pytime: + self._class = Page + return + # Else load the code-behind from a .py file pycpath = pypath + 'c' + pyctime = self._gettime(pycpath) try: - pyctime = os.stat(pycpath).st_mtime - except OSError: - pyctime = 0 - try: - if pyctime < os.stat(pypath).st_mtime: + if pyctime < pytime: py_compile.compile(pypath, cfile=pycpath, doraise=True) except py_compile.PyCompileError as e: raise TinCanError(str(e)) from e