Skip to content

Commit afe785b

Browse files
committed
Jython 2.7.1+ compatibility on Windows. Fixes robotframework#3364.
1 parent e8acf4b commit afe785b

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

atest/robot/rebot/filter_by_names.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ ${INPUT FILE} %{TEMPDIR}${/}robot-test-file.xml
7070
... --name CustomName --suite nonex ${INPUT FILE} ${INPUT FILE}
7171

7272
--suite and --test together
73-
Run And Check Suites and Tests --suite tsuite1 --suite tsuite3 --test *1first --test *2* Tsuite1 Suite1 First
73+
Run And Check Suites and Tests --suite tsuite1 --suite tsuite3 --test *1first --test nomatch Tsuite1 Suite1 First
7474

7575
--suite and --test together not matching
7676
Failing Rebot

src/robot/utils/encoding.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,15 @@ def system_encode(string, errors='replace'):
8686

8787
else:
8888

89+
# Jython 2.7.1+ uses UTF-8 with cli args etc. regardless the actual system
90+
# encoding. Cannot set the "real" SYSTEM_ENCODING to that value because
91+
# we use it also for other purposes.
92+
_SYSTEM_ENCODING = SYSTEM_ENCODING if not JYTHON else 'UTF-8'
93+
8994
def system_decode(string):
9095
"""Decodes bytes from system (e.g. cli args or env vars) to Unicode."""
9196
try:
92-
return string.decode(SYSTEM_ENCODING)
97+
return string.decode(_SYSTEM_ENCODING)
9398
except UnicodeError:
9499
return unic(string)
95100

@@ -100,4 +105,4 @@ def system_encode(string, errors='replace'):
100105
"""
101106
if not is_unicode(string):
102107
string = unic(string)
103-
return string.encode(SYSTEM_ENCODING, errors)
108+
return string.encode(_SYSTEM_ENCODING, errors)

src/robot/utils/encodingsniffer.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,19 @@ def _get_encoding(platform_getters, default):
5353

5454

5555
def _get_python_system_encoding():
56-
# `locale.getpreferredencoding(False)` returns exactly what we want, but
57-
# it doesn't seem to work outside Windows on Python 2. Luckily on these
56+
# `locale.getpreferredencoding(False)` should return exactly what we want,
57+
# but it doesn't seem to work outside Windows on Python 2. Luckily on these
5858
# platforms `sys.getfilesystemencoding()` seems to do the right thing.
59+
# Jython 2.7.1+ actually uses UTF-8 regardless the system encoding, but
60+
# that's handled by `system_decode/encode` utilities separately.
5961
if PY2 and not WINDOWS:
6062
return sys.getfilesystemencoding()
6163
return locale.getpreferredencoding(False)
6264

6365

6466
def _get_java_system_encoding():
67+
# This is only used with Jython 2.7.0, others get encoding already
68+
# from `_get_python_system_encoding`.
6569
from java.lang import System
6670
return System.getProperty('file.encoding')
6771

0 commit comments

Comments
 (0)