| 2899 | return data |
| 2900 | |
| 2901 | class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler): |
| 2902 | def http_error_default(self, req, fp, code, msg, headers): |
| 2903 | # The default implementation just raises HTTPError. |
| 2904 | # Forget that. |
| 2905 | fp.status = code |
| 2906 | return fp |
| 2907 | |
| 2908 | def http_error_301(self, req, fp, code, msg, hdrs): |
| 2909 | result = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, |
| 2910 | code, msg, hdrs) |
| 2911 | result.status = code |
| 2912 | result.newurl = result.geturl() |
| 2913 | return result |
| 2914 | # The default implementations in urllib2.HTTPRedirectHandler |
| 2915 | # are identical, so hardcoding a http_error_301 call above |
| 2916 | # won't affect anything |
| 2917 | http_error_300 = http_error_301 |
| 2918 | http_error_302 = http_error_301 |
| 2919 | http_error_303 = http_error_301 |
| 2920 | http_error_307 = http_error_301 |
| 2921 | |
| 2922 | def http_error_401(self, req, fp, code, msg, headers): |
| 2923 | # Check if |
| 2924 | # - server requires digest auth, AND |
| 2925 | # - we tried (unsuccessfully) with basic auth, AND |
| 2926 | # If all conditions hold, parse authentication information |
| 2927 | # out of the Authorization header we sent the first time |
| 2928 | # (for the username and password) and the WWW-Authenticate |
| 2929 | # header the server sent back (for the realm) and retry |
| 2930 | # the request with the appropriate digest auth headers instead. |
| 2931 | # This evil genius hack has been brought to you by Aaron Swartz. |
| 2932 | host = urlparse.urlparse(req.get_full_url())[1] |
| 2933 | if base64 is None or 'Authorization' not in req.headers \ |
| 2934 | or 'WWW-Authenticate' not in headers: |
| 2935 | return self.http_error_default(req, fp, code, msg, headers) |
| 2936 | auth = _base64decode(req.headers['Authorization'].split(' ')[1]) |
| 2937 | user, passw = auth.split(':') |
| 2938 | realm = re.findall('realm="([^"]*)"', headers['WWW-Authenticate'])[0] |
| 2939 | self.add_password(realm, host, user, passw) |
| 2940 | retry = self.http_error_auth_reqed('www-authenticate', host, req, headers) |
| 2941 | self.reset_retry_count() |
| 2942 | return retry |
| 2943 | |
| 2944 | def _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers): |
| 2945 | """URL, filename, or string --> stream |
no outgoing calls
no test coverage detected
searching dependent graphs…