scripts: Adopt __get__ binding for write/writeln methods
This actually binds our custom write/writeln functions as methods to the
file object:
def writeln(self, s=''):
self.write(s)
self.write('\n')
f.writeln = writeln.__get__(f)
This doesn't really gain us anything, but is a bit more correct and may
be safer if other code messes with the file's internals.
This commit is contained in:
+11
-10
@@ -362,17 +362,18 @@ def compile(bench_paths, **args):
|
|||||||
# write generated bench source
|
# write generated bench source
|
||||||
if 'output' in args:
|
if 'output' in args:
|
||||||
with openio(args['output'], 'w') as f:
|
with openio(args['output'], 'w') as f:
|
||||||
_write = f.write
|
# some helpful file functions
|
||||||
def write(s):
|
|
||||||
f.lineno += s.count('\n')
|
|
||||||
_write(s)
|
|
||||||
def writeln(s=''):
|
|
||||||
f.lineno += s.count('\n') + 1
|
|
||||||
_write(s)
|
|
||||||
_write('\n')
|
|
||||||
f.lineno = 1
|
f.lineno = 1
|
||||||
f.write = write
|
f.write_ = f.write
|
||||||
f.writeln = writeln
|
def write(self, s):
|
||||||
|
self.lineno += s.count('\n')
|
||||||
|
self.write_(s)
|
||||||
|
f.write = write.__get__(f)
|
||||||
|
def writeln(self, s=''):
|
||||||
|
self.lineno += s.count('\n') + 1
|
||||||
|
self.write_(s)
|
||||||
|
self.write_('\n')
|
||||||
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
f.writeln("// Generated by %s:" % sys.argv[0])
|
f.writeln("// Generated by %s:" % sys.argv[0])
|
||||||
f.writeln("//")
|
f.writeln("//")
|
||||||
|
|||||||
+5
-5
@@ -951,11 +951,11 @@ def main_(ring, paths, *,
|
|||||||
label=False,
|
label=False,
|
||||||
no_label=False,
|
no_label=False,
|
||||||
**args):
|
**args):
|
||||||
# give ring an writeln function
|
# give ring a writeln function
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
ring.write(s)
|
self.write(s)
|
||||||
ring.write('\n')
|
self.write('\n')
|
||||||
ring.writeln = writeln
|
ring.writeln = writeln.__get__(ring)
|
||||||
|
|
||||||
# figure out what color should be
|
# figure out what color should be
|
||||||
if color == 'auto':
|
if color == 'auto':
|
||||||
|
|||||||
@@ -1174,10 +1174,10 @@ def main(paths, output, *,
|
|||||||
|
|
||||||
# create svg file
|
# create svg file
|
||||||
with openio(output, 'w') as f:
|
with openio(output, 'w') as f:
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
f.write(s)
|
self.write(s)
|
||||||
f.write('\n')
|
self.write('\n')
|
||||||
f.writeln = writeln
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
# yes this is svg
|
# yes this is svg
|
||||||
f.write('<svg '
|
f.write('<svg '
|
||||||
|
|||||||
+5
-5
@@ -4421,11 +4421,11 @@ def main_(ring, disk, mroots=None, *,
|
|||||||
title_littlefs=False,
|
title_littlefs=False,
|
||||||
title_usage=False,
|
title_usage=False,
|
||||||
**args):
|
**args):
|
||||||
# give ring an writeln function
|
# give ring a writeln function
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
ring.write(s)
|
self.write(s)
|
||||||
ring.write('\n')
|
self.write('\n')
|
||||||
ring.writeln = writeln
|
ring.writeln = writeln.__get__(ring)
|
||||||
|
|
||||||
# figure out what color should be
|
# figure out what color should be
|
||||||
if color == 'auto':
|
if color == 'auto':
|
||||||
|
|||||||
@@ -4512,10 +4512,10 @@ def main(disk, output, mroots=None, *,
|
|||||||
|
|
||||||
# create svg file
|
# create svg file
|
||||||
with openio(output, 'w') as f:
|
with openio(output, 'w') as f:
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
f.write(s)
|
self.write(s)
|
||||||
f.write('\n')
|
self.write('\n')
|
||||||
f.writeln = writeln
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
# yes this is svg
|
# yes this is svg
|
||||||
f.write('<svg '
|
f.write('<svg '
|
||||||
|
|||||||
+4
-4
@@ -1284,10 +1284,10 @@ def main(path='-', *,
|
|||||||
if wear else ''))
|
if wear else ''))
|
||||||
|
|
||||||
# give ring a writeln function
|
# give ring a writeln function
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
ring.write(s)
|
self.write(s)
|
||||||
ring.write('\n')
|
self.write('\n')
|
||||||
ring.writeln = writeln
|
ring.writeln = writeln.__get__(ring)
|
||||||
|
|
||||||
# figure out width/height
|
# figure out width/height
|
||||||
if width is None:
|
if width is None:
|
||||||
|
|||||||
+5
-5
@@ -1243,11 +1243,11 @@ def main_(ring, csv_paths, *,
|
|||||||
subplot={},
|
subplot={},
|
||||||
subplots=[],
|
subplots=[],
|
||||||
**args):
|
**args):
|
||||||
# give ring an writeln function
|
# give ring a writeln function
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
ring.write(s)
|
self.write(s)
|
||||||
ring.write('\n')
|
self.write('\n')
|
||||||
ring.writeln = writeln
|
ring.writeln = writeln.__get__(ring)
|
||||||
|
|
||||||
# figure out what color should be
|
# figure out what color should be
|
||||||
if color == 'auto':
|
if color == 'auto':
|
||||||
|
|||||||
@@ -583,10 +583,10 @@ def main(input=None, output=None, *,
|
|||||||
p = Parser(in_f.read(), '')
|
p = Parser(in_f.read(), '')
|
||||||
|
|
||||||
with openio(output or '-', 'w') as f:
|
with openio(output or '-', 'w') as f:
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
f.write(s)
|
self.write(s)
|
||||||
f.write('\n')
|
self.write('\n')
|
||||||
f.writeln = writeln
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
# write extra verbose asserts
|
# write extra verbose asserts
|
||||||
mkheader(f, limit=limit)
|
mkheader(f, limit=limit)
|
||||||
|
|||||||
+11
-10
@@ -374,17 +374,18 @@ def compile(test_paths, **args):
|
|||||||
# write generated test source
|
# write generated test source
|
||||||
if 'output' in args:
|
if 'output' in args:
|
||||||
with openio(args['output'], 'w') as f:
|
with openio(args['output'], 'w') as f:
|
||||||
_write = f.write
|
# some helpful file functions
|
||||||
def write(s):
|
|
||||||
f.lineno += s.count('\n')
|
|
||||||
_write(s)
|
|
||||||
def writeln(s=''):
|
|
||||||
f.lineno += s.count('\n') + 1
|
|
||||||
_write(s)
|
|
||||||
_write('\n')
|
|
||||||
f.lineno = 1
|
f.lineno = 1
|
||||||
f.write = write
|
f.write_ = f.write
|
||||||
f.writeln = writeln
|
def write(self, s):
|
||||||
|
self.lineno += s.count('\n')
|
||||||
|
self.write_(s)
|
||||||
|
f.write = write.__get__(f)
|
||||||
|
def writeln(self, s=''):
|
||||||
|
self.lineno += s.count('\n') + 1
|
||||||
|
self.write_(s)
|
||||||
|
self.write_('\n')
|
||||||
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
f.writeln("// Generated by %s:" % sys.argv[0])
|
f.writeln("// Generated by %s:" % sys.argv[0])
|
||||||
f.writeln("//")
|
f.writeln("//")
|
||||||
|
|||||||
+5
-5
@@ -964,11 +964,11 @@ def main_(ring, csv_paths, *,
|
|||||||
label=False,
|
label=False,
|
||||||
no_label=False,
|
no_label=False,
|
||||||
**args):
|
**args):
|
||||||
# give ring an writeln function
|
# give ring a writeln function
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
ring.write(s)
|
self.write(s)
|
||||||
ring.write('\n')
|
self.write('\n')
|
||||||
ring.writeln = writeln
|
ring.writeln = writeln.__get__(ring)
|
||||||
|
|
||||||
# figure out what color should be
|
# figure out what color should be
|
||||||
if color == 'auto':
|
if color == 'auto':
|
||||||
|
|||||||
@@ -877,10 +877,10 @@ def main(csv_paths, output, *,
|
|||||||
|
|
||||||
# create svg file
|
# create svg file
|
||||||
with openio(output, 'w') as f:
|
with openio(output, 'w') as f:
|
||||||
def writeln(s=''):
|
def writeln(self, s=''):
|
||||||
f.write(s)
|
self.write(s)
|
||||||
f.write('\n')
|
self.write('\n')
|
||||||
f.writeln = writeln
|
f.writeln = writeln.__get__(f)
|
||||||
|
|
||||||
# yes this is svg
|
# yes this is svg
|
||||||
f.write('<svg '
|
f.write('<svg '
|
||||||
|
|||||||
Reference in New Issue
Block a user