diff options
author | ianb <devnull@localhost> | 2005-10-04 18:59:59 +0000 |
---|---|---|
committer | ianb <devnull@localhost> | 2005-10-04 18:59:59 +0000 |
commit | 65b5b5de85b2afb7d792608fa2be915d16f4170c (patch) | |
tree | dbd390af7b7fd8d79d132e146d25f6f7985b01d6 /paste | |
parent | 5d3719a2929012c8eab1827fc14dcd4a17bae6bd (diff) | |
download | pastedeploy-65b5b5de85b2afb7d792608fa2be915d16f4170c.tar.gz |
Copy the one bit of code we share with Paste core over (or should it use svn:externals?)
Diffstat (limited to 'paste')
-rw-r--r-- | paste/deploy/__init__.py | 7 | ||||
-rw-r--r-- | paste/deploy/config.py | 4 | ||||
-rw-r--r-- | paste/deploy/util/__init__.py | 1 | ||||
-rw-r--r-- | paste/deploy/util/threadinglocal.py | 39 |
4 files changed, 47 insertions, 4 deletions
diff --git a/paste/deploy/__init__.py b/paste/deploy/__init__.py index 5c83a6d..1677202 100644 --- a/paste/deploy/__init__.py +++ b/paste/deploy/__init__.py @@ -1,3 +1,8 @@ from loadwsgi import loadapp, loadfilter, loadserver -from config import CONFIG +try: + from config import CONFIG +except ImportError: + # @@: Or should we require Paste? Or should we put threadlocal + # into this package too? + pass diff --git a/paste/deploy/config.py b/paste/deploy/config.py index 23b811d..055a1c2 100644 --- a/paste/deploy/config.py +++ b/paste/deploy/config.py @@ -10,9 +10,7 @@ def local_dict(): try: return config_local.wsgi_dict except NameError: - import pkg_resources - pkg_resources.require('Paste>=0.1') - from paste.util.threadinglocal import local + from paste.deploy.util.threadinglocal import local config_local = local() config_local.wsgi_dict = result = {} return result diff --git a/paste/deploy/util/__init__.py b/paste/deploy/util/__init__.py new file mode 100644 index 0000000..792d600 --- /dev/null +++ b/paste/deploy/util/__init__.py @@ -0,0 +1 @@ +# diff --git a/paste/deploy/util/threadinglocal.py b/paste/deploy/util/threadinglocal.py new file mode 100644 index 0000000..57afa17 --- /dev/null +++ b/paste/deploy/util/threadinglocal.py @@ -0,0 +1,39 @@ +# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) +# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php + +try: + import threading +except ImportError: + # No threads, so "thread local" means process-global + class local(object): + pass +else: + try: + local = threading.local + except AttributeError: + # Added in 2.4, but now we'll have to define it ourselves + import thread + class local(object): + + def __init__(self): + self.__dict__['__objs'] = {} + + def __getattr__(self, attr, g=thread.get_ident): + try: + return self.__dict__['__objs'][g()][attr] + except KeyError: + raise AttributeError( + "No variable %s defined for the thread %s" + % (attr, g())) + + def __setattr__(self, attr, value, g=thread.get_ident): + self.__dict__['__objs'].setdefault(g(), {})[attr] = value + + def __delattr__(self, attr, g=thread.get_ident): + try: + del self.__dict__['__objs'][g()][attr] + except KeyError: + raise AttributeError( + "No variable %s defined for thread %s" + % (attr, g())) + |