Logo Search packages:      
Sourcecode: kayali version File versions  Download package

def pexpect::spawn::read (   self,
  size = -1 
)

This reads at most size bytes from the file 
(less if the read hits EOF before obtaining size bytes). 
If the size argument is negative or omitted, 
read all data until EOF is reached. 
The bytes are returned as a string object. 
An empty string is returned when EOF is encountered immediately.

Definition at line 402 of file pexpect.py.

00402                               :   # File-like object.
        """This reads at most size bytes from the file 
        (less if the read hits EOF before obtaining size bytes). 
        If the size argument is negative or omitted, 
        read all data until EOF is reached. 
        The bytes are returned as a string object. 
        An empty string is returned when EOF is encountered immediately.
        """
        if size == 0:
            return ''
        if size < 0:
            self.expect (EOF)
            return self.before

        # I could have done this more directly by not using expect(), but
        # I deliberately decided to couple read() to expect() so that
        # I would catch any bugs early and ensure consistant behavior.
        # It's a little less efficient, but there is less for me to
        # worry about if I have to later modify read() or expect().
        cre = re.compile('.{%d}' % size, re.DOTALL) 
        index = self.expect ([cre, EOF])
        if index == 0:
            return self.after ### self.before should be ''. Should I assert this?
        return self.before
        


Generated by  Doxygen 1.6.0   Back to index