MCPcopy Index your code
hub / github.com/RustPython/RustPython / decode

Method decode

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

Source from the content-addressed store, hash-verified

1950 self.pendingcr = False
1951
1952 def decode(self, input, final=False):
1953 # decode input (with the eventual \r from a previous pass)
1954 if self.decoder is None:
1955 output = input
1956 else:
1957 output = self.decoder.decode(input, final=final)
1958 if self.pendingcr and (output or final):
1959 output = "\r" + output
1960 self.pendingcr = False
1961
1962 # retain last \r even when not translating data:
1963 # then readline() is sure to get \r\n in one pass
1964 if output.endswith("\r") and not final:
1965 output = output[:-1]
1966 self.pendingcr = True
1967
1968 # Record which newlines are read
1969 crlf = output.count('\r\n')
1970 cr = output.count('\r') - crlf
1971 lf = output.count('\n') - crlf
1972 self.seennl |= (lf and self._LF) | (cr and self._CR) \
1973 | (crlf and self._CRLF)
1974
1975 if self.translate:
1976 if crlf:
1977 output = output.replace("\r\n", "\n")
1978 if cr:
1979 output = output.replace("\r", "\n")
1980
1981 return output
1982
1983 def getstate(self):
1984 if self.decoder is None:

Callers 8

test_translateMethod · 0.95
decode_sourceFunction · 0.95
decode_sourceFunction · 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