diff --git a/Makefile b/Makefile index 1bf5d3d99..4dfc01271 100644 --- a/Makefile +++ b/Makefile @@ -62,7 +62,7 @@ endif all: $(BINARIES) $(HOOKSRC): $(SIGS) $(FLAGS) $(JINJA2) $(HOOKREQ) $(YAML) - python2 utils/process.py $(RELMODE) --apis=$(APIS) + python utils/process.py $(RELMODE) --apis=$(APIS) $(INSNSSRC) $(FLAGSRC): $(HOOKSRC) diff --git a/test/unittest.py b/test/unittest.py index 7b04cf463..bd854d31c 100755 --- a/test/unittest.py +++ b/test/unittest.py @@ -69,7 +69,7 @@ def __getattr__(self, name): def compile_file(fname, arch): kw = Dict(DEFAULTS) - for line in open(fname, 'rb'): + for line in open(fname, 'r'): if not line.startswith('///'): continue @@ -97,7 +97,7 @@ def compile_file(fname, arch): continue # Write extra configuration to the config.yml file. - with open(os.path.join(arch, "config.yml"), "a+b") as f: + with open(os.path.join(arch, "config.yml"), "a+") as f: if kw.FINISH == 'yes' or kw.PIPE == 'yes' or kw.FREE == 'yes': f.write("%s:\n" % fname[:-2]) f.write(" options:\n") @@ -137,7 +137,7 @@ def compile_file(fname, arch): lines += compile_file(fname, 'x86') lines += compile_file(fname, 'x64') - with open(os.path.join(curdir, 'Makefile'), 'wb') as f: + with open(os.path.join(curdir, 'Makefile'), 'w') as f: f.write('MAKEFLAGS = -j8\n') f.write('all: %s\n' % ' '.join(ALL)) f.write('clean:\n\trm -f %s\n\n' % ' '.join(ALL)) diff --git a/utils/process.py b/utils/process.py index b49a54f03..41b1166d3 100755 --- a/utils/process.py +++ b/utils/process.py @@ -27,6 +27,7 @@ import os import sys import yaml +from yaml import Loader class DefinitionProcessor(object): def __init__(self, data_dir): @@ -42,14 +43,15 @@ def read_document(self, sig): doc = docutils.utils.new_document(os.path.basename(sig), self.parser_settings()) parser = docutils.parsers.rst.Parser() - parser.parse(open(sig, 'rb').read(), doc) + with open(sig, 'r') as fin: + parser.parse(fin.read(), doc) return parser def template(self, name): return self.templ_env.get_template('%s.jinja2' % name) def render(self, template, path, **kwargs): - with open(path, 'wb') as f: + with open(path, 'w') as f: f.write(self.template(template).render(**kwargs)) @@ -77,22 +79,22 @@ def __init__(self, data_dir, out_dir, sig_dirpath, flags, insns): self.sig_dirpath = sig_dirpath self.types = {} - for line in open(types_path, 'rb'): + for line in open(types_path, 'r'): key, value = line.split('=', 1) self.types[key.strip()] = value.strip() self.is_success = {} - for line in open(is_success_path, 'rb'): + for line in open(is_success_path, 'r'): key, value = line.split('=', 1) self.is_success[key.strip()] = value.strip() self.dereference = {} - for line in open(dereference_path, 'rb'): + for line in open(dereference_path, 'r'): key, value = line.split('=', 1) self.dereference[key.strip()] = value.strip() self.base_sigs = [] - for entry in json.load(open(base_sigs_path, 'rb')): + for entry in json.load(open(base_sigs_path, 'r')): entry['is_hook'] = False entry['signature']['special'] = False for param in entry['parameters']: @@ -295,15 +297,14 @@ def normalize(self, doc): children = entry.children if apiname.startswith('_'): - print>>sys.stderr, \ - 'Skipping ignored API Signature:', apiname[1:] + print('Skipping ignored API Signature:', apiname[1:], file=sys.stderr) continue row = copy.deepcopy(global_values) row['apiname'] = apiname - for x in xrange(1, len(children), 2): + for x in range(1, len(children), 2): try: key, value = self._parse_paragraph(children[x], children[x+1]) @@ -506,11 +507,11 @@ def list_categories(self): category = sig['signature']['category'] if category not in categories: categories[category] = None - print category + print(category) def list_apis(self): for sig in self.sigs: - print sig['signature']['category'], sig['apiname'] + print(sig['signature']['category'], sig['apiname']) class FlagsProcessor(object): def __init__(self, data_dir, output_directory): @@ -556,7 +557,7 @@ def normalize(self, doc): row = dict(name=flagname, value=[], enum=[]) - for x in xrange(1, len(children), 2): + for x in range(1, len(children), 2): try: key, value = self._parse_paragraph(children[x], children[x+1]) @@ -627,7 +628,7 @@ def parse_logging(self, l): if not l: return [] - if isinstance(l, basestring): + if isinstance(l, str): l = [l] r = [] @@ -666,7 +667,7 @@ def make_signature(self, arguments): def process(self): methods = [] for filepath in self.insnfiles: - doc = yaml.load(open(filepath, "rb")) + doc = yaml.load(open(filepath, "r"), Loader=Loader) if not doc: continue glob = doc.pop("global", {}) @@ -728,7 +729,8 @@ def write(self, apis): "methods": self.methods, "modules": self.modules, }) - open(self.outfile, "wb").write(content) + with open(self.outfile, "w") as fout: + fout.write(content) def render(self, docname, apis, variables, dirpath="data/"): for method in self.methods: