fastfeedparser 0.5.9__tar.gz → 0.5.10__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastfeedparser
3
- Version: 0.5.9
3
+ Version: 0.5.10
4
4
  Summary: High performance RSS, Atom, JSON and RDF feed parser in Python
5
5
  Home-page: https://github.com/kagisearch/fastfeedparser
6
6
  Author: Vladimir Prelovac
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = fastfeedparser
3
- version = 0.5.9
3
+ version = 0.5.10
4
4
  author = Vladimir Prelovac
5
5
  author_email = vlad@kagi.com
6
6
  description = High performance RSS, Atom, JSON and RDF feed parser in Python
@@ -635,6 +635,7 @@ def _raise_for_non_feed_root(
635
635
 
636
636
 
637
637
  _RE_META_REFRESH_URL = re.compile(r'url\s*=\s*["\']?\s*([^"\'>\s]+)', re.IGNORECASE)
638
+ _MAX_META_REDIRECTS = 3
638
639
 
639
640
 
640
641
  def _extract_meta_refresh_url(content: str | bytes, base_url: str) -> str | None:
@@ -866,31 +867,32 @@ def parse(
866
867
  else:
867
868
  content = source
868
869
 
869
- try:
870
- return _parse_content(
871
- content,
872
- include_content=include_content,
873
- include_tags=include_tags,
874
- include_media=include_media,
875
- include_enclosures=include_enclosures,
876
- )
877
- except ValueError as e:
878
- if not is_url:
879
- raise
880
- assert isinstance(source, str)
881
- err_msg = str(e)
882
- if "HTML" not in err_msg and "not a valid RSS/Atom feed" not in err_msg:
883
- raise
884
- redirect_url = _extract_meta_refresh_url(content, source)
885
- if redirect_url is None:
886
- raise
887
- return parse(
888
- redirect_url,
889
- include_content=include_content,
890
- include_tags=include_tags,
891
- include_media=include_media,
892
- include_enclosures=include_enclosures,
893
- )
870
+ parse_kwargs = dict(
871
+ include_content=include_content,
872
+ include_tags=include_tags,
873
+ include_media=include_media,
874
+ include_enclosures=include_enclosures,
875
+ )
876
+
877
+ redirects_left = _MAX_META_REDIRECTS
878
+ while True:
879
+ try:
880
+ return _parse_content(content, **parse_kwargs)
881
+ except ValueError as e:
882
+ if not is_url:
883
+ raise
884
+ assert isinstance(source, str)
885
+ err_msg = str(e)
886
+ if "HTML" not in err_msg and "not a valid RSS/Atom feed" not in err_msg:
887
+ raise
888
+ if redirects_left <= 0:
889
+ raise ValueError("too many meta-refresh redirects") from e
890
+ redirect_url = _extract_meta_refresh_url(content, source)
891
+ if redirect_url is None:
892
+ raise
893
+ content = _fetch_url_content(redirect_url)
894
+ source = redirect_url
895
+ redirects_left -= 1
894
896
 
895
897
 
896
898
  def _parse_feed_info(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fastfeedparser
3
- Version: 0.5.9
3
+ Version: 0.5.10
4
4
  Summary: High performance RSS, Atom, JSON and RDF feed parser in Python
5
5
  Home-page: https://github.com/kagisearch/fastfeedparser
6
6
  Author: Vladimir Prelovac
File without changes