Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita60f7a1

Browse files
anishathalyeingydotnet
authored andcommitted
Fix compatibility with Jython
This patch was taken from#369 (comment),authored by Pekka Klärck <peke@iki.fi>.In short, Jython doesn't support lone surrogates, so importing yaml (andin particular, loading `reader.py`) caused a UnicodeDecodeError. Thispatch works around this through a clever use of `eval` to deferevaluation of the string containing the lone surrogates, only doing iton non-Jython platforms.This is only done in `lib/yaml/reader.py` and not `lib3/yaml/reader.py`because Jython does not support Python 3.With this patch, Jython's behavior with respect to Unicode code pointsover 0xFFFF becomes as it was before0716ae2. It still does not pass all theunit tests on Jython (passes 1275, fails 3, errors on 1); all thefailing tests are related to unicode. Still, this is better than simplycrashing upon `import yaml`.With this patch, all tests continue to pass on Python 2 / Python 3.
1 parentee98abd commita60f7a1

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

‎lib/yaml/reader.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,14 @@ def determine_encoding(self):
137137
self.update(1)
138138

139139
ifhas_ucs4:
140-
NON_PRINTABLE=re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]')
140+
NON_PRINTABLE=u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD\U00010000-\U0010ffff]'
141+
elifsys.platform.startswith('java'):
142+
# Jython doesn't support lone surrogates https://bugs.jython.org/issue2048
143+
NON_PRINTABLE=u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uD7FF\uE000-\uFFFD]'
141144
else:
142-
NON_PRINTABLE=re.compile(u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uFFFD]|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)')
145+
# Need to use eval here due to the above Jython issue
146+
NON_PRINTABLE=eval(r"u'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\uFFFD]|(?:^|[^\uD800-\uDBFF])[\uDC00-\uDFFF]|[\uD800-\uDBFF](?:[^\uDC00-\uDFFF]|$)'")
147+
NON_PRINTABLE=re.compile(NON_PRINTABLE)
143148
defcheck_printable(self,data):
144149
match=self.NON_PRINTABLE.search(data)
145150
ifmatch:

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp