Reads body part by line by line. :rtype: bytearray
(self)
| 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): |
no test coverage detected