[pypy-commit] pypy decimal-libmpdec: Add missing file

amauryfa noreply at buildbot.pypy.org
Sun Aug 24 23:20:17 CEST 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: decimal-libmpdec
Changeset: r73051:b763ba8d4b7e
Date: 2014-08-24 23:19 +0200
http://bitbucket.org/pypy/pypy/changeset/b763ba8d4b7e/

Log:	Add missing file

diff --git a/pypy/module/_decimal/app_context.py b/pypy/module/_decimal/app_context.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_decimal/app_context.py
@@ -0,0 +1,17 @@
+from _decimal import getcontext, setcontext
+
+class _ContextManager(object):
+    """Context manager class to support localcontext()."""
+    def __init__(self, new_context):
+        self.new_context = new_context.copy()
+    def __enter__(self):
+        self.saved_context = getcontext()
+        setcontext(self.new_context)
+        return self.new_context
+    def __exit__(self, t, v, tb):
+        setcontext(self.saved_context)
+
+def localcontext(ctx=None):
+    if ctx is None:
+        ctx = getcontext()
+    return _ContextManager(ctx)


More information about the pypy-commit mailing list