10 examples of 'eof when reading a line python' in Python

Every line of 'eof when reading a line python' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
139def read(vm):
140 line = vm.input.readline().rstrip()
141 vm.push(line)
142
143 # To be compatible with the old code that relied on raw_input raising
144 # EOFError, we should also do it for a while (later on, we should use
145 # another mechanism).
146 if line == "":
147 raise EOFError()
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

59def eof(self):
60 self.dedent_to(0)
16def readline(self):
17 if self.stack:
18 self.line_number += 1
19 return self.stack.pop()
20 else:
21 line = self.f.readline()
22 if line != "":
23 self.line_number += 1
24 return line
915def _next_line(self):
916 # This provides a single line of "unget" if _reuse_line is set to True
917 if not self._reuse_line:
918 self._line = self._file.readline()
919 self._linenr += 1
920
921 self._reuse_line = False
922
923 while self._line.endswith("\\\n"):
924 self._line = self._line[:-2] + self._file.readline()
925 self._linenr += 1
926
927 return self._line
469def peek(self):
470 saved = self.sy, self.systring
471 self.next()
472 next = self.sy, self.systring
473 self.unread(*next)
474 self.sy, self.systring = saved
475 return next
82def _GetLine(self):
83 # type: () -> Optional[str]
84 line = self.f.readline()
85 if len(line) == 0:
86 return None
87
88 if not line.endswith('\n'):
89 self.last_line_hint = True
90
91 return line
27def test_eof():
28 class TestParser(Parser):
29 def parse(self):
30 data = yield self.read_until(b'\r\n\r\n', max_bytes=100)
31 yield data
32 test_parser = TestParser()
33 test_data = [b'foo', b'']
34 assert not test_parser.is_eof
35 with pytest.raises(ParseError):
36 for data in test_data:
37 for _token in test_parser.feed(data):
38 print(_token)
39 assert test_parser.is_eof
40 test_parser.feed(b'more')
41 with pytest.raises(ParseError):
42 for data in test_parser.feed('foo'):
43 print(data)
61@staticmethod
62def do_EOF(dummy):
63 return True
84def peek_line(self, line_num):
85 if (line_num >= 0) and (line_num < len(self._lines)):
86 return self._lines[line_num]
87 else:
88 return None
1084def skipWhitespace(self, allow_eof=True):
1085 try:
1086 skipped = True
1087 while skipped:
1088 skipped = False
1089
1090 # Skip whitespace
1091 while self.code[self.pos] in whitespace:
1092 skipped = True
1093 self.pos += 1
1094
1095 # Skip ; comment
1096 if self.code[self.pos] == ";":
1097 # Comment
1098 skipped = True
1099 while self.code[self.pos] != "\n":
1100 self.pos += 1
1101
1102 # Skip // comment
1103 if self.code[self.pos:self.pos + 2] == "//":
1104 # Comment
1105 skipped = True
1106 while self.code[self.pos] != "\n":
1107 self.pos += 1
1108 except IndexError:
1109 if not allow_eof:
1110 raise InvalidError("Unexpected EOF")

Related snippets