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 Sep 15, 2023
1 parent 263caa4 commit ee8b07d
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 @@ -1916,7 +1919,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.

3.3.2 (2023-08-08)
------------------

Expand Down

0 comments on commit ee8b07d

Please sign in to comment.