19
19
import time
20
20
21
21
import py
22
+ import six
22
23
23
24
import pytest
24
25
from _pytest import nodes
27
28
# Python 2.X and 3.X compatibility
28
29
if sys .version_info [0 ] < 3 :
29
30
from codecs import open
30
- else :
31
- unichr = chr
32
- unicode = str
33
- long = int
34
31
35
32
36
33
class Junit (py .xml .Namespace ):
@@ -45,12 +42,12 @@ class Junit(py.xml.Namespace):
45
42
_legal_chars = (0x09 , 0x0A , 0x0D )
46
43
_legal_ranges = ((0x20 , 0x7E ), (0x80 , 0xD7FF ), (0xE000 , 0xFFFD ), (0x10000 , 0x10FFFF ))
47
44
_legal_xml_re = [
48
- unicode ( "%s-%s" ) % (unichr (low ), unichr (high ))
45
+ u "%s-%s" % (six . unichr (low ), six . unichr (high ))
49
46
for (low , high ) in _legal_ranges
50
47
if low < sys .maxunicode
51
48
]
52
- _legal_xml_re = [unichr (x ) for x in _legal_chars ] + _legal_xml_re
53
- illegal_xml_re = re .compile (unicode ( "[^%s]" ) % unicode ( "" ) .join (_legal_xml_re ))
49
+ _legal_xml_re = [six . unichr (x ) for x in _legal_chars ] + _legal_xml_re
50
+ illegal_xml_re = re .compile (u "[^%s]" % u"" .join (_legal_xml_re ))
54
51
del _legal_chars
55
52
del _legal_ranges
56
53
del _legal_xml_re
@@ -62,9 +59,9 @@ def bin_xml_escape(arg):
62
59
def repl (matchobj ):
63
60
i = ord (matchobj .group ())
64
61
if i <= 0xFF :
65
- return unicode ( "#x%02X" ) % i
62
+ return u "#x%02X" % i
66
63
else :
67
- return unicode ( "#x%04X" ) % i
64
+ return u "#x%04X" % i
68
65
69
66
return py .xml .raw (illegal_xml_re .sub (repl , py .xml .escape (arg )))
70
67
@@ -194,7 +191,7 @@ def append_failure(self, report):
194
191
else :
195
192
if hasattr (report .longrepr , "reprcrash" ):
196
193
message = report .longrepr .reprcrash .message
197
- elif isinstance (report .longrepr , ( unicode , str ) ):
194
+ elif isinstance (report .longrepr , six . string_types ):
198
195
message = report .longrepr
199
196
else :
200
197
message = str (report .longrepr )
0 commit comments