Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ExeBy/exe_root.../opt/alt/python27/lib64/python2....
File: _pyio.py
"""
[0] Fix | Delete
Python implementation of the io module.
[1] Fix | Delete
"""
[2] Fix | Delete
[3] Fix | Delete
from __future__ import (print_function, unicode_literals)
[4] Fix | Delete
[5] Fix | Delete
import os
[6] Fix | Delete
import abc
[7] Fix | Delete
import codecs
[8] Fix | Delete
import sys
[9] Fix | Delete
import warnings
[10] Fix | Delete
import errno
[11] Fix | Delete
# Import thread instead of threading to reduce startup cost
[12] Fix | Delete
try:
[13] Fix | Delete
from thread import allocate_lock as Lock
[14] Fix | Delete
except ImportError:
[15] Fix | Delete
from dummy_thread import allocate_lock as Lock
[16] Fix | Delete
[17] Fix | Delete
import io
[18] Fix | Delete
from io import (__all__, SEEK_SET, SEEK_CUR, SEEK_END)
[19] Fix | Delete
from errno import EINTR
[20] Fix | Delete
[21] Fix | Delete
__metaclass__ = type
[22] Fix | Delete
[23] Fix | Delete
# open() uses st_blksize whenever we can
[24] Fix | Delete
DEFAULT_BUFFER_SIZE = 8 * 1024 # bytes
[25] Fix | Delete
[26] Fix | Delete
# NOTE: Base classes defined here are registered with the "official" ABCs
[27] Fix | Delete
# defined in io.py. We don't use real inheritance though, because we don't want
[28] Fix | Delete
# to inherit the C implementations.
[29] Fix | Delete
[30] Fix | Delete
[31] Fix | Delete
class BlockingIOError(IOError):
[32] Fix | Delete
[33] Fix | Delete
"""Exception raised when I/O would block on a non-blocking I/O stream."""
[34] Fix | Delete
[35] Fix | Delete
def __init__(self, errno, strerror, characters_written=0):
[36] Fix | Delete
super(IOError, self).__init__(errno, strerror)
[37] Fix | Delete
if not isinstance(characters_written, (int, long)):
[38] Fix | Delete
raise TypeError("characters_written must be a integer")
[39] Fix | Delete
self.characters_written = characters_written
[40] Fix | Delete
[41] Fix | Delete
[42] Fix | Delete
def open(file, mode="r", buffering=-1,
[43] Fix | Delete
encoding=None, errors=None,
[44] Fix | Delete
newline=None, closefd=True):
[45] Fix | Delete
[46] Fix | Delete
r"""Open file and return a stream. Raise IOError upon failure.
[47] Fix | Delete
[48] Fix | Delete
file is either a text or byte string giving the name (and the path
[49] Fix | Delete
if the file isn't in the current working directory) of the file to
[50] Fix | Delete
be opened or an integer file descriptor of the file to be
[51] Fix | Delete
wrapped. (If a file descriptor is given, it is closed when the
[52] Fix | Delete
returned I/O object is closed, unless closefd is set to False.)
[53] Fix | Delete
[54] Fix | Delete
mode is an optional string that specifies the mode in which the file
[55] Fix | Delete
is opened. It defaults to 'r' which means open for reading in text
[56] Fix | Delete
mode. Other common values are 'w' for writing (truncating the file if
[57] Fix | Delete
it already exists), and 'a' for appending (which on some Unix systems,
[58] Fix | Delete
means that all writes append to the end of the file regardless of the
[59] Fix | Delete
current seek position). In text mode, if encoding is not specified the
[60] Fix | Delete
encoding used is platform dependent. (For reading and writing raw
[61] Fix | Delete
bytes use binary mode and leave encoding unspecified.) The available
[62] Fix | Delete
modes are:
[63] Fix | Delete
[64] Fix | Delete
========= ===============================================================
[65] Fix | Delete
Character Meaning
[66] Fix | Delete
--------- ---------------------------------------------------------------
[67] Fix | Delete
'r' open for reading (default)
[68] Fix | Delete
'w' open for writing, truncating the file first
[69] Fix | Delete
'a' open for writing, appending to the end of the file if it exists
[70] Fix | Delete
'b' binary mode
[71] Fix | Delete
't' text mode (default)
[72] Fix | Delete
'+' open a disk file for updating (reading and writing)
[73] Fix | Delete
'U' universal newline mode (for backwards compatibility; unneeded
[74] Fix | Delete
for new code)
[75] Fix | Delete
========= ===============================================================
[76] Fix | Delete
[77] Fix | Delete
The default mode is 'rt' (open for reading text). For binary random
[78] Fix | Delete
access, the mode 'w+b' opens and truncates the file to 0 bytes, while
[79] Fix | Delete
'r+b' opens the file without truncation.
[80] Fix | Delete
[81] Fix | Delete
Python distinguishes between files opened in binary and text modes,
[82] Fix | Delete
even when the underlying operating system doesn't. Files opened in
[83] Fix | Delete
binary mode (appending 'b' to the mode argument) return contents as
[84] Fix | Delete
bytes objects without any decoding. In text mode (the default, or when
[85] Fix | Delete
't' is appended to the mode argument), the contents of the file are
[86] Fix | Delete
returned as strings, the bytes having been first decoded using a
[87] Fix | Delete
platform-dependent encoding or using the specified encoding if given.
[88] Fix | Delete
[89] Fix | Delete
buffering is an optional integer used to set the buffering policy.
[90] Fix | Delete
Pass 0 to switch buffering off (only allowed in binary mode), 1 to select
[91] Fix | Delete
line buffering (only usable in text mode), and an integer > 1 to indicate
[92] Fix | Delete
the size of a fixed-size chunk buffer. When no buffering argument is
[93] Fix | Delete
given, the default buffering policy works as follows:
[94] Fix | Delete
[95] Fix | Delete
* Binary files are buffered in fixed-size chunks; the size of the buffer
[96] Fix | Delete
is chosen using a heuristic trying to determine the underlying device's
[97] Fix | Delete
"block size" and falling back on `io.DEFAULT_BUFFER_SIZE`.
[98] Fix | Delete
On many systems, the buffer will typically be 4096 or 8192 bytes long.
[99] Fix | Delete
[100] Fix | Delete
* "Interactive" text files (files for which isatty() returns True)
[101] Fix | Delete
use line buffering. Other text files use the policy described above
[102] Fix | Delete
for binary files.
[103] Fix | Delete
[104] Fix | Delete
encoding is the name of the encoding used to decode or encode the
[105] Fix | Delete
file. This should only be used in text mode. The default encoding is
[106] Fix | Delete
platform dependent, but any encoding supported by Python can be
[107] Fix | Delete
passed. See the codecs module for the list of supported encodings.
[108] Fix | Delete
[109] Fix | Delete
errors is an optional string that specifies how encoding errors are to
[110] Fix | Delete
be handled---this argument should not be used in binary mode. Pass
[111] Fix | Delete
'strict' to raise a ValueError exception if there is an encoding error
[112] Fix | Delete
(the default of None has the same effect), or pass 'ignore' to ignore
[113] Fix | Delete
errors. (Note that ignoring encoding errors can lead to data loss.)
[114] Fix | Delete
See the documentation for codecs.register for a list of the permitted
[115] Fix | Delete
encoding error strings.
[116] Fix | Delete
[117] Fix | Delete
newline controls how universal newlines works (it only applies to text
[118] Fix | Delete
mode). It can be None, '', '\n', '\r', and '\r\n'. It works as
[119] Fix | Delete
follows:
[120] Fix | Delete
[121] Fix | Delete
* On input, if newline is None, universal newlines mode is
[122] Fix | Delete
enabled. Lines in the input can end in '\n', '\r', or '\r\n', and
[123] Fix | Delete
these are translated into '\n' before being returned to the
[124] Fix | Delete
caller. If it is '', universal newline mode is enabled, but line
[125] Fix | Delete
endings are returned to the caller untranslated. If it has any of
[126] Fix | Delete
the other legal values, input lines are only terminated by the given
[127] Fix | Delete
string, and the line ending is returned to the caller untranslated.
[128] Fix | Delete
[129] Fix | Delete
* On output, if newline is None, any '\n' characters written are
[130] Fix | Delete
translated to the system default line separator, os.linesep. If
[131] Fix | Delete
newline is '', no translation takes place. If newline is any of the
[132] Fix | Delete
other legal values, any '\n' characters written are translated to
[133] Fix | Delete
the given string.
[134] Fix | Delete
[135] Fix | Delete
If closefd is False, the underlying file descriptor will be kept open
[136] Fix | Delete
when the file is closed. This does not work when a file name is given
[137] Fix | Delete
and must be True in that case.
[138] Fix | Delete
[139] Fix | Delete
open() returns a file object whose type depends on the mode, and
[140] Fix | Delete
through which the standard file operations such as reading and writing
[141] Fix | Delete
are performed. When open() is used to open a file in a text mode ('w',
[142] Fix | Delete
'r', 'wt', 'rt', etc.), it returns a TextIOWrapper. When used to open
[143] Fix | Delete
a file in a binary mode, the returned class varies: in read binary
[144] Fix | Delete
mode, it returns a BufferedReader; in write binary and append binary
[145] Fix | Delete
modes, it returns a BufferedWriter, and in read/write mode, it returns
[146] Fix | Delete
a BufferedRandom.
[147] Fix | Delete
[148] Fix | Delete
It is also possible to use a string or bytearray as a file for both
[149] Fix | Delete
reading and writing. For strings StringIO can be used like a file
[150] Fix | Delete
opened in a text mode, and for bytes a BytesIO can be used like a file
[151] Fix | Delete
opened in a binary mode.
[152] Fix | Delete
"""
[153] Fix | Delete
if not isinstance(file, (basestring, int, long)):
[154] Fix | Delete
raise TypeError("invalid file: %r" % file)
[155] Fix | Delete
if not isinstance(mode, basestring):
[156] Fix | Delete
raise TypeError("invalid mode: %r" % mode)
[157] Fix | Delete
if not isinstance(buffering, (int, long)):
[158] Fix | Delete
raise TypeError("invalid buffering: %r" % buffering)
[159] Fix | Delete
if encoding is not None and not isinstance(encoding, basestring):
[160] Fix | Delete
raise TypeError("invalid encoding: %r" % encoding)
[161] Fix | Delete
if errors is not None and not isinstance(errors, basestring):
[162] Fix | Delete
raise TypeError("invalid errors: %r" % errors)
[163] Fix | Delete
modes = set(mode)
[164] Fix | Delete
if modes - set("arwb+tU") or len(mode) > len(modes):
[165] Fix | Delete
raise ValueError("invalid mode: %r" % mode)
[166] Fix | Delete
reading = "r" in modes
[167] Fix | Delete
writing = "w" in modes
[168] Fix | Delete
appending = "a" in modes
[169] Fix | Delete
updating = "+" in modes
[170] Fix | Delete
text = "t" in modes
[171] Fix | Delete
binary = "b" in modes
[172] Fix | Delete
if "U" in modes:
[173] Fix | Delete
if writing or appending:
[174] Fix | Delete
raise ValueError("can't use U and writing mode at once")
[175] Fix | Delete
reading = True
[176] Fix | Delete
if text and binary:
[177] Fix | Delete
raise ValueError("can't have text and binary mode at once")
[178] Fix | Delete
if reading + writing + appending > 1:
[179] Fix | Delete
raise ValueError("can't have read/write/append mode at once")
[180] Fix | Delete
if not (reading or writing or appending):
[181] Fix | Delete
raise ValueError("must have exactly one of read/write/append mode")
[182] Fix | Delete
if binary and encoding is not None:
[183] Fix | Delete
raise ValueError("binary mode doesn't take an encoding argument")
[184] Fix | Delete
if binary and errors is not None:
[185] Fix | Delete
raise ValueError("binary mode doesn't take an errors argument")
[186] Fix | Delete
if binary and newline is not None:
[187] Fix | Delete
raise ValueError("binary mode doesn't take a newline argument")
[188] Fix | Delete
raw = FileIO(file,
[189] Fix | Delete
(reading and "r" or "") +
[190] Fix | Delete
(writing and "w" or "") +
[191] Fix | Delete
(appending and "a" or "") +
[192] Fix | Delete
(updating and "+" or ""),
[193] Fix | Delete
closefd)
[194] Fix | Delete
result = raw
[195] Fix | Delete
try:
[196] Fix | Delete
line_buffering = False
[197] Fix | Delete
if buffering == 1 or buffering < 0 and raw.isatty():
[198] Fix | Delete
buffering = -1
[199] Fix | Delete
line_buffering = True
[200] Fix | Delete
if buffering < 0:
[201] Fix | Delete
buffering = DEFAULT_BUFFER_SIZE
[202] Fix | Delete
try:
[203] Fix | Delete
bs = os.fstat(raw.fileno()).st_blksize
[204] Fix | Delete
except (os.error, AttributeError):
[205] Fix | Delete
pass
[206] Fix | Delete
else:
[207] Fix | Delete
if bs > 1:
[208] Fix | Delete
buffering = bs
[209] Fix | Delete
if buffering < 0:
[210] Fix | Delete
raise ValueError("invalid buffering size")
[211] Fix | Delete
if buffering == 0:
[212] Fix | Delete
if binary:
[213] Fix | Delete
return result
[214] Fix | Delete
raise ValueError("can't have unbuffered text I/O")
[215] Fix | Delete
if updating:
[216] Fix | Delete
buffer = BufferedRandom(raw, buffering)
[217] Fix | Delete
elif writing or appending:
[218] Fix | Delete
buffer = BufferedWriter(raw, buffering)
[219] Fix | Delete
elif reading:
[220] Fix | Delete
buffer = BufferedReader(raw, buffering)
[221] Fix | Delete
else:
[222] Fix | Delete
raise ValueError("unknown mode: %r" % mode)
[223] Fix | Delete
result = buffer
[224] Fix | Delete
if binary:
[225] Fix | Delete
return result
[226] Fix | Delete
text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
[227] Fix | Delete
result = text
[228] Fix | Delete
text.mode = mode
[229] Fix | Delete
return result
[230] Fix | Delete
except:
[231] Fix | Delete
result.close()
[232] Fix | Delete
raise
[233] Fix | Delete
[234] Fix | Delete
[235] Fix | Delete
class DocDescriptor:
[236] Fix | Delete
"""Helper for builtins.open.__doc__
[237] Fix | Delete
"""
[238] Fix | Delete
def __get__(self, obj, typ):
[239] Fix | Delete
return (
[240] Fix | Delete
"open(file, mode='r', buffering=-1, encoding=None, "
[241] Fix | Delete
"errors=None, newline=None, closefd=True)\n\n" +
[242] Fix | Delete
open.__doc__)
[243] Fix | Delete
[244] Fix | Delete
class OpenWrapper:
[245] Fix | Delete
"""Wrapper for builtins.open
[246] Fix | Delete
[247] Fix | Delete
Trick so that open won't become a bound method when stored
[248] Fix | Delete
as a class variable (as dbm.dumb does).
[249] Fix | Delete
[250] Fix | Delete
See initstdio() in Python/pythonrun.c.
[251] Fix | Delete
"""
[252] Fix | Delete
__doc__ = DocDescriptor()
[253] Fix | Delete
[254] Fix | Delete
def __new__(cls, *args, **kwargs):
[255] Fix | Delete
return open(*args, **kwargs)
[256] Fix | Delete
[257] Fix | Delete
[258] Fix | Delete
class UnsupportedOperation(ValueError, IOError):
[259] Fix | Delete
pass
[260] Fix | Delete
[261] Fix | Delete
[262] Fix | Delete
class IOBase:
[263] Fix | Delete
__metaclass__ = abc.ABCMeta
[264] Fix | Delete
[265] Fix | Delete
"""The abstract base class for all I/O classes, acting on streams of
[266] Fix | Delete
bytes. There is no public constructor.
[267] Fix | Delete
[268] Fix | Delete
This class provides dummy implementations for many methods that
[269] Fix | Delete
derived classes can override selectively; the default implementations
[270] Fix | Delete
represent a file that cannot be read, written or seeked.
[271] Fix | Delete
[272] Fix | Delete
Even though IOBase does not declare read, readinto, or write because
[273] Fix | Delete
their signatures will vary, implementations and clients should
[274] Fix | Delete
consider those methods part of the interface. Also, implementations
[275] Fix | Delete
may raise an IOError when operations they do not support are called.
[276] Fix | Delete
[277] Fix | Delete
The basic type used for binary data read from or written to a file is
[278] Fix | Delete
the bytes type. Method arguments may also be bytearray or memoryview of
[279] Fix | Delete
arrays of bytes. In some cases, such as readinto, a writable object such
[280] Fix | Delete
as bytearray is required. Text I/O classes work with unicode data.
[281] Fix | Delete
[282] Fix | Delete
Note that calling any method (even inquiries) on a closed stream is
[283] Fix | Delete
undefined. Implementations may raise IOError in this case.
[284] Fix | Delete
[285] Fix | Delete
IOBase (and its subclasses) support the iterator protocol, meaning
[286] Fix | Delete
that an IOBase object can be iterated over yielding the lines in a
[287] Fix | Delete
stream.
[288] Fix | Delete
[289] Fix | Delete
IOBase also supports the :keyword:`with` statement. In this example,
[290] Fix | Delete
fp is closed after the suite of the with statement is complete:
[291] Fix | Delete
[292] Fix | Delete
with open('spam.txt', 'r') as fp:
[293] Fix | Delete
fp.write('Spam and eggs!')
[294] Fix | Delete
"""
[295] Fix | Delete
[296] Fix | Delete
### Internal ###
[297] Fix | Delete
[298] Fix | Delete
def _unsupported(self, name):
[299] Fix | Delete
"""Internal: raise an exception for unsupported operations."""
[300] Fix | Delete
raise UnsupportedOperation("%s.%s() not supported" %
[301] Fix | Delete
(self.__class__.__name__, name))
[302] Fix | Delete
[303] Fix | Delete
### Positioning ###
[304] Fix | Delete
[305] Fix | Delete
def seek(self, pos, whence=0):
[306] Fix | Delete
"""Change stream position.
[307] Fix | Delete
[308] Fix | Delete
Change the stream position to byte offset pos. Argument pos is
[309] Fix | Delete
interpreted relative to the position indicated by whence. Values
[310] Fix | Delete
for whence are:
[311] Fix | Delete
[312] Fix | Delete
* 0 -- start of stream (the default); offset should be zero or positive
[313] Fix | Delete
* 1 -- current stream position; offset may be negative
[314] Fix | Delete
* 2 -- end of stream; offset is usually negative
[315] Fix | Delete
[316] Fix | Delete
Return the new absolute position.
[317] Fix | Delete
"""
[318] Fix | Delete
self._unsupported("seek")
[319] Fix | Delete
[320] Fix | Delete
def tell(self):
[321] Fix | Delete
"""Return current stream position."""
[322] Fix | Delete
return self.seek(0, 1)
[323] Fix | Delete
[324] Fix | Delete
def truncate(self, pos=None):
[325] Fix | Delete
"""Truncate file to size bytes.
[326] Fix | Delete
[327] Fix | Delete
Size defaults to the current IO position as reported by tell(). Return
[328] Fix | Delete
the new size.
[329] Fix | Delete
"""
[330] Fix | Delete
self._unsupported("truncate")
[331] Fix | Delete
[332] Fix | Delete
### Flush and close ###
[333] Fix | Delete
[334] Fix | Delete
def flush(self):
[335] Fix | Delete
"""Flush write buffers, if applicable.
[336] Fix | Delete
[337] Fix | Delete
This is not implemented for read-only and non-blocking streams.
[338] Fix | Delete
"""
[339] Fix | Delete
self._checkClosed()
[340] Fix | Delete
# XXX Should this return the number of bytes written???
[341] Fix | Delete
[342] Fix | Delete
__closed = False
[343] Fix | Delete
[344] Fix | Delete
def close(self):
[345] Fix | Delete
"""Flush and close the IO object.
[346] Fix | Delete
[347] Fix | Delete
This method has no effect if the file is already closed.
[348] Fix | Delete
"""
[349] Fix | Delete
if not self.__closed:
[350] Fix | Delete
try:
[351] Fix | Delete
self.flush()
[352] Fix | Delete
finally:
[353] Fix | Delete
self.__closed = True
[354] Fix | Delete
[355] Fix | Delete
def __del__(self):
[356] Fix | Delete
"""Destructor. Calls close()."""
[357] Fix | Delete
# The try/except block is in case this is called at program
[358] Fix | Delete
# exit time, when it's possible that globals have already been
[359] Fix | Delete
# deleted, and then the close() call might fail. Since
[360] Fix | Delete
# there's nothing we can do about such failures and they annoy
[361] Fix | Delete
# the end users, we suppress the traceback.
[362] Fix | Delete
try:
[363] Fix | Delete
self.close()
[364] Fix | Delete
except:
[365] Fix | Delete
pass
[366] Fix | Delete
[367] Fix | Delete
### Inquiries ###
[368] Fix | Delete
[369] Fix | Delete
def seekable(self):
[370] Fix | Delete
"""Return whether object supports random access.
[371] Fix | Delete
[372] Fix | Delete
If False, seek(), tell() and truncate() will raise IOError.
[373] Fix | Delete
This method may need to do a test seek().
[374] Fix | Delete
"""
[375] Fix | Delete
return False
[376] Fix | Delete
[377] Fix | Delete
def _checkSeekable(self, msg=None):
[378] Fix | Delete
"""Internal: raise an IOError if file is not seekable
[379] Fix | Delete
"""
[380] Fix | Delete
if not self.seekable():
[381] Fix | Delete
raise IOError("File or stream is not seekable."
[382] Fix | Delete
if msg is None else msg)
[383] Fix | Delete
[384] Fix | Delete
[385] Fix | Delete
def readable(self):
[386] Fix | Delete
"""Return whether object was opened for reading.
[387] Fix | Delete
[388] Fix | Delete
If False, read() will raise IOError.
[389] Fix | Delete
"""
[390] Fix | Delete
return False
[391] Fix | Delete
[392] Fix | Delete
def _checkReadable(self, msg=None):
[393] Fix | Delete
"""Internal: raise an IOError if file is not readable
[394] Fix | Delete
"""
[395] Fix | Delete
if not self.readable():
[396] Fix | Delete
raise IOError("File or stream is not readable."
[397] Fix | Delete
if msg is None else msg)
[398] Fix | Delete
[399] Fix | Delete
def writable(self):
[400] Fix | Delete
"""Return whether object was opened for writing.
[401] Fix | Delete
[402] Fix | Delete
If False, write() and truncate() will raise IOError.
[403] Fix | Delete
"""
[404] Fix | Delete
return False
[405] Fix | Delete
[406] Fix | Delete
def _checkWritable(self, msg=None):
[407] Fix | Delete
"""Internal: raise an IOError if file is not writable
[408] Fix | Delete
"""
[409] Fix | Delete
if not self.writable():
[410] Fix | Delete
raise IOError("File or stream is not writable."
[411] Fix | Delete
if msg is None else msg)
[412] Fix | Delete
[413] Fix | Delete
@property
[414] Fix | Delete
def closed(self):
[415] Fix | Delete
"""closed: bool. True iff the file has been closed.
[416] Fix | Delete
[417] Fix | Delete
For backwards compatibility, this is a property, not a predicate.
[418] Fix | Delete
"""
[419] Fix | Delete
return self.__closed
[420] Fix | Delete
[421] Fix | Delete
def _checkClosed(self, msg=None):
[422] Fix | Delete
"""Internal: raise a ValueError if file is closed
[423] Fix | Delete
"""
[424] Fix | Delete
if self.closed:
[425] Fix | Delete
raise ValueError("I/O operation on closed file."
[426] Fix | Delete
if msg is None else msg)
[427] Fix | Delete
[428] Fix | Delete
### Context manager ###
[429] Fix | Delete
[430] Fix | Delete
def __enter__(self):
[431] Fix | Delete
"""Context management protocol. Returns self."""
[432] Fix | Delete
self._checkClosed()
[433] Fix | Delete
return self
[434] Fix | Delete
[435] Fix | Delete
def __exit__(self, *args):
[436] Fix | Delete
"""Context management protocol. Calls close()"""
[437] Fix | Delete
self.close()
[438] Fix | Delete
[439] Fix | Delete
### Lower-level APIs ###
[440] Fix | Delete
[441] Fix | Delete
# XXX Should these be present even if unimplemented?
[442] Fix | Delete
[443] Fix | Delete
def fileno(self):
[444] Fix | Delete
"""Returns underlying file descriptor if one exists.
[445] Fix | Delete
[446] Fix | Delete
An IOError is raised if the IO object does not use a file descriptor.
[447] Fix | Delete
"""
[448] Fix | Delete
self._unsupported("fileno")
[449] Fix | Delete
[450] Fix | Delete
def isatty(self):
[451] Fix | Delete
"""Return whether this is an 'interactive' stream.
[452] Fix | Delete
[453] Fix | Delete
Return False if it can't be determined.
[454] Fix | Delete
"""
[455] Fix | Delete
self._checkClosed()
[456] Fix | Delete
return False
[457] Fix | Delete
[458] Fix | Delete
### Readline[s] and writelines ###
[459] Fix | Delete
[460] Fix | Delete
def readline(self, limit=-1):
[461] Fix | Delete
r"""Read and return a line from the stream.
[462] Fix | Delete
[463] Fix | Delete
If limit is specified, at most limit bytes will be read.
[464] Fix | Delete
[465] Fix | Delete
The line terminator is always b'\n' for binary files; for text
[466] Fix | Delete
files, the newlines argument to open can be used to select the line
[467] Fix | Delete
terminator(s) recognized.
[468] Fix | Delete
"""
[469] Fix | Delete
# For backwards compatibility, a (slowish) readline().
[470] Fix | Delete
if hasattr(self, "peek"):
[471] Fix | Delete
def nreadahead():
[472] Fix | Delete
readahead = self.peek(1)
[473] Fix | Delete
if not readahead:
[474] Fix | Delete
return 1
[475] Fix | Delete
n = (readahead.find(b"\n") + 1) or len(readahead)
[476] Fix | Delete
if limit >= 0:
[477] Fix | Delete
n = min(n, limit)
[478] Fix | Delete
return n
[479] Fix | Delete
else:
[480] Fix | Delete
def nreadahead():
[481] Fix | Delete
return 1
[482] Fix | Delete
if limit is None:
[483] Fix | Delete
limit = -1
[484] Fix | Delete
elif not isinstance(limit, (int, long)):
[485] Fix | Delete
raise TypeError("limit must be an integer")
[486] Fix | Delete
res = bytearray()
[487] Fix | Delete
while limit < 0 or len(res) < limit:
[488] Fix | Delete
b = self.read(nreadahead())
[489] Fix | Delete
if not b:
[490] Fix | Delete
break
[491] Fix | Delete
res += b
[492] Fix | Delete
if res.endswith(b"\n"):
[493] Fix | Delete
break
[494] Fix | Delete
return bytes(res)
[495] Fix | Delete
[496] Fix | Delete
def __iter__(self):
[497] Fix | Delete
self._checkClosed()
[498] Fix | Delete
return self
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function