MCPcopy
hub / github.com/pyload/pyload / _open_resource

Function _open_resource

module/lib/feedparser.py:2819–2901  ·  view source on GitHub ↗

URL, filename, or string --> stream This function lets you define parsers that take any input source (URL, pathname to local or network file, or actual data as a string) and deal with it in a uniform manner. Returned object is guaranteed to have all the basic stdio read methods (re

(url_file_stream_or_string, etag, modified, agent, referrer, handlers, request_headers)

Source from the content-addressed store, hash-verified

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
2821
2822 This function lets you define parsers that take any input source
2823 (URL, pathname to local or network file, or actual data as a string)
2824 and deal with it in a uniform manner. Returned object is guaranteed
2825 to have all the basic stdio read methods (read, readline, readlines).
2826 Just .close() the object when you're done with it.
2827
2828 If the etag argument is supplied, it will be used as the value of an
2829 If-None-Match request header.
2830
2831 If the modified argument is supplied, it can be a tuple of 9 integers
2832 (as returned by gmtime() in the standard Python time module) or a date
2833 string in any format supported by feedparser. Regardless, it MUST
2834 be in GMT (Greenwich Mean Time). It will be reformatted into an
2835 RFC 1123-compliant date and used as the value of an If-Modified-Since
2836 request header.
2837
2838 If the agent argument is supplied, it will be used as the value of a
2839 User-Agent request header.
2840
2841 If the referrer argument is supplied, it will be used as the value of a
2842 Referer[sic] request header.
2843
2844 If handlers is supplied, it is a list of handlers used to build a
2845 urllib2 opener.
2846
2847 if request_headers is supplied it is a dictionary of HTTP request headers
2848 that will override the values generated by FeedParser.
2849 """
2850
2851 if hasattr(url_file_stream_or_string, 'read'):
2852 return url_file_stream_or_string
2853
2854 if url_file_stream_or_string == '-':
2855 return sys.stdin
2856
2857 if urlparse.urlparse(url_file_stream_or_string)[0] in ('http', 'https', 'ftp', 'file', 'feed'):
2858 # Deal with the feed URI scheme
2859 if url_file_stream_or_string.startswith('feed:http'):
2860 url_file_stream_or_string = url_file_stream_or_string[5:]
2861 elif url_file_stream_or_string.startswith('feed:'):
2862 url_file_stream_or_string = 'http:' + url_file_stream_or_string[5:]
2863 if not agent:
2864 agent = USER_AGENT
2865 # test for inline user:password for basic auth
2866 auth = None
2867 if base64:
2868 urltype, rest = urllib.splittype(url_file_stream_or_string)
2869 realhost, rest = urllib.splithost(rest)
2870 if realhost:
2871 user_passwd, realhost = urllib.splituser(realhost)
2872 if user_passwd:
2873 url_file_stream_or_string = '%s://%s%s' % (urltype, realhost, rest)
2874 auth = base64.standard_b64encode(user_passwd).strip()
2875
2876 # iri support

Callers 1

parseFunction · 0.85

Calls 6

_build_urllib2_requestFunction · 0.85
_FeedURLHandlerClass · 0.85
decodeMethod · 0.80
encodeMethod · 0.45
openMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected