MCPcopy Index your code
hub / github.com/python/cpython / _readline

Method _readline

Lib/fileinput.py:301–372  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

299 # repeat with next file
300
301 def _readline(self):
302 if not self._files:
303 if 'b' in self._mode:
304 return b''
305 else:
306 return ''
307 self._filename = self._files[0]
308 self._files = self._files[1:]
309 self._startlineno = self.lineno()
310 self._filelineno = 0
311 self._file = None
312 self._isstdin = False
313 self._backupfilename = 0
314
315 # EncodingWarning is emitted in __init__() already
316 if "b" not in self._mode:
317 encoding = self._encoding or "locale"
318 else:
319 encoding = None
320
321 if self._filename == '-':
322 self._filename = '<stdin>'
323 if 'b' in self._mode:
324 self._file = getattr(sys.stdin, 'buffer', sys.stdin)
325 else:
326 self._file = sys.stdin
327 self._isstdin = True
328 else:
329 if self._inplace:
330 self._backupfilename = (
331 os.fspath(self._filename) + (self._backup or ".bak"))
332 try:
333 os.unlink(self._backupfilename)
334 except OSError:
335 pass
336 # The next few lines may raise OSError
337 os.rename(self._filename, self._backupfilename)
338 self._file = open(self._backupfilename, self._mode,
339 encoding=encoding, errors=self._errors)
340 try:
341 perm = os.fstat(self._file.fileno()).st_mode
342 except OSError:
343 self._output = open(self._filename, self._write_mode,
344 encoding=encoding, errors=self._errors)
345 else:
346 mode = os.O_CREAT | os.O_WRONLY | os.O_TRUNC
347 if hasattr(os, 'O_BINARY'):
348 mode |= os.O_BINARY
349
350 fd = os.open(self._filename, mode, perm)
351 self._output = os.fdopen(fd, self._write_mode,
352 encoding=encoding, errors=self._errors)
353 try:
354 os.chmod(self._filename, perm)
355 except OSError:
356 pass
357 self._savestdout = sys.stdout
358 sys.stdout = self._output

Callers 2

__next__Method · 0.95
readlineMethod · 0.95

Calls 7

linenoMethod · 0.95
openFunction · 0.70
unlinkMethod · 0.45
renameMethod · 0.45
filenoMethod · 0.45
openMethod · 0.45
chmodMethod · 0.45

Tested by

no test coverage detected