diff options
author | Fedja Beader <fedja@protonmail.ch> | 2023-12-14 01:11:23 +0100 |
---|---|---|
committer | Fedja Beader <fedja@protonmail.ch> | 2024-01-28 17:25:09 +0100 |
commit | f535bec6e5b01ce418bae0c19104947a809e9abf (patch) | |
tree | a205ceba3bdbffcbc07c90c1ed09d3dab4c3811d | |
parent | ad709218a31d49320cde855762d579b4a1edc897 (diff) | |
download | tmwa-f535bec6e5b01ce418bae0c19104947a809e9abf.tar.gz tmwa-f535bec6e5b01ce418bae0c19104947a809e9abf.tar.bz2 tmwa-f535bec6e5b01ce418bae0c19104947a809e9abf.tar.xz tmwa-f535bec6e5b01ce418bae0c19104947a809e9abf.zip |
find src/ tools/ -name '*.py' -execdir 2to3 -w {} \;
-rw-r--r-- | src/main-gdb-head.py | 8 | ||||
-rw-r--r-- | src/map/script-parse.py | 2 | ||||
-rwxr-xr-x | tools/config.py | 8 | ||||
-rwxr-xr-x | tools/protocol.py | 114 |
4 files changed, 66 insertions, 66 deletions
diff --git a/src/main-gdb-head.py b/src/main-gdb-head.py index a465c97..dc688d7 100644 --- a/src/main-gdb-head.py +++ b/src/main-gdb-head.py @@ -5,7 +5,7 @@ # gdb sticks everything in one scope. # This lets us enumerate what *we* added. -initial_globals = {id(v):v for v in globals().values()} +initial_globals = {id(v):v for v in list(globals().values())} import re @@ -54,7 +54,7 @@ def info_symbol(addr): def finish(): global finish, initial_globals, FastPrinters, EnumPrinter, PointerPrinter - final_globals = {id(v):v for v in globals().values()} + final_globals = {id(v):v for v in list(globals().values())} diff = set(final_globals.keys()) - set(initial_globals.keys()) \ - { 'finish', @@ -90,8 +90,8 @@ def finish(): obj.pretty_printers.append(ep) obj.pretty_printers.append(ptrp) n = len(obj.pretty_printers) - n - print('Added %d+%d custom printers for %s' - % (len(fp.printers), n, filename)) + print(('Added %d+%d custom printers for %s' + % (len(fp.printers), n, filename))) class EnumPrinter(object): __slots__ = ('_value') diff --git a/src/map/script-parse.py b/src/map/script-parse.py index 199e348..3346b92 100644 --- a/src/map/script-parse.py +++ b/src/map/script-parse.py @@ -106,7 +106,7 @@ class ScriptBuffer(object): code_begin = code['_M_impl']['_M_start'] code_end = code['_M_impl']['_M_finish'] code_size = int(code_end - code_begin) - r = iter(range(code_size)) + r = iter(list(range(code_size))) for i in r: buf = [] for label in labels_dict.get(i, []): diff --git a/tools/config.py b/tools/config.py index fb9ffe3..2d16979 100755 --- a/tools/config.py +++ b/tools/config.py @@ -20,7 +20,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from __future__ import print_function + import glob import os @@ -259,7 +259,7 @@ class Group(object): short_cpp_name = '%s.cpp' % var_name cpp_name = os.path.join(path, short_cpp_name) - values = sorted(self.options.values(), key=lambda o: o.name) + values = sorted(list(self.options.values()), key=lambda o: o.name) desc = 'Config for %s::%s' % (namespace_name, self.name) with OpenWrite(hpp_name) as hpp, \ @@ -384,7 +384,7 @@ class Realm(object): return rv def dump(self): - for g in self.groups.values(): + for g in list(self.groups.values()): g.dump_in(self.path, self.path.split('/')[-1]) class Everything(object): @@ -401,7 +401,7 @@ class Everything(object): def dump(self): for g in glob.glob('src/*/*_conf.[ch]pp'): os.rename(g, g + '.old') - for v in self.realms.values(): + for v in list(self.realms.values()): v.dump() for g in glob.glob('src/*/*_conf.[ch]pp.old'): print('Obsolete: %s' % g) diff --git a/tools/protocol.py b/tools/protocol.py index cef3acb..9b6f64f 100755 --- a/tools/protocol.py +++ b/tools/protocol.py @@ -20,7 +20,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. -from __future__ import print_function + import glob import itertools @@ -30,9 +30,9 @@ from posixpath import relpath from weakref import ref as wr try: - unicode + str except NameError: - unicode = str + str = str ## For various reasons this is all one file, so let's navigate with a ## @@ -116,30 +116,30 @@ class OpenWrite(object): # TOC_ def gvq(s): - return u'"%s"' % s.replace(u'"', u'\\"') + return '"%s"' % s.replace('"', '\\"') def gva(d): if d: - return u' [%s]' % u', '.join(u'%s=%s' % (ak, gvq(av)) for (ak, av) in sorted(d.items())) - return u'' + return ' [%s]' % ', '.join('%s=%s' % (ak, gvq(av)) for (ak, av) in sorted(d.items())) + return '' class Attributes(object): - __slots__ = (u'_attributes') + __slots__ = ('_attributes') def __init__(self): self._attributes = {} def __getitem__(self, k): - assert isinstance(k, unicode) + assert isinstance(k, str) return self._attributes[k] def __setitem__(self, k, v): - assert isinstance(k, unicode) - assert isinstance(v, unicode) + assert isinstance(k, str) + assert isinstance(v, str) self._attributes[k] = v def __delitem__(self, k): - assert isinstance(k, unicode) + assert isinstance(k, str) del self._attributes[k] def merge(self, *others): @@ -150,7 +150,7 @@ class Attributes(object): self._attributes.update(other._attributes) class Graph(Attributes): - __slots__ = (u'default_vertex', u'default_edge', u'_vertices', u'_edges', u'_vertex_lookup') + __slots__ = ('default_vertex', 'default_edge', '_vertices', '_edges', '_vertex_lookup') def __init__(self): Attributes.__init__(self) @@ -161,7 +161,7 @@ class Graph(Attributes): self._vertex_lookup = {} def vertex(self, name, insert=True): - assert isinstance(name, unicode) + assert isinstance(name, str) vert = self._vertex_lookup.get(name) if insert and vert is None: vert = Vertex(name) @@ -238,21 +238,21 @@ class Graph(Attributes): def p(*args): for x in args: - out.write(unicode(x)) - out.write(u'\n') - p(u'digraph') - p(u'{') + out.write(str(x)) + out.write('\n') + p('digraph') + p('{') for ak, av in sorted(self._attributes.items()): - p(u' ', ak, u'=', gvq(av), u';') + p(' ', ak, '=', gvq(av), ';') for ak, av in sorted(self.default_vertex._attributes.items()): - p(u' node [', ak, u'=', gvq(av), u'];') + p(' node [', ak, '=', gvq(av), '];') for ak, av in sorted(self.default_edge._attributes.items()): - p(u' edge [', ak, u'=', gvq(av), u'];') + p(' edge [', ak, '=', gvq(av), '];') for n in sorted(self._vertices): - p(u' ', n) + p(' ', n) for _, e in sorted(self._edges.items()): - p(u' ', e) - p(u'}') + p(' ', e) + p('}') def dot_str(self): from io import StringIO @@ -261,18 +261,18 @@ class Graph(Attributes): return out.getvalue() def dot_file(self, name): - with open(name, u'w') as f: + with open(name, 'w') as f: self.dot(f, False) def preview(self, block): from subprocess import Popen, PIPE - proc = Popen([u'dot', u'-Txlib', u'/dev/stdin'], stdin=PIPE, universal_newlines=True) + proc = Popen(['dot', '-Txlib', '/dev/stdin'], stdin=PIPE, universal_newlines=True) self.dot(proc.stdin, True) if block: proc.wait() class Vertex(Attributes): - __slots__ = (u'_key', u'_post', u'_pre', u'__weakref__') + __slots__ = ('_key', '_post', '_pre', '__weakref__') def __init__(self, key): Attributes.__init__(self) @@ -281,13 +281,13 @@ class Vertex(Attributes): self._pre = set() def __str__(self): - return u'%s%s;' % (gvq(self._key), gva(self._attributes)) + return '%s%s;' % (gvq(self._key), gva(self._attributes)) def __lt__(self, other): return self._key < other._key class Edge(Attributes): - __slots__ = (u'_from', u'_to') + __slots__ = ('_from', '_to') def __init__(self, f, t): Attributes.__init__(self) @@ -295,7 +295,7 @@ class Edge(Attributes): self._to = t def __str__(self): - return u'%s -> %s%s;' % (gvq(self._from._key), gvq(self._to._key), gva(self._attributes)) + return '%s -> %s%s;' % (gvq(self._from._key), gvq(self._to._key), gva(self._attributes)) # TOC_TYPES @@ -7034,7 +7034,7 @@ def partition(d): changed = True while changed: changed = False - for k, vlist in d.items(): + for k, vlist in list(d.items()): if vlist: m = min(leaders[v] for v in vlist) if m < leaders[k]: @@ -7050,9 +7050,9 @@ def partition(d): leaders[v] = m followers = {} - for k, v in leaders.items(): + for k, v in list(leaders.items()): followers.setdefault(v, []).append(k) - return [set(v) for v in followers.values()] + return [set(v) for v in list(followers.values())] def ids_only(vpost): rv = [e for e in vpost if not isinstance(e, SpecialEventOrigin)] @@ -7075,7 +7075,7 @@ def make_dots(ctx): for g in glob.glob('doc-gen/Packet-*.md'): os.rename(g, g + '.old') - for (id, p) in d.items(): + for (id, p) in list(d.items()): md = 'doc-gen/Packet-0x%04x.md' % id dot = 'doc-gen/packets-around-0x%04x.gv' % id with OpenWrite(md) as f: @@ -7122,16 +7122,16 @@ def make_dots(ctx): covered_nodes = sorted(p.pre_set(d, 2) | p.post_set(d, 2)) covered_edges = [(a, b) for a in covered_nodes for b in covered_nodes if b in d[a].post] g = Graph() - g.default_vertex[u'shape'] = u'box' + g.default_vertex['shape'] = 'box' # g[u'layout'] = u'twopi' # g[u'root'] = u'0x%04x' % id for n in covered_nodes: - v = g.vertex(u'0x%04x' % n) - v[u'label'] = u'Packet \\N: %s' % d[n].name + v = g.vertex('0x%04x' % n) + v['label'] = 'Packet \\N: %s' % d[n].name if n == id: - v[u'style'] = u'filled' + v['style'] = 'filled' for (a, b) in covered_edges: - g.edge(u'0x%04x' % a, u'0x%04x' % b) + g.edge('0x%04x' % a, '0x%04x' % b) for n in covered_nodes: # the center node will be covered specially below if n == id: @@ -7149,10 +7149,10 @@ def make_dots(ctx): # don't show mere siblings unless also ancestor/descendent count += 1 if count: - v = g.vertex(u'0x%04x...pre' % n) - v[u'label'] = u'%d more' % count - v[u'style'] = u'dashed' - g.edge(v, u'0x%04x' % n) + v = g.vertex('0x%04x...pre' % n) + v['label'] = '%d more' % count + v['style'] = 'dashed' + g.edge(v, '0x%04x' % n) # strong forward links count = 0 for p in d[n].post: @@ -7161,36 +7161,36 @@ def make_dots(ctx): elif p not in covered_nodes: count += 1 if count: - v = g.vertex(u'0x%04x...post' % n) - v[u'label'] = u'%d more' % count - v[u'style'] = u'dashed' - g.edge(u'0x%04x' % n, v) + v = g.vertex('0x%04x...post' % n) + v['label'] = '%d more' % count + v['style'] = 'dashed' + g.edge('0x%04x' % n, v) # for the immediate node, also cover specials and weaks for p in d[id].pre: # (there are no weak backward specials) # strong backward specials if isinstance(p, SpecialEventOrigin): - g.edge(unicode(p.name), u'0x%04x' % id) + g.edge(str(p.name), '0x%04x' % id) # weak backward nodes elif id in d[p].xpost: - e = g.edge(u'0x%04x' % p, u'0x%04x' % id) - e[u'style']=u'dashed' - e[u'weight'] = u'0' + e = g.edge('0x%04x' % p, '0x%04x' % id) + e['style']='dashed' + e['weight'] = '0' for p in d[id].post: # strong forward specials if isinstance(p, SpecialEventOrigin): - g.edge(u'0x%04x' % id, unicode(p.name)) + g.edge('0x%04x' % id, str(p.name)) for p in d[id].xpost: # weak forward specials if isinstance(p, SpecialEventOrigin): - e = g.edge(u'0x%04x' % id, unicode(p.name)) - e[u'style'] = u'dashed' - e[u'weight'] = u'0' + e = g.edge('0x%04x' % id, str(p.name)) + e['style'] = 'dashed' + e['weight'] = '0' # weak forward nodes elif p not in covered_nodes: - e = g.edge(u'0x%04x' % id, u'0x%04x' % p) - e[u'style'] = u'dashed' - e[u'weight'] = u'0' + e = g.edge('0x%04x' % id, '0x%04x' % p) + e['style'] = 'dashed' + e['weight'] = '0' g.dot(f, False) |