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

Method initfp

Lib/wave.py:263–292  ·  view source on GitHub ↗
(self, file)

Source from the content-addressed store, hash-verified

261 """
262
263 def initfp(self, file):
264 self._convert = None
265 self._soundpos = 0
266 self._file = _Chunk(file, bigendian = 0)
267 if self._file.getname() != b'RIFF':
268 raise Error('file does not start with RIFF id')
269 if self._file.read(4) != b'WAVE':
270 raise Error('not a WAVE file')
271 self._fmt_chunk_read = 0
272 self._data_chunk = None
273 while 1:
274 self._data_seek_needed = 1
275 try:
276 chunk = _Chunk(self._file, bigendian = 0)
277 except EOFError:
278 break
279 chunkname = chunk.getname()
280 if chunkname == b'fmt ':
281 self._read_fmt_chunk(chunk)
282 self._fmt_chunk_read = 1
283 elif chunkname == b'data':
284 if not self._fmt_chunk_read:
285 raise Error('data chunk before fmt chunk')
286 self._data_chunk = chunk
287 self._nframes = chunk.chunksize // self._framesize
288 self._data_seek_needed = 0
289 break
290 chunk.skip()
291 if not self._fmt_chunk_read or not self._data_chunk:
292 raise Error('fmt chunk and/or data chunk missing')
293
294 def __init__(self, f):
295 self._i_opened_the_file = None

Callers 1

__init__Method · 0.95

Calls 6

_read_fmt_chunkMethod · 0.95
_ChunkClass · 0.85
getnameMethod · 0.80
skipMethod · 0.80
ErrorClass · 0.70
readMethod · 0.45

Tested by

no test coverage detected