MCPcopy Index your code
hub / github.com/pyload/pyload / _FeedURLHandler

Class _FeedURLHandler

module/lib/feedparser.py:2765–2817  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2763 return data
2764
2765class _FeedURLHandler(urllib2.HTTPDigestAuthHandler, urllib2.HTTPRedirectHandler, urllib2.HTTPDefaultErrorHandler):
2766 def http_error_default(self, req, fp, code, msg, headers):
2767 if ((code / 100) == 3) and (code != 304):
2768 return self.http_error_302(req, fp, code, msg, headers)
2769 infourl = urllib.addinfourl(fp, headers, req.get_full_url())
2770 infourl.status = code
2771 return infourl
2772
2773 def http_error_302(self, req, fp, code, msg, headers):
2774 if headers.dict.has_key('location'):
2775 infourl = urllib2.HTTPRedirectHandler.http_error_302(self, req, fp, code, msg, headers)
2776 else:
2777 infourl = urllib.addinfourl(fp, headers, req.get_full_url())
2778 if not hasattr(infourl, 'status'):
2779 infourl.status = code
2780 return infourl
2781
2782 def http_error_301(self, req, fp, code, msg, headers):
2783 if headers.dict.has_key('location'):
2784 infourl = urllib2.HTTPRedirectHandler.http_error_301(self, req, fp, code, msg, headers)
2785 else:
2786 infourl = urllib.addinfourl(fp, headers, req.get_full_url())
2787 if not hasattr(infourl, 'status'):
2788 infourl.status = code
2789 return infourl
2790
2791 http_error_300 = http_error_302
2792 http_error_303 = http_error_302
2793 http_error_307 = http_error_302
2794
2795 def http_error_401(self, req, fp, code, msg, headers):
2796 # Check if
2797 # - server requires digest auth, AND
2798 # - we tried (unsuccessfully) with basic auth, AND
2799 # - we're using Python 2.3.3 or later (digest auth is irreparably broken in earlier versions)
2800 # If all conditions hold, parse authentication information
2801 # out of the Authorization header we sent the first time
2802 # (for the username and password) and the WWW-Authenticate
2803 # header the server sent back (for the realm) and retry
2804 # the request with the appropriate digest auth headers instead.
2805 # This evil genius hack has been brought to you by Aaron Swartz.
2806 host = urlparse.urlparse(req.get_full_url())[1]
2807 try:
2808 assert sys.version.split()[0] >= '2.3.3'
2809 assert base64 is not None
2810 user, passw = _base64decode(req.headers['Authorization'].split(' ')[1]).split(':')
2811 realm = re.findall('realm="([^"]*)"', headers['WWW-Authenticate'])[0]
2812 self.add_password(realm, host, user, passw)
2813 retry = self.http_error_auth_reqed('www-authenticate', host, req, headers)
2814 self.reset_retry_count()
2815 return retry
2816 except:
2817 return self.http_error_default(req, fp, code, msg, headers)
2818
2819def _open_resource(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers):
2820 """URL, filename, or string --> stream

Callers 1

_open_resourceFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected