1.1 --- a/lib/posix/io.py Thu Feb 02 22:38:26 2017 +0100
1.2 +++ b/lib/posix/io.py Thu Feb 02 22:41:07 2017 +0100
1.3 @@ -19,85 +19,7 @@
1.4 this program. If not, see <http://www.gnu.org/licenses/>.
1.5 """
1.6
1.7 -from __builtins__.file import filestream
1.8 -from __builtins__.types import check_int, check_string
1.9 -
1.10 -from native import (
1.11 - close as _close,
1.12 - fdopen as _fdopen,
1.13 - read as _read,
1.14 - write as _write
1.15 - )
1.16 -
1.17 -import locale
1.18 -
1.19 -# Abstractions for system-level files and streams.
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, returning a string."
1.34 -
1.35 - return read(self.fd, n)
1.36 -
1.37 - def write(self, s):
1.38 -
1.39 - "Write string 's' to the file."
1.40 -
1.41 - return write(self.fd, s)
1.42 -
1.43 - def close(self):
1.44 -
1.45 - "Close the file."
1.46 -
1.47 - close(self.fd)
1.48 -
1.49 -class sysstream(filestream):
1.50 -
1.51 - "A system-level stream object."
1.52 -
1.53 - def __init__(self, fd, mode="r", encoding=None, bufsize=1024):
1.54 -
1.55 - """
1.56 - Initialise the stream with the given 'fd', 'mode', 'encoding' and
1.57 - 'bufsize'.
1.58 - """
1.59 -
1.60 - check_int(fd)
1.61 - check_string(mode)
1.62 -
1.63 - get_using(filestream.__init__, self)(encoding, bufsize)
1.64 - self.__data__ = _fdopen(fd, mode)
1.65 -
1.66 -# Standard streams.
1.67 -
1.68 -stdin = sysstream(0)
1.69 -stdout = sysstream(1, "w")
1.70 -stderr = sysstream(2, "w")
1.71 -
1.72 -# Localised streams.
1.73 -# Perform locale initialisation explicitly to ensure that the locale module
1.74 -# and various function defaults have been initialised.
1.75 -
1.76 -locale.initlocale()
1.77 -lstdin = sysstream(0, "r", locale.getpreferredencoding())
1.78 -
1.79 -# Input/output functions.
1.80 -
1.81 -def close(fd):
1.82 -
1.83 - "Close the file descriptor 'fd'."
1.84 -
1.85 - _close(fd)
1.86 +from libc.io import close, fdopen, read, write
1.87
1.88 def closerange(fd_low, fd_high): pass
1.89 def dup(fd): pass
1.90 @@ -106,16 +28,6 @@
1.91 def fchmod(fd, mode): pass
1.92 def fchown(fd, uid, gid): pass
1.93 def fdatasync(fd): pass
1.94 -
1.95 -def fdopen(fd, mode="r"):
1.96 -
1.97 - """
1.98 - Open a stream for the given file descriptor 'fd', operating in the given
1.99 - 'mode'.
1.100 - """
1.101 -
1.102 - return sysstream(fd, mode)
1.103 -
1.104 def fpathconf(fd, name): pass
1.105 def fstat(fd): pass
1.106 def fstatvfs(fd): pass
1.107 @@ -132,31 +44,12 @@
1.108 def openpty(): pass
1.109 def pipe(): pass
1.110 def putenv(key, value): pass
1.111 -
1.112 -def read(fd, n):
1.113 -
1.114 - """
1.115 - Read using the low-level file descriptor 'fd' the given number of bytes 'n'.
1.116 - """
1.117 -
1.118 - check_int(fd)
1.119 - check_int(n)
1.120 - return _read(fd, n)
1.121 -
1.122 def times(): pass
1.123 def ttyname(fd): pass
1.124 def umask(new_mask): pass
1.125 def uname(): pass
1.126 def unsetenv(key): pass
1.127
1.128 -def write(fd, s):
1.129 -
1.130 - "Write using the low-level file descriptor 'fd' the given string 's'."
1.131 -
1.132 - check_int(fd)
1.133 - check_string(s)
1.134 - return _write(fd, s)
1.135 -
1.136 # Constants.
1.137
1.138 O_APPEND = 1024