[Checkins] SVN: z3c.jbot/trunk/ Fixed a bug where an exception
would be raised if a template was not defined inside the syspath;
the syspath is now also queried just once, which seems to fix an
instability issue.
Malthe Borch
mborch at gmail.com
Thu Mar 13 10:17:25 EDT 2008
Log message for revision 84635:
Fixed a bug where an exception would be raised if a template was not defined inside the syspath; the syspath is now also queried just once, which seems to fix an instability issue.
Changed:
U z3c.jbot/trunk/setup.py
U z3c.jbot/trunk/z3c/jbot/manager.py
-=-
Modified: z3c.jbot/trunk/setup.py
===================================================================
--- z3c.jbot/trunk/setup.py 2008-03-13 10:54:57 UTC (rev 84634)
+++ z3c.jbot/trunk/setup.py 2008-03-13 14:17:23 UTC (rev 84635)
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import sys, os
-version = '0.1.2'
+version = '0.1.3'
setup(name='z3c.jbot',
version=version,
Modified: z3c.jbot/trunk/z3c/jbot/manager.py
===================================================================
--- z3c.jbot/trunk/z3c/jbot/manager.py 2008-03-13 10:54:57 UTC (rev 84634)
+++ z3c.jbot/trunk/z3c/jbot/manager.py 2008-03-13 14:17:23 UTC (rev 84635)
@@ -1,7 +1,7 @@
import sys
import os.path
-import threading
+IGNORE = object()
def root_length(a, b):
if b.startswith(a):
@@ -9,22 +9,29 @@
else:
return 0
-def find_package(path):
- # find out in which package this file is located
- syspaths = sys.path
- syspaths.sort(key=lambda syspath: root_length(syspath, path),
- reverse=True)
-
- path = path[len(syspaths[0]):]
+def find_package(syspaths, path):
+ """Determine the Python-package where path is located. If the path is
+ not located within the Python sys-path, return ``None``."""
+ _syspaths = sorted(
+ syspaths, key=lambda syspath: root_length(syspath, path), reverse=True)
+
+ syspath = _syspaths[0]
+
+ if not path.startswith(syspath):
+ return None
+
+ path = path[len(syspath):]
+
# convert path to dotted filename
if path.startswith(os.path.sep):
path = path[1:]
-
+
return path
-class GlobalTemplateManager(threading.local):
+class GlobalTemplateManager(object):
def __init__(self):
+ self.syspaths = tuple(sys.path)
self.templates = {}
self.paths = {}
@@ -45,16 +52,23 @@
# assert that template is not already registered
filename = self.templates.get(template)
+ if filename is IGNORE:
+ return
+
if self.paths.get(filename) == template.filename:
return
- if filename and filename not in self.paths:
+ if filename is not None and filename not in self.paths:
# template file has been unregistered; restore
# original template
template.filename = template._filename
delattr(template, '_filename')
-
- path = find_package(template.filename)
+
+ path = find_package(self.syspaths, template.filename)
+ if path is None:
+ self.templates[template] = IGNORE
+ return
+
filename = path.replace(os.path.sep, '.')
if filename in self.paths:
More information about the Checkins
mailing list