diff --git a/Cheetah/Template.py b/Cheetah/Template.py index 4aac607e..393f290f 100644 --- a/Cheetah/Template.py +++ b/Cheetah/Template.py @@ -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 @@ -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() diff --git a/docs/news.rst b/docs/news.rst index dfb69bb5..fc1809d5 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -4,6 +4,10 @@ News Development (master) -------------------- +Minor features: + + - Protect ``import cgi`` in preparation to Python 3.13. + 3.3.2 (2023-08-08) ------------------