summaryrefslogtreecommitdiff
path: root/repoze/bfg/threadlocal.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-10-25 10:29:31 -0400
committerChris McDonough <chrism@plope.com>2010-10-25 10:29:31 -0400
commit64372401084889a440c9d990a0febc221e3e4b5c (patch)
treec8939a341505d19f19fa6918d264b4e1d95326f8 /repoze/bfg/threadlocal.py
parentc8e78c2037806f3e5dab57de635bf80865b7061d (diff)
downloadpyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.gz
pyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.bz2
pyramid-64372401084889a440c9d990a0febc221e3e4b5c.zip
first pass at converting bfg to pyramid namespace
Diffstat (limited to 'repoze/bfg/threadlocal.py')
-rw-r--r--repoze/bfg/threadlocal.py61
1 files changed, 0 insertions, 61 deletions
diff --git a/repoze/bfg/threadlocal.py b/repoze/bfg/threadlocal.py
deleted file mode 100644
index 631cca62a..000000000
--- a/repoze/bfg/threadlocal.py
+++ /dev/null
@@ -1,61 +0,0 @@
-import threading
-
-from repoze.bfg.registry import global_registry
-
-class ThreadLocalManager(threading.local):
- def __init__(self, default=None):
- # http://code.google.com/p/google-app-engine-django/issues/detail?id=119
- # we *must* use a keword argument for ``default`` here instead
- # of a positional argument to work around a bug in the
- # implementation of _threading_local.local in Python, which is
- # used by GAE instead of _thread.local
- self.stack = []
- self.default = default
-
- def push(self, info):
- self.stack.append(info)
-
- set = push # b/c
-
- def pop(self):
- if self.stack:
- return self.stack.pop()
-
- def get(self):
- try:
- return self.stack[-1]
- except IndexError:
- return self.default()
-
- def clear(self):
- self.stack[:] = []
-
-def defaults():
- return {'request':None, 'registry':global_registry}
-
-manager = ThreadLocalManager(default=defaults)
-
-def get_current_request():
- """Return the currently active request or ``None`` if no request
- is currently active.
-
- This function should be used *extremely sparingly*, usually only
- in unit testing code. it's almost always usually a mistake to use
- ``get_current_request`` outside a testing context because its
- usage makes it possible to write code that can be neither easily
- tested nor scripted.
- """
- return manager.get()['request']
-
-def get_current_registry(context=None): # context required by getSiteManager API
- """Return the currently active :term:`application registry` or the
- global application registry if no request is currently active.
-
- This function should be used *extremely sparingly*, usually only
- in unit testing code. it's almost always usually a mistake to use
- ``get_current_registry`` outside a testing context because its
- usage makes it possible to write code that can be neither easily
- tested nor scripted.
- """
- return manager.get()['registry']
-