fix syntax of unicode raw string in Python 3
This commit is contained in:
parent
36dcbd7715
commit
e82bc9363f
|
@ -39,12 +39,15 @@ Library for reading and manipulating Ant JUnit XML result files.
|
|||
|
||||
from __future__ import print_function
|
||||
|
||||
import codecs
|
||||
import os
|
||||
import sys
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
python2 = True
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
python2 = False
|
||||
import string
|
||||
import codecs
|
||||
import re
|
||||
|
@ -56,7 +59,14 @@ from xml.dom import Node as DomNode
|
|||
from functools import reduce
|
||||
import rospkg
|
||||
|
||||
invalid_chars = re.compile(ur'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\xFF\u0100-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]')
|
||||
pattern = r'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\xFF\u0100-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]'
|
||||
if python2:
|
||||
pattern = pattern.decode('unicode_escape')
|
||||
else:
|
||||
pattern = codecs.decode(pattern, 'unicode_escape')
|
||||
invalid_chars = re.compile(pattern)
|
||||
|
||||
|
||||
def invalid_char_replacer(m):
|
||||
return "&#x"+('%04X' % ord(m.group(0)))+";"
|
||||
def filter_nonprintable_text(text):
|
||||
|
|
|
@ -9,6 +9,7 @@ from __future__ import print_function
|
|||
|
||||
__revision__ = "$Id$"
|
||||
|
||||
import codecs
|
||||
import os.path
|
||||
import re
|
||||
import sys
|
||||
|
@ -17,8 +18,10 @@ import traceback
|
|||
import unittest
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
python2 = True
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
python2 = False
|
||||
from xml.sax.saxutils import escape
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
@ -159,7 +162,13 @@ class _XMLTestResult(unittest.TestResult):
|
|||
self._failure = err
|
||||
|
||||
def filter_nonprintable_text(self, text):
|
||||
invalid_chars = re.compile(ur'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\xFF\u0100-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]')
|
||||
pattern = r'[^\x09\x0A\x0D\x20-\x7E\x85\xA0-\xFF\u0100-\uD7FF\uE000-\uFDCF\uFDE0-\uFFFD]'
|
||||
if python2:
|
||||
pattern = pattern.decode('unicode_escape')
|
||||
else:
|
||||
pattern = codecs.decode(pattern, 'unicode_escape')
|
||||
invalid_chars = re.compile(pattern)
|
||||
|
||||
def invalid_char_replacer(m):
|
||||
return "&#x"+('%04X' % ord(m.group(0)))+";"
|
||||
return re.sub(invalid_chars, invalid_char_replacer, str(text))
|
||||
|
|
Loading…
Reference in New Issue