MCPcopy Create free account
hub / github.com/pexpect/pexpect / read

Method read

pexpect/spawnbase.py:444–471  ·  view source on GitHub ↗

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 encounter

(self, size=-1)

Source from the content-addressed store, hash-verified

442 return exp.expect_loop(timeout)
443
444 def read(self, size=-1):
445 '''This reads at most "size" bytes from the file (less if the read hits
446 EOF before obtaining size bytes). If the size argument is negative or
447 omitted, read all data until EOF is reached. The bytes are returned as
448 a string object. An empty string is returned when EOF is encountered
449 immediately. '''
450
451 if size == 0:
452 return self.string_type()
453 if size < 0:
454 # delimiter default is EOF
455 self.expect(self.delimiter)
456 return self.before
457
458 # I could have done this more directly by not using expect(), but
459 # I deliberately decided to couple read() to expect() so that
460 # I would catch any bugs early and ensure consistent behavior.
461 # It's a little less efficient, but there is less for me to
462 # worry about if I have to later modify read() or expect().
463 # Note, it's OK if size==-1 in the regex. That just means it
464 # will never match anything in which case we stop only on EOF.
465 cre = re.compile(self._coerce_expect_string('.{%d}' % size), re.DOTALL)
466 # delimiter default is EOF
467 index = self.expect([cre, self.delimiter])
468 if index == 0:
469 ### FIXME self.before should be ''. Should I assert this?
470 return self.after
471 return self.before
472
473 def readline(self, size=-1):
474 ''&#x27;This reads and returns one entire line. The newline at the end of

Callers 15

_read_incomingMethod · 0.80
__interact_readMethod · 0.80
read_nonblockingMethod · 0.80
existing_dataMethod · 0.80
new_dataMethod · 0.80
my_forkpty.pyFile · 0.80
test_crlfMethod · 0.80
test_crlf_encodingMethod · 0.80
open_file_socketFunction · 0.80
test_torturetMethod · 0.80
test_tetrisMethod · 0.80
test_readMethod · 0.80

Calls 2

expectMethod · 0.95
_coerce_expect_stringMethod · 0.95

Tested by 13

test_crlfMethod · 0.64
test_crlf_encodingMethod · 0.64
open_file_socketFunction · 0.64
test_torturetMethod · 0.64
test_tetrisMethod · 0.64
test_readMethod · 0.64
test_read_pollMethod · 0.64
test_logMethod · 0.64
test_log_logfile_readMethod · 0.64
test_log_logfile_sendMethod · 0.64