Skip to content

Commit af3045c

Browse files
timfelsteve-s
authored andcommitted
[GR-47994] fix creating datetime objects when platform access is denied
1 parent f8d7a58 commit af3045c

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

graalpython/com.oracle.graal.python.test/src/com/oracle/graal/python/test/advance/ExclusionsTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,30 @@
4141
package com.oracle.graal.python.test.advance;
4242

4343
import org.graalvm.polyglot.Context;
44+
import org.junit.Test;
4445

4546
public class ExclusionsTest {
4647
public static void main(String[] args) {
4748
try (Context context = Context.create()) {
4849
context.eval("python", "print('Hello Python!');");
4950
}
5051
}
52+
53+
@Test
54+
public void testDatetimeWithoutPlatformAccess() {
55+
if (!"true".equals(System.getProperty("python.WithoutPlatformAccess"))) {
56+
return;
57+
}
58+
var builder = Context.newBuilder().allowExperimentalOptions(true);
59+
if (System.getenv("GRAAL_PYTHONHOME") != null) {
60+
builder.option("python.PythonHome", System.getenv("GRAAL_PYTHONHOME"));
61+
}
62+
try (Context context = builder.build()) {
63+
context.eval("python",
64+
"""
65+
import datetime
66+
datetime.datetime.strptime('2014 7 2 6 14 0 742 +0700', '%Y %m %d %H %M %S %f %z')
67+
""");
68+
}
69+
}
5170
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TimeModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ Object tzset() {
325325
}
326326
TimeZone.setDefault(TimeZone.getTimeZone(tzEnv));
327327
} else {
328-
PRaiseNode.raiseUncached(this, PythonBuiltinClassType.SystemError, SET_TIMEZONE_ERROR);
328+
PRaiseNode.raiseUncached(this, PythonBuiltinClassType.AttributeError, SET_TIMEZONE_ERROR);
329329
}
330330
return PNone.NONE;
331331
}

mx.graalpython/mx_graalpython.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,14 @@ def graalpython_gate_runner(args, tasks):
14121412
)
14131413
else:
14141414
punittest(['--verbose'], report=report())
1415+
# Run tests with static exclusion paths
1416+
jdk = mx.get_jdk()
1417+
prev = jdk.java_args_pfx
1418+
try:
1419+
jdk.java_args_pfx = (mx._opts.java_args or []) + ['-Dpython.WithoutPlatformAccess=true']
1420+
punittest(['--verbose', '--no-leak-tests', '--regex', 'com.oracle.graal.python.test.advance.ExclusionsTest'])
1421+
finally:
1422+
jdk.java_args_pfx = prev
14151423

14161424
# Unittests on JVM
14171425
with Task('GraalPython Python unittests', tasks, tags=[GraalPythonTags.unittest]) as task:

0 commit comments

Comments
 (0)