MCPcopy
hub / github.com/aio-libs/aiohttp / readline

Method readline

aiohttp/multipart.py:340–370  ·  view source on GitHub ↗

Reads body part by line by line. :rtype: bytearray

(self)

Source from the content-addressed store, hash-verified

338
339 @asyncio.coroutine
340 def readline(self):
341 """Reads body part by line by line.
342
343 :rtype: bytearray
344 """
345 if self._at_eof:
346 return b''
347
348 if self._unread:
349 line = self._unread.popleft()
350 else:
351 line = yield from self._content.readline()
352
353 if line.startswith(self._boundary):
354 # the very last boundary may not come with \r\n,
355 # so set single rules for everyone
356 sline = line.rstrip(b'\r\n')
357 boundary = self._boundary
358 last_boundary = self._boundary + b'--'
359 # ensure that we read exactly the boundary, not something alike
360 if sline == boundary or sline == last_boundary:
361 self._at_eof = True
362 self._unread.append(line)
363 return b''
364 else:
365 next_line = yield from self._content.readline()
366 if next_line.startswith(self._boundary):
367 line = line[:-2] # strip CRLF but only once
368 self._unread.append(next_line)
369
370 return line
371
372 @asyncio.coroutine
373 def release(self):

Callers 5

readMethod · 0.95
releaseMethod · 0.95
read_chunkMethod · 0.45
_readlineMethod · 0.45
_read_headersMethod · 0.45

Calls 1

appendMethod · 0.80

Tested by

no test coverage detected