|
1 | 1 | from __future__ import absolute_import, division, unicode_literals
|
2 | 2 |
|
3 |
| -import platform |
4 | 3 | from types import ModuleType
|
5 | 4 |
|
| 5 | +from six import text_type |
| 6 | + |
6 | 7 | try:
|
7 | 8 | import xml.etree.cElementTree as default_etree
|
8 | 9 | except ImportError:
|
|
15 | 16 |
|
16 | 17 |
|
17 | 18 | # Platforms not supporting lone surrogates (\uD800-\uDFFF) should be
|
18 |
| -# added to the below test. In general this would be any platform using |
19 |
| -# UTF-16 as its encoding of unicode strings, such as Jython. This is |
20 |
| -# because UTF-16 itself is based on the use of such surrogates, and |
21 |
| -# there is no mechanism to further escape such escapes. |
22 |
| -# |
23 |
| -# Otherwise we assume such support. |
24 |
| -supports_lone_surrogates = platform.python_implementation() != "Jython" |
| 19 | +# caught by the below test. In general this would be any platform |
| 20 | +# using UTF-16 as its encoding of unicode strings, such as |
| 21 | +# Jython. This is because UTF-16 itself is based on the use of such |
| 22 | +# surrogates, and there is no mechanism to further escape such |
| 23 | +# escapes. |
| 24 | +try: |
| 25 | + _x = eval('"\\uD800"') |
| 26 | + if not isinstance(_x, text_type): |
| 27 | + # We need this with u"" because of http://bugs.jython.org/issue2039 |
| 28 | + _x = eval('u"\\uD800"') |
| 29 | + assert isinstance(_x, text_type) |
| 30 | +except: |
| 31 | + supports_lone_surrogates = False |
| 32 | +else: |
| 33 | + supports_lone_surrogates = True |
25 | 34 |
|
26 | 35 |
|
27 | 36 | class MethodDispatcher(dict):
|
|
0 commit comments