Philipp Hörist pushed to branch generate-ogp-previews at gajim / gajim


Commits:
4fccb057 by Philipp Hörist at 2026-02-15T15:31:05+01:00
cfix: Simplify open graph parser

- - - - -


1 changed file:

- gajim/common/open_graph_parser.py


Changes:

=====================================
gajim/common/open_graph_parser.py
=====================================
@@ -32,13 +32,13 @@ def handle_starttag(self, tag: str, attrs: list[tuple[str, 
str | None]]) -> None
         if not (prop := attrs_dict.get("property")):
             return
 
-        if not prop.startswith("og:"):
+        if prop not in ALLOWED_OG_PROPERTIES:
             return
 
         if not (content := attrs_dict.get("content")):
             return
 
-        self._attributes[prop] = content
+        self._attributes[prop.removeprefix("og:")] = content
 
     def handle_endtag(self, tag: str) -> None:
         if tag == "head":
@@ -50,19 +50,10 @@ def parse(self, text: str) -> OpenGraphData | None:
         except EOF:
             pass
 
-        open_graph_data: dict[str, str] = {}
-        any_data_found = False
-        for og_type, content in self._attributes.items():
-            if og_type not in (ALLOWED_OG_PROPERTIES):
-                continue
-
-            any_data_found = True
-            open_graph_data[og_type[3:]] = content
-
-        if not any_data_found:
+        if not self._attributes:
             return None
 
-        return OpenGraphData(**open_graph_data)
+        return OpenGraphData(**self._attributes)
 
 
 class EOF(Exception):



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/4fccb057dd860138246b1edba824776daa631e49

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/4fccb057dd860138246b1edba824776daa631e49
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to