File: httpauth.py

package info (click to toggle)
python-scrapy 0.8-3
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,904 kB
  • ctags: 2,981
  • sloc: python: 15,349; xml: 199; makefile: 68; sql: 64; sh: 34
file content (17 lines) | stat: -rw-r--r-- 579 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
"""
HTTP basic auth downloader middleware

See documentation in docs/topics/downloader-middleware.rst
"""

from scrapy.utils.request import request_authenticate

class HttpAuthMiddleware(object):
    """This middleware allows spiders to use HTTP auth in a cleaner way
    (http_user and http_pass spider class attributes)"""

    def process_request(self, request, spider):
        http_user = getattr(spider, 'http_user', '')
        http_pass = getattr(spider, 'http_pass', '')
        if http_user or http_pass:
            request_authenticate(request, http_user, http_pass)