Author: Armin Rigo <[email protected]>
Branch: stm-gc
Changeset: r54581:ce0532024f73
Date: 2012-04-20 14:15 +0200
http://bitbucket.org/pypy/pypy/changeset/ce0532024f73/

Log:    Add '__pypy__.local', re-exposing either 'thread._local', or
        'transaction.local', or just a dummy class if we have neither.

diff --git a/pypy/module/__pypy__/__init__.py b/pypy/module/__pypy__/__init__.py
--- a/pypy/module/__pypy__/__init__.py
+++ b/pypy/module/__pypy__/__init__.py
@@ -29,6 +29,7 @@
 
 class Module(MixedModule):
     appleveldefs = {
+        'local'                     : 'app_local.local',
     }
 
     interpleveldefs = {
diff --git a/pypy/module/__pypy__/app_local.py 
b/pypy/module/__pypy__/app_local.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/app_local.py
@@ -0,0 +1,11 @@
+import sys
+
+if 'thread' in sys.builtin_module_names:
+    from thread import _local as local
+elif 'transaction' in sys.builtin_module_names:
+    from transaction import local
+else:
+    class local(object):
+        """A pseudo-thread-local class.
+        As this interpreter does not have threads, it is a regular class.
+        """
diff --git a/pypy/module/__pypy__/test/test_local.py 
b/pypy/module/__pypy__/test/test_local.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/__pypy__/test/test_local.py
@@ -0,0 +1,19 @@
+import py
+from pypy.conftest import gettestobjspace
+
+
+class AppTestLocal(object):
+    def test_local(self):
+        import __pypy__
+        x = __pypy__.local()
+        x.foo = 42
+        assert x.foo == 42     # hard to test more :-)
+
+
+class AppTestLocalWithThreads(object):
+    def setup_class(cls):
+        cls.space = gettestobjspace(usemodules=['thread'])
+
+    def test_local(self):
+        import __pypy__, thread
+        assert __pypy__.local is thread._local
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to