Skip to content

Commit

Permalink
Python 3.10 (#959)
Browse files Browse the repository at this point in the history
* Dockerfile & requirements

* Fix tests

* Treat all AssertionErrors as HTMLParseErrors
  • Loading branch information
squeaky-pl authored Oct 29, 2024
1 parent 4efdbc4 commit 1a6d56d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
14 changes: 7 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# --- Stage 0 --- #
# This first stage is responsible for installing any dependencies the app needs
# to run, and updating any base dependencies.
FROM ubuntu:20.04 AS stage_0
FROM ubuntu:22.04 AS stage_0

RUN groupadd -g 5000 sync-engine \
&& useradd -d /home/sync-engine -m -u 5000 -g 5000 sync-engine
Expand All @@ -24,7 +24,7 @@ RUN echo $BUILD_WEEK && apt-get update \
gpg \
gpg-agent \
dirmngr \
python3.9 \
python3.10 \
gettext-base \
libmysqlclient21 \
mysql-client \
Expand Down Expand Up @@ -54,16 +54,16 @@ RUN apt-get update \
gcc \
git \
pkg-config \
python3.9-dev \
python3.10-dev \
python3-pip \
libmysqlclient-dev \
&& rm -rf /var/lib/apt/lists/*

COPY /requirements/ /requirements/
RUN python3.9 -m pip install pip==24.0 virtualenv==20.25.1 && \
python3.9 -m virtualenv /opt/venv && \
/opt/venv/bin/python3.9 -m pip install --no-cache --no-deps -r /requirements/prod.txt -r /requirements/test.txt && \
/opt/venv/bin/python3.9 -m pip check
RUN python3.10 -m pip install pip==24.3.1 virtualenv==20.27.0 && \
python3.10 -m virtualenv /opt/venv && \
/opt/venv/bin/python3.10 -m pip install --no-cache --no-deps -r /requirements/prod.txt -r /requirements/test.txt && \
/opt/venv/bin/python3.10 -m pip check


# --- Stage 2 --- #
Expand Down
21 changes: 14 additions & 7 deletions inbox/util/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from html import escape as html_escape


class HTMLParseError(Exception):
class HTMLParseError(ValueError):
pass


Expand Down Expand Up @@ -42,11 +42,6 @@ def handle_data(self, d):
if not self.strip_tag_contents_mode:
self.fed.append(d)

if (3,) <= sys.version_info < (3, 10):

def error(self, message):
raise HTMLParseError(message)

def handle_entityref(self, d):
try:
val = chr(name2codepoint[d])
Expand All @@ -68,7 +63,19 @@ def strip_tags(html: str) -> str:
You are responsible for handling it in the calling function.
"""
s = HTMLTagStripper()
s.feed(html)

# `HTMLParser.feed()` raises `AssertionError` if fed invalid HTML.
# See the source at https://github.com/python/cpython/blob/main/Lib/html/parser.py
# and https://github.com/python/cpython/blob/main/Lib/_markupbase.py#L30.
# We want to catch this exception and raise a more informative exception to
# tell it apart from general `AssertionError`s that normally mean a programmer error.
# Those are later caught in `Message.calculate_html_snippet` so it can recover from
# invalid HTML.
try:
s.feed(html)
except AssertionError as e:
raise HTMLParseError(*e.args) from e

return s.get_data()


Expand Down

0 comments on commit 1a6d56d

Please sign in to comment.