httpobj.py 516 B

1234567891011121314
  1. """Helper functions for scrapy.http objects (Request, Response)"""
  2. import weakref
  3. from six.moves.urllib.parse import urlparse
  4. _urlparse_cache = weakref.WeakKeyDictionary()
  5. def urlparse_cached(request_or_response):
  6. """Return urlparse.urlparse caching the result, where the argument can be a
  7. Request or Response object
  8. """
  9. if request_or_response not in _urlparse_cache:
  10. _urlparse_cache[request_or_response] = urlparse(request_or_response.url)
  11. return _urlparse_cache[request_or_response]