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

Method decode

Lib/_pyio.py:1976–2005  ·  view source on GitHub ↗
(self, input, final=False)

Source from the content-addressed store, hash-verified

1974 self.pendingcr = False
1975
1976 def decode(self, input, final=False):
1977 # decode input (with the eventual \r from a previous pass)
1978 if self.decoder is None:
1979 output = input
1980 else:
1981 output = self.decoder.decode(input, final=final)
1982 if self.pendingcr and (output or final):
1983 output = "\r" + output
1984 self.pendingcr = False
1985
1986 # retain last \r even when not translating data:
1987 # then readline() is sure to get \r\n in one pass
1988 if output.endswith("\r") and not final:
1989 output = output[:-1]
1990 self.pendingcr = True
1991
1992 # Record which newlines are read
1993 crlf = output.count('\r\n')
1994 cr = output.count('\r') - crlf
1995 lf = output.count('\n') - crlf
1996 self.seennl |= (lf and self._LF) | (cr and self._CR) \
1997 | (crlf and self._CRLF)
1998
1999 if self.translate:
2000 if crlf:
2001 output = output.replace("\r\n", "\n")
2002 if cr:
2003 output = output.replace("\r", "\n")
2004
2005 return output
2006
2007 def getstate(self):
2008 if self.decoder is None:

Callers 6

test_translateMethod · 0.95
_read_chunkMethod · 0.45
tellMethod · 0.45
seekMethod · 0.45
readMethod · 0.45
getvalueMethod · 0.45

Calls 3

endswithMethod · 0.45
countMethod · 0.45
replaceMethod · 0.45

Tested by 1

test_translateMethod · 0.76