Skip to content

Commit

Permalink
Feat(Template): Protect import cgi in preparation to Python 3.13
Browse files Browse the repository at this point in the history
  • Loading branch information
phdru committed Oct 18, 2023
1 parent c7ade90 commit 1b8515d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Cheetah/Template.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@
from io import StringIO
import traceback
import pprint
import cgi # Used by .webInput() if the template is a CGI script.
try:
import cgi # Used by .webInput() if the template is a CGI script.
except ImportError: # Python 3.13+
cgi = None
import types

from . import ErrorCatchers # for placeholder tags
Expand Down Expand Up @@ -1917,7 +1920,7 @@ def webInput(self, names, namesMulti=(), default='', src='f',
"""
src = src.lower()
isCgi = not self._CHEETAH__isControlledByWebKit
if isCgi and src in ('f', 'v'):
if isCgi and (cgi is not None) and src in ('f', 'v'):
global _formUsedByWebInput
if _formUsedByWebInput is None:
_formUsedByWebInput = cgi.FieldStorage()
Expand Down
4 changes: 4 additions & 0 deletions docs/news.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ News
Development (master)
--------------------

Minor features:

- Protect ``import cgi`` in preparation to Python 3.13.

Tests:

- Run tests with Python 3.12.
Expand Down

0 comments on commit 1b8515d

Please sign in to comment.