Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions graalpython/com.oracle.graal.python.test/src/tests/test_codecs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
# Copyright (C) 1996-2017 Python Software Foundation
#
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
import importlib
import importlib.util
import sys
from pathlib import Path


def coding_checker(self, coder):
Expand Down Expand Up @@ -892,6 +895,34 @@ def test_encode_dict_err_xmlcharrefreplace(self):

class MultibyteCodecTest(unittest.TestCase):

def test_missing_multibyte_codecs_raise_lookup_error(self):
for module_name in ('_codecs_cn', '_codecs_hk', '_codecs_iso2022', '_codecs_jp', '_codecs_kr', '_codecs_tw'):
with self.subTest(module_name=module_name):
module = importlib.import_module(module_name)
self.assertRaises(LookupError, module.getcodec, '__missing_codec__')

def test_unsupported_multibyte_codec_modules_raise_import_error_on_graalpy(self):
encodings_dir = Path(__file__).resolve().parents[3] / 'lib-python' / '3' / 'encodings'
for module_name in (
'encodings.euc_jis_2004',
'encodings.euc_jisx0213',
'encodings.iso2022_jp_1',
'encodings.iso2022_jp_2004',
'encodings.iso2022_jp_3',
'encodings.iso2022_jp_ext',
):
with self.subTest(module_name=module_name):
module_path = encodings_dir / f'{module_name.rsplit(".", 1)[1]}.py'
spec = importlib.util.spec_from_file_location(f'test_{module_name.replace(".", "_")}', module_path)
module = importlib.util.module_from_spec(spec)
if sys.implementation.name == 'graalpy':
self.assertRaises(ImportError, spec.loader.exec_module, module)
else:
spec.loader.exec_module(module)

def test_shift_jis_2004_codec_module_imports(self):
import encodings.shift_jis_2004

# just a smoke test
def test_encode(self):
import _codecs_tw
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ private static void addAlias(String alias, String pythonName) {
addMapping("mac_turkish", "x-MacTurkish");
addMapping("palmos", null);
addMapping("ptcp154", null);
addMapping("shift_jis_2004", "Shift_JISX0213");
addMapping("shift_jis_2004", "x-SJIS_0213");
addMapping("shift_jis", "Shift_JIS");
addMapping("shift_jisx0213", "x-SJIS_0213");
addMapping("utf_16_be", "UTF-16BE");
Expand Down Expand Up @@ -438,10 +438,6 @@ private static void addAlias(String alias, String pythonName) {
addAlias("uhc", "cp949");
addAlias("950", "cp950");
addAlias("ms950", "cp950");
addAlias("jisx0213", "euc_jis_2004");
addAlias("eucjis2004", "euc_jis_2004");
addAlias("euc_jis2004", "euc_jis_2004");
addAlias("eucjisx0213", "euc_jisx0213");
addAlias("eucjp", "euc_jp");
addAlias("ujis", "euc_jp");
addAlias("u_jis", "euc_jp");
Expand Down
7 changes: 3 additions & 4 deletions graalpython/lib-python/3/encodings/aliases.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,10 +491,9 @@
's_jis' : 'shift_jis',

# shift_jis_2004 codec
# GraalPy change: Java doesn't have this codec
# 'shiftjis2004' : 'shift_jis_2004',
# 'sjis_2004' : 'shift_jis_2004',
# 's_jis_2004' : 'shift_jis_2004',
'shiftjis2004' : 'shift_jis_2004',
'sjis_2004' : 'shift_jis_2004',
's_jis_2004' : 'shift_jis_2004',

# shift_jisx0213 codec
'shiftjisx0213' : 'shift_jisx0213',
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/euc_jis_2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_jp, codecs
import _multibytecodec as mbc

codec = _codecs_jp.getcodec('euc_jis_2004')
try:
codec = _codecs_jp.getcodec('euc_jis_2004')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/euc_jisx0213.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_jp, codecs
import _multibytecodec as mbc

codec = _codecs_jp.getcodec('euc_jisx0213')
try:
codec = _codecs_jp.getcodec('euc_jisx0213')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/iso2022_jp_1.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_iso2022, codecs
import _multibytecodec as mbc

codec = _codecs_iso2022.getcodec('iso2022_jp_1')
try:
codec = _codecs_iso2022.getcodec('iso2022_jp_1')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/iso2022_jp_2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_iso2022, codecs
import _multibytecodec as mbc

codec = _codecs_iso2022.getcodec('iso2022_jp_2004')
try:
codec = _codecs_iso2022.getcodec('iso2022_jp_2004')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/iso2022_jp_3.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_iso2022, codecs
import _multibytecodec as mbc

codec = _codecs_iso2022.getcodec('iso2022_jp_3')
try:
codec = _codecs_iso2022.getcodec('iso2022_jp_3')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/iso2022_jp_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_iso2022, codecs
import _multibytecodec as mbc

codec = _codecs_iso2022.getcodec('iso2022_jp_ext')
try:
codec = _codecs_iso2022.getcodec('iso2022_jp_ext')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
5 changes: 4 additions & 1 deletion graalpython/lib-python/3/encodings/shift_jis_2004.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
import _codecs_jp, codecs
import _multibytecodec as mbc

codec = _codecs_jp.getcodec('shift_jis_2004')
try:
codec = _codecs_jp.getcodec('shift_jis_2004')
except LookupError as e:
raise ImportError(str(e)) from e

class Codec(codecs.Codec):
encode = codec.encode
Expand Down
Loading