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)
| 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 |
| 2946 | |
| 2947 | This function lets you define parsers that take any input source |
| 2948 | (URL, pathname to local or network file, or actual data as a string) |
| 2949 | and deal with it in a uniform manner. Returned object is guaranteed |
| 2950 | to have all the basic stdio read methods (read, readline, readlines). |
| 2951 | Just .close() the object when you're done with it. |
| 2952 | |
| 2953 | If the etag argument is supplied, it will be used as the value of an |
| 2954 | If-None-Match request header. |
| 2955 | |
| 2956 | If the modified argument is supplied, it can be a tuple of 9 integers |
| 2957 | (as returned by gmtime() in the standard Python time module) or a date |
| 2958 | string in any format supported by feedparser. Regardless, it MUST |
| 2959 | be in GMT (Greenwich Mean Time). It will be reformatted into an |
| 2960 | RFC 1123-compliant date and used as the value of an If-Modified-Since |
| 2961 | request header. |
| 2962 | |
| 2963 | If the agent argument is supplied, it will be used as the value of a |
| 2964 | User-Agent request header. |
| 2965 | |
| 2966 | If the referrer argument is supplied, it will be used as the value of a |
| 2967 | Referer[sic] request header. |
| 2968 | |
| 2969 | If handlers is supplied, it is a list of handlers used to build a |
| 2970 | urllib2 opener. |
| 2971 | |
| 2972 | if request_headers is supplied it is a dictionary of HTTP request headers |
| 2973 | that will override the values generated by FeedParser. |
| 2974 | """ |
| 2975 | |
| 2976 | if hasattr(url_file_stream_or_string, 'read'): |
| 2977 | return url_file_stream_or_string |
| 2978 | |
| 2979 | if isinstance(url_file_stream_or_string, basestring) \ |
| 2980 | and urlparse.urlparse(url_file_stream_or_string)[0] in ('http', 'https', 'ftp', 'file', 'feed'): |
| 2981 | # Deal with the feed URI scheme |
| 2982 | if url_file_stream_or_string.startswith('feed:http'): |
| 2983 | url_file_stream_or_string = url_file_stream_or_string[5:] |
| 2984 | elif url_file_stream_or_string.startswith('feed:'): |
| 2985 | url_file_stream_or_string = 'http:' + url_file_stream_or_string[5:] |
| 2986 | if not agent: |
| 2987 | agent = USER_AGENT |
| 2988 | # test for inline user:password for basic auth |
| 2989 | auth = None |
| 2990 | if base64: |
| 2991 | urltype, rest = urllib.splittype(url_file_stream_or_string) |
| 2992 | realhost, rest = urllib.splithost(rest) |
| 2993 | if realhost: |
| 2994 | user_passwd, realhost = urllib.splituser(realhost) |
| 2995 | if user_passwd: |
| 2996 | url_file_stream_or_string = '%s://%s%s' % (urltype, realhost, rest) |
| 2997 | auth = base64.standard_b64encode(user_passwd).strip() |
| 2998 | |
| 2999 | # iri support |
| 3000 | if isinstance(url_file_stream_or_string, unicode): |
| 3001 | url_file_stream_or_string = _convert_to_idn(url_file_stream_or_string) |
no test coverage detected
searching dependent graphs…