Skip to content

Commit

Permalink
Pattern matching is python 3.10 only.
Browse files Browse the repository at this point in the history
  • Loading branch information
mgautierfr committed Dec 18, 2023
1 parent e6eeac5 commit 63cfb53
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions src/warc2zim/content_rewriting.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,23 +147,22 @@ def process_list(self, components: Iterable[TCSS2Node]):
self.process(component)

def process(self, component: TCSS2Node):
match component.type:
case "qualified-rule" | "() block" | "[] block" | "{} block":
self.process_list(component.content)
case "function":
if component.lower_name == "url":
url_component = component.arguments[0]
new_url = self.url_rewriter(url_component.value)
url_component.value = new_url
url_component.representation = f'"{serialize_url(new_url)}"'
else:
self.process_list(component.arguments)
case "at-rule":
self.process_list(component.prelude)
self.process_list(component.content)
case "declaration":
self.process_list(component.value)
case "url":
new_url = self.url_rewriter(component.value)
component.value = new_url
component.representation = f"url({serialize_url(new_url)})"
if component.type in ("qualified-rule", "() block", "[] block", "{} block"):
self.process_list(component.content)
elif component.type == "function":
if component.lower_name == "url":
url_component = component.arguments[0]
new_url = self.url_rewriter(url_component.value)
url_component.value = new_url
url_component.representation = f'"{serialize_url(new_url)}"'
else:
self.process_list(component.arguments)
elif component.type == "at-rule":
self.process_list(component.prelude)
self.process_list(component.content)
elif component.type == "declaration":
self.process_list(component.value)
elif component.type == "url":
new_url = self.url_rewriter(component.value)
component.value = new_url
component.representation = f"url({serialize_url(new_url)})"

0 comments on commit 63cfb53

Please sign in to comment.