mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 20:44:04 +00:00
python: Skip unnecessary decode before BeautifulSoup parsing.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
86e8d81c7f
commit
7c4f68d9cf
@@ -1,4 +1,4 @@
|
||||
from typing import Mapping
|
||||
from typing import Mapping, Union
|
||||
|
||||
from bs4 import BeautifulSoup
|
||||
from django.http import HttpRequest
|
||||
@@ -7,7 +7,7 @@ from django.utils.html import escape
|
||||
from zerver.lib.cache import cache_with_key, open_graph_description_cache_key
|
||||
|
||||
|
||||
def html_to_text(content: str, tags: Mapping[str, str] = {'p': ' | '}) -> str:
|
||||
def html_to_text(content: Union[str, bytes], tags: Mapping[str, str] = {'p': ' | '}) -> str:
|
||||
bs = BeautifulSoup(content, features='lxml')
|
||||
# Skip any admonition (warning) blocks, since they're
|
||||
# usually something about users needing to be an
|
||||
@@ -35,5 +35,4 @@ def html_to_text(content: str, tags: Mapping[str, str] = {'p': ' | '}) -> str:
|
||||
|
||||
@cache_with_key(open_graph_description_cache_key, timeout=3600*24)
|
||||
def get_content_description(content: bytes, request: HttpRequest) -> str:
|
||||
str_content = content.decode("utf-8")
|
||||
return html_to_text(str_content)
|
||||
return html_to_text(content)
|
||||
|
||||
Reference in New Issue
Block a user