MCPcopy Create free account
hub / github.com/kurtmckee/feedparser / parse

Function parse

feedparser/api.py:152–277  ·  view source on GitHub ↗

Parse a feed from a URL, file, stream, or string. :param url_file_stream_or_string: File-like object, URL, file path, or string. Both byte and text strings are accepted. If necessary, encoding will be derived from the response headers or automatically detected.

(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=None, request_headers=None, response_headers=None, resolve_relative_uris=None, sanitize_html=None)

Source from the content-addressed store, hash-verified

150
151
152def parse(url_file_stream_or_string, etag=None, modified=None, agent=None, referrer=None, handlers=None, request_headers=None, response_headers=None, resolve_relative_uris=None, sanitize_html=None):
153 """Parse a feed from a URL, file, stream, or string.
154
155 :param url_file_stream_or_string:
156 File-like object, URL, file path, or string. Both byte and text strings
157 are accepted. If necessary, encoding will be derived from the response
158 headers or automatically detected.
159
160 Note that strings may trigger network I/O or filesystem access
161 depending on the value. Wrap an untrusted string in
162 a :class:`io.StringIO` or :class:`io.BytesIO` to avoid this. Do not
163 pass untrusted strings to this function.
164
165 When a URL is not passed the feed location to use in relative URL
166 resolution should be passed in the ``Content-Location`` response header
167 (see ``response_headers`` below).
168
169 :param str etag: HTTP ``ETag`` request header.
170 :param modified: HTTP ``Last-Modified`` request header.
171 :type modified: :class:`str`, :class:`time.struct_time` 9-tuple, or
172 :class:`datetime.datetime`
173 :param str agent: HTTP ``User-Agent`` request header, which defaults to
174 the value of :data:`feedparser.USER_AGENT`.
175 :param referrer: HTTP ``Referer`` [sic] request header.
176 :param request_headers:
177 A mapping of HTTP header name to HTTP header value to add to the
178 request, overriding internally generated values.
179 :type request_headers: :class:`dict` mapping :class:`str` to :class:`str`
180 :param response_headers:
181 A mapping of HTTP header name to HTTP header value. Multiple values may
182 be joined with a comma. If a HTTP request was made, these headers
183 override any matching headers in the response. Otherwise this specifies
184 the entirety of the response headers.
185 :type response_headers: :class:`dict` mapping :class:`str` to :class:`str`
186
187 :param bool resolve_relative_uris:
188 Should feedparser attempt to resolve relative URIs absolute ones within
189 HTML content? Defaults to the value of
190 :data:`feedparser.RESOLVE_RELATIVE_URIS`, which is ``True``.
191 :param bool sanitize_html:
192 Should feedparser skip HTML sanitization? Only disable this if you know
193 what you are doing! Defaults to the value of
194 :data:`feedparser.SANITIZE_HTML`, which is ``True``.
195
196 :return: A :class:`FeedParserDict`.
197 """
198
199 if not agent or sanitize_html is None or resolve_relative_uris is None:
200 import feedparser
201 if not agent:
202 agent = feedparser.USER_AGENT
203 if sanitize_html is None:
204 sanitize_html = feedparser.SANITIZE_HTML
205 if resolve_relative_uris is None:
206 resolve_relative_uris = feedparser.RESOLVE_RELATIVE_URIS
207
208 result = FeedParserDict(
209 bozo=False,

Callers

nothing calls this directly

Calls 7

getMethod · 0.95
FeedParserDictClass · 0.85
_open_resourceFunction · 0.85
replace_doctypeFunction · 0.85
make_safe_absolute_uriFunction · 0.85
feedMethod · 0.80
convert_to_utf8Function · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…