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