Skip to content

Commit 6f8b65f

Browse files
committed
builtin _io remove unused code from _BufferedIOBase and BytesIO.
1 parent 3d33795 commit 6f8b65f

File tree

1 file changed

+12
-91
lines changed
  • graalpython/lib-graalpython

1 file changed

+12
-91
lines changed

graalpython/lib-graalpython/_io.py

Lines changed: 12 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -543,99 +543,17 @@ def truncate(self, size=-1):
543543
sys.__stderr__ = sys.stderr
544544

545545

546+
# ----------------------------------------------------------------------------------------------------------------------
547+
#
548+
# following definitions: patched in the __builtins_patches__ module
549+
#
550+
# ----------------------------------------------------------------------------------------------------------------------
546551
class _BufferedIOBase(_IOBase):
547-
"""Base class for buffered IO objects.
548-
549-
The main difference with RawIOBase is that the read() method
550-
supports omitting the size argument, and does not have a default
551-
implementation that defers to readinto().
552-
553-
In addition, read(), readinto() and write() may raise
554-
BlockingIOError if the underlying raw stream is in non-blocking
555-
mode and not ready; unlike their raw counterparts, they will never
556-
return None.
557-
558-
A typical implementation should not inherit from a RawIOBase
559-
implementation, but wrap one.
560-
"""
561-
562-
def _check_init(self):
563-
raise NotImplementedError
564-
565-
def read(self, size=None):
566-
"""Read and return up to n bytes.
567-
568-
If the argument is omitted, None, or negative, reads and
569-
returns all data until EOF.
570-
571-
If the argument is positive, and the underlying raw stream is
572-
not 'interactive', multiple raw reads may be issued to satisfy
573-
the byte count (unless EOF is reached first). But for
574-
interactive raw streams (as well as sockets and pipes), at most
575-
one raw read will be issued, and a short result does not imply
576-
that EOF is imminent.
577-
578-
Returns an empty bytes object on EOF.
579-
580-
Returns None if the underlying raw stream was open in non-blocking
581-
mode and no data is available at the moment."""
582-
raise UnsupportedOperation("read")
583-
584-
def read1(self, size):
585-
"""Read and return up to n bytes, with at most one read() call
586-
to the underlying raw stream. A short result does not imply
587-
that EOF is imminent.
588-
589-
Returns an empty bytes object on EOF."""
590-
raise UnsupportedOperation("read1")
591-
592-
def write(self, data):
593-
"""Write the given buffer to the IO stream.
594-
595-
Returns the number of bytes written, which is always the length of b
596-
in bytes.
597-
598-
Raises BlockingIOError if the buffer is full and the
599-
underlying raw stream cannot accept more data at the moment."""
600-
raise UnsupportedOperation("write")
601-
602-
def detach(self):
603-
"""Disconnect this buffer from its underlying raw stream and return it.
604-
605-
After the raw stream has been detached, the buffer is in an unusable
606-
state."""
607-
raise UnsupportedOperation("detach")
608-
609-
def readinto(self, space, buffer):
610-
length = len(buffer)
611-
data = self.read(length)
612-
if not isinstance(data, bytes):
613-
raise TypeError("read() should return bytes")
614-
ldata = len(data)
615-
if ldata > length:
616-
raise ValueError("read() returned too much data: "
617-
"%d bytes requested, %d returned" % (length, ldata))
618-
buffer[0:ldata] = data
619-
return ldata
620-
621-
def readinto1(self, buffer):
622-
length = len(buffer)
623-
data = self.read1(length)
624-
if not isinstance(data, bytes):
625-
raise TypeError("read1() should return bytes")
626-
ldata = len(data)
627-
if ldata > length:
628-
raise ValueError("read1() returned too much data: "
629-
"%d bytes requested, %d returned" % (length, ldata))
630-
buffer[0:ldata] = data
631-
return ldata
552+
pass
632553

633554

634555
class BytesIO(_BufferedIOBase):
635-
def __init__(self, inital_bytes=None):
636-
if inital_bytes:
637-
self.write(inital_bytes)
638-
self.seek(0)
556+
pass
639557

640558

641559
class _TextIOBase(_IOBase):
@@ -671,11 +589,14 @@ class TextIOWrapper(_TextIOBase):
671589

672590

673591
def open(*args, **kwargs):
674-
# this method will be overwritten in _patches
675592
raise NotImplementedError
676593

677594

678-
# set the builtins open method
595+
# ----------------------------------------------------------------------------------------------------------------------
596+
#
597+
# needed for imports will be patched in the __builtins_patches__ module
598+
#
599+
# ----------------------------------------------------------------------------------------------------------------------
679600
import builtins
680601
setattr(builtins, 'open', open)
681602
globals()['open'] = open

0 commit comments

Comments
 (0)