http.py 905 B

12345678910111213141516171819202122232425262728293031323334353637
  1. """
  2. Transitional module for moving to the w3lib library.
  3. For new code, always import from w3lib.http instead of this module
  4. """
  5. import warnings
  6. from scrapy.exceptions import ScrapyDeprecationWarning
  7. from scrapy.utils.decorators import deprecated
  8. from w3lib.http import *
  9. warnings.warn("Module `scrapy.utils.http` is deprecated, "
  10. "Please import from `w3lib.http` instead.",
  11. ScrapyDeprecationWarning, stacklevel=2)
  12. @deprecated
  13. def decode_chunked_transfer(chunked_body):
  14. """Parsed body received with chunked transfer encoding, and return the
  15. decoded body.
  16. For more info see:
  17. https://en.wikipedia.org/wiki/Chunked_transfer_encoding
  18. """
  19. body, h, t = '', '', chunked_body
  20. while t:
  21. h, t = t.split('\r\n', 1)
  22. if h == '0':
  23. break
  24. size = int(h, 16)
  25. body += t[:size]
  26. t = t[size+2:]
  27. return body