Skip to content

Commit 04e4556

Browse files
fangerertimfel
authored andcommitted
Add shim for module '_contextvars'.
1 parent 8be1e02 commit 04e4556

File tree

3 files changed

+131
-2
lines changed

3 files changed

+131
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/Python3Core.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import com.oracle.graal.python.builtins.modules.BuiltinFunctions;
5353
import com.oracle.graal.python.builtins.modules.CodecsModuleBuiltins;
5454
import com.oracle.graal.python.builtins.modules.CollectionsModuleBuiltins;
55+
import com.oracle.graal.python.builtins.modules.ContextvarsModuleBuiltins;
5556
import com.oracle.graal.python.builtins.modules.CtypesModuleBuiltins;
5657
import com.oracle.graal.python.builtins.modules.ErrnoModuleBuiltins;
5758
import com.oracle.graal.python.builtins.modules.FaulthandlerModuleBuiltins;
@@ -227,7 +228,8 @@ private static final String[] initializeCoreFiles() {
227228
"zipimport",
228229
"mmap",
229230
"_queue",
230-
"_ast"));
231+
"_ast",
232+
"_contextvars"));
231233

232234
return coreFiles.toArray(new String[coreFiles.size()]);
233235
}
@@ -338,7 +340,8 @@ private static final PythonBuiltins[] initializeBuiltins() {
338340
new ThreadModuleBuiltins(),
339341
new ThreadBuiltins(),
340342
new LockBuiltins(),
341-
new RLockBuiltins()));
343+
new RLockBuiltins(),
344+
new ContextvarsModuleBuiltins()));
342345
if (!TruffleOptions.AOT) {
343346
ServiceLoader<PythonBuiltins> providers = ServiceLoader.load(PythonBuiltins.class);
344347
for (PythonBuiltins builtin : providers) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* The Universal Permissive License (UPL), Version 1.0
6+
*
7+
* Subject to the condition set forth below, permission is hereby granted to any
8+
* person obtaining a copy of this software, associated documentation and/or
9+
* data (collectively the "Software"), free of charge and under any and all
10+
* copyright rights in the Software, and any and all patent rights owned or
11+
* freely licensable by each licensor hereunder covering either (i) the
12+
* unmodified Software as contributed to or provided by such licensor, or (ii)
13+
* the Larger Works (as defined below), to deal in both
14+
*
15+
* (a) the Software, and
16+
*
17+
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
18+
* one is included with the Software each a "Larger Work" to which the Software
19+
* is contributed by such licensors),
20+
*
21+
* without restriction, including without limitation the rights to copy, create
22+
* derivative works of, display, perform, and distribute the Software and make,
23+
* use, sell, offer for sale, import, export, have made, and have sold the
24+
* Software and the Larger Work(s), and to sublicense the foregoing rights on
25+
* either these or other terms.
26+
*
27+
* This license is subject to the following condition:
28+
*
29+
* The above copyright notice and either this complete permission notice or at a
30+
* minimum a reference to the UPL must be included in all copies or substantial
31+
* portions of the Software.
32+
*
33+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39+
* SOFTWARE.
40+
*/
41+
package com.oracle.graal.python.builtins.modules;
42+
43+
import java.util.Collections;
44+
import java.util.List;
45+
46+
import com.oracle.graal.python.builtins.CoreFunctions;
47+
import com.oracle.graal.python.builtins.PythonBuiltins;
48+
import com.oracle.graal.python.nodes.function.PythonBuiltinBaseNode;
49+
import com.oracle.truffle.api.dsl.NodeFactory;
50+
51+
@CoreFunctions(defineModule = "_contextvars")
52+
public class ContextvarsModuleBuiltins extends PythonBuiltins {
53+
54+
@Override
55+
protected List<? extends NodeFactory<? extends PythonBuiltinBaseNode>> getNodeFactories() {
56+
return Collections.emptyList();
57+
}
58+
59+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
2+
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
3+
#
4+
# The Universal Permissive License (UPL), Version 1.0
5+
#
6+
# Subject to the condition set forth below, permission is hereby granted to any
7+
# person obtaining a copy of this software, associated documentation and/or
8+
# data (collectively the "Software"), free of charge and under any and all
9+
# copyright rights in the Software, and any and all patent rights owned or
10+
# freely licensable by each licensor hereunder covering either (i) the
11+
# unmodified Software as contributed to or provided by such licensor, or (ii)
12+
# the Larger Works (as defined below), to deal in both
13+
#
14+
# (a) the Software, and
15+
#
16+
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
17+
# one is included with the Software each a "Larger Work" to which the Software
18+
# is contributed by such licensors),
19+
#
20+
# without restriction, including without limitation the rights to copy, create
21+
# derivative works of, display, perform, and distribute the Software and make,
22+
# use, sell, offer for sale, import, export, have made, and have sold the
23+
# Software and the Larger Work(s), and to sublicense the foregoing rights on
24+
# either these or other terms.
25+
#
26+
# This license is subject to the following condition:
27+
#
28+
# The above copyright notice and either this complete permission notice or at a
29+
# minimum a reference to the UPL must be included in all copies or substantial
30+
# portions of the Software.
31+
#
32+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
33+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
34+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
35+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
36+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
37+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
38+
# SOFTWARE.
39+
40+
class Context:
41+
pass
42+
43+
44+
class ContextVar:
45+
def __init__(self, name, default=None):
46+
self._name = name
47+
self._value = default
48+
49+
def get(self):
50+
if self._value is None:
51+
raise LookupError
52+
return self._value
53+
54+
def set(self, value):
55+
self._value = value
56+
57+
def reset(self, token):
58+
pass
59+
60+
61+
class Token:
62+
pass
63+
64+
65+
def copy_context():
66+
raise NotImplementedError
67+

0 commit comments

Comments
 (0)