[tools] More on py3 compatibility
This commit is contained in:
parent
0cf050a7b1
commit
e17fd0d91c
|
@ -19,13 +19,8 @@ case, the fallback behavior will choose the right tag anyway.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
try:
|
from html.parser import HTMLParser
|
||||||
from HTMLParser import HTMLParser
|
def write (s):
|
||||||
def write (s):
|
|
||||||
print (s.encode ('utf-8'), end='')
|
|
||||||
except ImportError:
|
|
||||||
from html.parser import HTMLParser
|
|
||||||
def write (s):
|
|
||||||
sys.stdout.flush ()
|
sys.stdout.flush ()
|
||||||
sys.stdout.buffer.write (s.encode ('utf-8'))
|
sys.stdout.buffer.write (s.encode ('utf-8'))
|
||||||
import io
|
import io
|
||||||
|
@ -42,13 +37,9 @@ Input files, as of Unicode 12:
|
||||||
* https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry''', file=sys.stderr)
|
* https://www.iana.org/assignments/language-subtag-registry/language-subtag-registry''', file=sys.stderr)
|
||||||
sys.exit (1)
|
sys.exit (1)
|
||||||
|
|
||||||
try:
|
from html import unescape
|
||||||
from html import unescape
|
def html_unescape (parser, entity):
|
||||||
def html_unescape (parser, entity):
|
|
||||||
return unescape (entity)
|
return unescape (entity)
|
||||||
except ImportError:
|
|
||||||
def html_unescape (parser, entity):
|
|
||||||
return parser.unescape (entity)
|
|
||||||
|
|
||||||
def expect (condition, message=None):
|
def expect (condition, message=None):
|
||||||
if not condition:
|
if not condition:
|
||||||
|
|
|
@ -10,13 +10,8 @@ This function should be used as the ``preprocess_text`` of an
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
try:
|
from html.parser import HTMLParser
|
||||||
from HTMLParser import HTMLParser
|
def write (s):
|
||||||
def write (s):
|
|
||||||
print (s.encode ('utf-8'), end='')
|
|
||||||
except ImportError:
|
|
||||||
from html.parser import HTMLParser
|
|
||||||
def write (s):
|
|
||||||
sys.stdout.flush ()
|
sys.stdout.flush ()
|
||||||
sys.stdout.buffer.write (s.encode ('utf-8'))
|
sys.stdout.buffer.write (s.encode ('utf-8'))
|
||||||
import itertools
|
import itertools
|
||||||
|
|
|
@ -4,7 +4,7 @@ from hb_test_tools import *
|
||||||
import sys, os
|
import sys, os
|
||||||
|
|
||||||
if len (sys.argv) < 2:
|
if len (sys.argv) < 2:
|
||||||
print "usage: %s FILES..." % sys.argv[0]
|
print ("usage: %s FILES..." % sys.argv[0])
|
||||||
sys.exit (1)
|
sys.exit (1)
|
||||||
|
|
||||||
ZipDiffer.diff_files (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:])
|
ZipDiffer.diff_files (FileHelpers.open_file_or_stdin (f) for f in sys.argv[1:])
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import sys, os, re, difflib, unicodedata, errno, cgi
|
import sys, os, re, difflib, unicodedata, errno, cgi, itertools
|
||||||
from itertools import *
|
from itertools import *
|
||||||
try:
|
try:
|
||||||
import unicodedata2 as unicodedata
|
import unicodedata2 as unicodedata
|
||||||
|
@ -139,7 +139,7 @@ class ZipDiffer:
|
||||||
def diff_files (files, symbols=diff_symbols):
|
def diff_files (files, symbols=diff_symbols):
|
||||||
files = tuple (files) # in case it's a generator, copy it
|
files = tuple (files) # in case it's a generator, copy it
|
||||||
try:
|
try:
|
||||||
for lines in izip_longest (*files):
|
for lines in itertools.zip_longest (*files):
|
||||||
if all (lines[0] == line for line in lines[1:]):
|
if all (lines[0] == line for line in lines[1:]):
|
||||||
sys.stdout.writelines ([" ", lines[0]])
|
sys.stdout.writelines ([" ", lines[0]])
|
||||||
continue
|
continue
|
||||||
|
@ -433,7 +433,7 @@ class Unicode:
|
||||||
s = re.sub (r"[<+>\\uU]", " ", s)
|
s = re.sub (r"[<+>\\uU]", " ", s)
|
||||||
s = re.sub (r"0[xX]", " ", s)
|
s = re.sub (r"0[xX]", " ", s)
|
||||||
s = [chr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)]
|
s = [chr (int (x, 16)) for x in re.split ('[, \n]', s) if len (x)]
|
||||||
return ' + '.join (Unicode.pretty_name (x) for x in s).encode ('utf-8')
|
return ' + '.join (Unicode.pretty_name (x) for x in s)
|
||||||
|
|
||||||
|
|
||||||
class FileHelpers:
|
class FileHelpers:
|
||||||
|
|
Loading…
Reference in New Issue