Skip to content

Commit

Permalink
Use language-neutral locale to infer Python class name
Browse files Browse the repository at this point in the history
We have long inferred the Python class name of many built-in classes
from the Java implementation class name by truncation and toLowerCase().
This fails e.g. for "PyNotImplemented" in a Turkish locale where the
lower-case of I is ı (dotless i). Thanks to Xiaoyin Liu for identifying
the cause. We therefore use the language neutral "root" locale.

Quite probably fixes jython#159.
  • Loading branch information
jeff5 committed Jul 8, 2022
1 parent 87f92b8 commit 257d6cb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Jython 2.7.3a1
- [ GH-178 ] Update icu4j JAR to 71.1
- [ GH-177 ] Update Ant to 1.10.12 (Gradle build) (CVE-2020-1945, 2021-36374)
- [ GH-160 ] Improve context of "Cannot create PyString with non-byte value"
- [ GH-159 ] Non-byte PyString error during initialisation in Turkish locale
- [ GH-158 ] Upgrade Bouncy Castle to 1.71
- [ GH-157 ] Upgrade ASM to 9.3
- [ GH-156 ] Replace custom SHA224 digest with Java's
Expand Down
14 changes: 8 additions & 6 deletions src/org/python/core/PyJavaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// Licensed to PSF under a Contributor Agreement.
package org.python.core;

import org.python.core.util.StringUtil;
import org.python.util.Generic;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
Expand Down Expand Up @@ -37,15 +34,20 @@
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;

import org.python.core.util.StringUtil;
import org.python.util.Generic;

public class PyJavaType extends PyType {

private final static Class<?>[] OO = {PyObject.class, PyObject.class};
private static final String CORE_PY = "org.python.core.Py";
private static final int CORE_PY_LENGTH = CORE_PY.length();

// @formatter:off
/** Deprecated methods in java.awt.* that have bean property equivalents we prefer. */
Expand Down Expand Up @@ -374,8 +376,8 @@ protected void init(Set<PyJavaType> needsInners) {
name = forClass.getName();

// Strip the java fully qualified class name from Py classes in core
if (name.startsWith("org.python.core.Py")) {
name = name.substring("org.python.core.Py".length()).toLowerCase();
if (name.startsWith(CORE_PY)) {
name = name.substring(CORE_PY_LENGTH).toLowerCase(Locale.ROOT);
}
dict = new PyStringMap();

Expand Down

0 comments on commit 257d6cb

Please sign in to comment.