Backing out 86dc014cdd74. Not ready yet · pythoncapi/cpython@990eff0 · GitHub
Skip to content

Commit 990eff0

Browse files
committed
Backing out 86dc014cdd74. Not ready yet
1 parent 2b47f0a commit 990eff0

8 files changed

Lines changed: 12 additions & 60 deletions

File tree

Doc/library/io.rst

Lines changed: 0 additions & 5 deletions

Doc/library/os.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -992,10 +992,6 @@ as internal buffering of data.
992992
Parameters to the :func:`lseek` function. Their values are 0, 1, and 2,
993993
respectively. Availability: Windows, Unix.
994994

995-
.. versionadded:: 3.3
996-
Some operating systems could support additional values, like
997-
:data:`os.SEEK_HOLE` or :data:`os.SEEK_DATA`.
998-
999995

1000996
.. function:: mkdirat(dirfd, path, mode=0o777)
1001997

Lib/_pyio.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,6 @@ def seek(self, pos, whence=0):
306306
* 0 -- start of stream (the default); offset should be zero or positive
307307
* 1 -- current stream position; offset may be negative
308308
* 2 -- end of stream; offset is usually negative
309-
Some operating systems / file systems could provide additional values.
310309
311310
Return an int indicating the new absolute position.
312311
"""
@@ -867,7 +866,7 @@ def seek(self, pos, whence=0):
867866
elif whence == 2:
868867
self._pos = max(0, len(self._buffer) + pos)
869868
else:
870-
raise ValueError("unsupported whence value")
869+
raise ValueError("invalid whence value")
871870
return self._pos
872871

873872
def tell(self):
@@ -1042,6 +1041,8 @@ def tell(self):
10421041
return _BufferedIOMixin.tell(self) - len(self._read_buf) + self._read_pos
10431042

10441043
def seek(self, pos, whence=0):
1044+
if not (0 <= whence <= 2):
1045+
raise ValueError("invalid whence value")
10451046
with self._read_lock:
10461047
if whence == 1:
10471048
pos -= len(self._read_buf) - self._read_pos
@@ -1137,6 +1138,8 @@ def tell(self):
11371138
return _BufferedIOMixin.tell(self) + len(self._write_buf)
11381139

11391140
def seek(self, pos, whence=0):
1141+
if not (0 <= whence <= 2):
1142+
raise ValueError("invalid whence")
11401143
with self._write_lock:
11411144
self._flush_unlocked()
11421145
return _BufferedIOMixin.seek(self, pos, whence)
@@ -1232,6 +1235,8 @@ def __init__(self, raw,
12321235
BufferedWriter.__init__(self, raw, buffer_size, max_buffer_size)
12331236

12341237
def seek(self, pos, whence=0):
1238+
if not (0 <= whence <= 2):
1239+
raise ValueError("invalid whence")
12351240
self.flush()
12361241
if self._read_buf:
12371242
# Undo read ahead.
@@ -1847,7 +1852,8 @@ def seek(self, cookie, whence=0):
18471852
self._decoder.reset()
18481853
return position
18491854
if whence != 0:
1850-
raise ValueError("unsupported whence (%r)" % (whence,))
1855+
raise ValueError("invalid whence (%r, should be 0, 1 or 2)" %
1856+
(whence,))
18511857
if cookie < 0:
18521858
raise ValueError("negative seek position %r" % (cookie,))
18531859
self.flush()

Lib/os.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ def _get_exports_list(module):
116116

117117
# Python uses fixed values for the SEEK_ constants; they are mapped
118118
# to native constants if necessary in posixmodule.c
119-
# Other possible SEEK values are directly imported from posixmodule.c
120119
SEEK_SET = 0
121120
SEEK_CUR = 1
122121
SEEK_END = 2

Lib/test/test_posix.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,26 +1009,6 @@ def test_rtld_constants(self):
10091009
posix.RTLD_GLOBAL
10101010
posix.RTLD_LOCAL
10111011

1012-
@unittest.skipUnless('PC_MIN_HOLE_SIZE' in os.pathconf_names,
1013-
"test needs an OS that reports file holes")
1014-
def test_fs_holes(self) :
1015-
# Even if the filesystem doesn't report holes,
1016-
# if the OS supports it the SEEK_* constants
1017-
# will be defined and will have a consistent
1018-
# behaviour:
1019-
# os.SEEK_DATA = current position
1020-
# os.SEEK_HOLE = end of file position
1021-
with open(support.TESTFN, 'r+b') as fp :
1022-
fp.write(b"hello")
1023-
fp.flush()
1024-
size = fp.tell()
1025-
fno = fp.fileno()
1026-
for i in range(size) :
1027-
self.assertEqual(i, os.lseek(fno, i, os.SEEK_DATA))
1028-
self.assertLessEqual(size, os.lseek(fno, i, os.SEEK_HOLE))
1029-
self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_DATA)
1030-
self.assertRaises(OSError, os.lseek, fno, size, os.SEEK_HOLE)
1031-
10321012
class PosixGroupsTester(unittest.TestCase):
10331013

10341014
def setUp(self):

Misc/NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,6 @@ Extension Modules
423423
- Issue #14259: The finditer() method of re objects did not take any
424424
keyword arguments, contrary to the documentation.
425425

426-
- Issue #10142: Support for SEEK_HOLE/SEEK_DATA (for example, under ZFS).
427-
428426
Tests
429427
-----
430428

Modules/_io/bufferedio.c

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,20 +1157,9 @@ buffered_seek(buffered *self, PyObject *args)
11571157
if (!PyArg_ParseTuple(args, "O|i:seek", &targetobj, &whence)) {
11581158
return NULL;
11591159
}
1160-
1161-
/* Do some error checking instead of trusting OS 'seek()'
1162-
** error detection, just in case.
1163-
*/
1164-
if ((whence < 0 || whence >2)
1165-
#ifdef SEEK_HOLE
1166-
&& (whence != SEEK_HOLE)
1167-
#endif
1168-
#ifdef SEEK_DATA
1169-
&& (whence != SEEK_DATA)
1170-
#endif
1171-
) {
1160+
if (whence < 0 || whence > 2) {
11721161
PyErr_Format(PyExc_ValueError,
1173-
"whence value %d unsupported", whence);
1162+
"whence must be between 0 and 2, not %d", whence);
11741163
return NULL;
11751164
}
11761165

@@ -1183,11 +1172,7 @@ buffered_seek(buffered *self, PyObject *args)
11831172
if (target == -1 && PyErr_Occurred())
11841173
return NULL;
11851174

1186-
/* SEEK_SET and SEEK_CUR are special because we could seek inside the
1187-
buffer. Other whence values must be managed without this optimization.
1188-
Some Operating Systems can provide additional values, like
1189-
SEEK_HOLE/SEEK_DATA. */
1190-
if (((whence == 0) || (whence == 1)) && self->readable) {
1175+
if (whence != 2 && self->readable) {
11911176
Py_off_t current, avail;
11921177
/* Check if seeking leaves us inside the current buffer,
11931178
so as to return quickly if possible. Also, we needn't take the

Modules/posixmodule.c

Lines changed: 0 additions & 7 deletions

0 commit comments

Comments
 (0)