summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorFreeyorp <TheFreeYorp+git@gmail.com>2024-06-05 20:08:39 +0000
committerFreeyorp <TheFreeYorp+git@gmail.com>2024-06-05 23:57:13 +0000
commitf5500cd949e6db20813c3bbec9cef66284866209 (patch)
treeae08eaa21ef4ba4c65612cb70f673b2017322632 /tools
parent36562d847999730634663d8a80c3cfdff36bd027 (diff)
downloadtmwa-f5500cd949e6db20813c3bbec9cef66284866209.tar.gz
tmwa-f5500cd949e6db20813c3bbec9cef66284866209.tar.bz2
tmwa-f5500cd949e6db20813c3bbec9cef66284866209.tar.xz
tmwa-f5500cd949e6db20813c3bbec9cef66284866209.zip
python3: Update names
- unicode -> str - u'' -> '' - cStringIO -> io Sourced from specing's work on the porting process. See https://git.themanaworld.org/legacy/tmwa/-/merge_requests/256
Diffstat (limited to 'tools')
-rwxr-xr-xtools/indenter4
-rwxr-xr-xtools/protocol.py109
2 files changed, 54 insertions, 59 deletions
diff --git a/tools/indenter b/tools/indenter
index 1d44581..ee000da 100755
--- a/tools/indenter
+++ b/tools/indenter
@@ -22,7 +22,7 @@
from collections import namedtuple
-import cStringIO
+import io
import string
import subprocess
import sys
@@ -113,7 +113,7 @@ class Reader(object):
self._column += 1
def string_reader(s, name='<string>', line=1, column=1):
- return Reader(name, cStringIO.StringIO(s), line, column)
+ return Reader(name, io.StringIO(s), line, column)
def take_while(b, r, s):
assert isinstance(b, bytearray)
diff --git a/tools/protocol.py b/tools/protocol.py
index 86515d2..8059c59 100755
--- a/tools/protocol.py
+++ b/tools/protocol.py
@@ -27,11 +27,6 @@ from pipes import quote
from posixpath import relpath
from weakref import ref as wr
-try:
- unicode
-except NameError:
- unicode = str
-
## For various reasons this is all one file, so let's navigate with a
##
## Table of Contents
@@ -114,30 +109,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):
@@ -148,7 +143,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)
@@ -159,7 +154,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)
@@ -236,21 +231,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
@@ -259,18 +254,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)
@@ -279,13 +274,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)
@@ -293,7 +288,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
@@ -7177,16 +7172,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[u'layout'] = u'twopi'
- # g[u'root'] = u'0x%04x' % id
+ g.default_vertex['shape'] = 'box'
+ # g['layout'] = 'twopi'
+ # g['root'] = '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:
@@ -7204,10 +7199,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:
@@ -7216,36 +7211,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)