@@ -543,99 +543,17 @@ def truncate(self, size=-1):
543
543
sys .__stderr__ = sys .stderr
544
544
545
545
546
+ # ----------------------------------------------------------------------------------------------------------------------
547
+ #
548
+ # following definitions: patched in the __builtins_patches__ module
549
+ #
550
+ # ----------------------------------------------------------------------------------------------------------------------
546
551
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
632
553
633
554
634
555
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
639
557
640
558
641
559
class _TextIOBase (_IOBase ):
@@ -671,11 +589,14 @@ class TextIOWrapper(_TextIOBase):
671
589
672
590
673
591
def open (* args , ** kwargs ):
674
- # this method will be overwritten in _patches
675
592
raise NotImplementedError
676
593
677
594
678
- # set the builtins open method
595
+ # ----------------------------------------------------------------------------------------------------------------------
596
+ #
597
+ # needed for imports will be patched in the __builtins_patches__ module
598
+ #
599
+ # ----------------------------------------------------------------------------------------------------------------------
679
600
import builtins
680
601
setattr (builtins , 'open' , open )
681
602
globals ()['open' ] = open
0 commit comments