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

Method readline

pexpect/spawnbase.py:473–492  ·  view source on GitHub ↗

This reads and returns one entire line. The newline at the end of line is returned as part of the string, unless the file ends without a newline. An empty string is returned if EOF is encountered immediately. This looks for a newline as a CR/LF pair (\\r\\n) even on UNIX beca

(self, size=-1)

Source from the content-addressed store, hash-verified

471 return self.before
472
473 def readline(self, size=-1):
474 '''This reads and returns one entire line. The newline at the end of
475 line is returned as part of the string, unless the file ends without a
476 newline. An empty string is returned if EOF is encountered immediately.
477 This looks for a newline as a CR/LF pair (\\r\\n) even on UNIX because
478 this is what the pseudotty device returns. So contrary to what you may
479 expect you will receive newlines as \\r\\n.
480
481 If the size argument is 0 then an empty string is returned. In all
482 other cases the size argument is ignored, which is not standard
483 behavior for a file-like object. '''
484
485 if size == 0:
486 return self.string_type()
487 # delimiter default is EOF
488 index = self.expect([self.crlf, self.delimiter])
489 if index == 0:
490 return self.before + self.crlf
491 else:
492 return self.before
493
494 def __iter__(self):
495 '''This is to support iterators over a file-like object.

Callers 8

readlinesMethod · 0.95
test_readlineMethod · 0.80
test_writeMethod · 0.80
test_writelinesMethod · 0.80
test_spawn_uses_envMethod · 0.80

Calls 1

expectMethod · 0.95

Tested by 7

test_readlineMethod · 0.64
test_writeMethod · 0.64
test_writelinesMethod · 0.64
test_spawn_uses_envMethod · 0.64