1.1 --- a/lib/__builtins__/io.py Fri Nov 11 00:03:05 2016 +0100
1.2 +++ b/lib/__builtins__/io.py Fri Nov 11 00:05:34 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Input/output-related functions.
1.6
1.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -19,8 +19,69 @@
1.13 this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 -def eval(source, globals=None, locals=None): pass
1.17 -def open(name, mode=None, buffering=None): pass
1.18 +from native import _read, _write
1.19 +from sys import stdout
1.20 +
1.21 +class sysfile:
1.22 +
1.23 + "A system-level file object."
1.24 +
1.25 + def __init__(self, fd):
1.26 +
1.27 + "Initialise the file with the given 'fd'."
1.28 +
1.29 + self.fd = fd
1.30 +
1.31 + def read(self, n):
1.32 +
1.33 + "Read 'n' bytes from the file."
1.34 +
1.35 + return _read(self.fd, n)
1.36 +
1.37 + def write(self, s):
1.38 +
1.39 + "Write 's' to the file."
1.40 +
1.41 + _write(self.fd, str(s))
1.42 +
1.43 +def open(name, mode=None, buffering=None):
1.44 +
1.45 + """
1.46 + Open the file with the given 'name', using the given 'mode' and applying the
1.47 + indicated 'buffering'.
1.48 + """
1.49 +
1.50 + return file(name, mode, buffering)
1.51 +
1.52 def raw_input(prompt=None): pass
1.53
1.54 +def print_(dest, args, nl):
1.55 +
1.56 + """
1.57 + Write to 'dest' the string representation of 'args', adding a newline if
1.58 + 'nl' is given as a true value.
1.59 + """
1.60 +
1.61 + # Write to standard output if dest is not specified.
1.62 +
1.63 + dest = dest or stdout
1.64 +
1.65 + first = True
1.66 +
1.67 + for arg in args:
1.68 +
1.69 + # Insert spaces between arguments.
1.70 +
1.71 + if first:
1.72 + first = False
1.73 + else:
1.74 + dest.write(" ")
1.75 +
1.76 + dest.write(str(arg))
1.77 +
1.78 + # Add a newline if specified.
1.79 +
1.80 + if nl:
1.81 + dest.write("\n")
1.82 +
1.83 # vim: tabstop=4 expandtab shiftwidth=4