MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / read

Method read

17-it-generator/isis2json/iso2709.py:48–66  ·  view source on GitHub ↗

read and drop all CR and LF characters

(self, size)

Source from the content-addressed store, hash-verified

46 __next__ = next # Python 3 compatibility
47
48 def read(self, size):
49 ''' read and drop all CR and LF characters '''
50 # TODO: this is inneficient but works, patches accepted!
51 # NOTE: our fixtures include files which have no linebreaks,
52 # files with CR-LF linebreaks and files with LF linebreaks
53 chunks = []
54 count = 0
55 while count < size:
56 chunk = self.file.read(size-count)
57 if len(chunk) == 0:
58 break
59 chunk = chunk.replace(CR+LF,'')
60 if CR in chunk:
61 chunk = chunk.replace(CR,'')
62 if LF in chunk:
63 chunk = chunk.replace(LF,'')
64 count += len(chunk)
65 chunks.append(chunk)
66 return ''.join(chunks)
67
68 def close(self):
69 self.file.close()

Callers 15

get_flagFunction · 0.80
handle_echoFunction · 0.80
handle_echoFunction · 0.80
readcharFunction · 0.80
mainFunction · 0.80
mainFunction · 0.80
_get_body_stringMethod · 0.80
load_configMethod · 0.80
_file_iter_rangeFunction · 0.80
__init__Method · 0.80
loaderMethod · 0.80
codeMethod · 0.80

Calls 2

replaceMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected