spacetelescope / pandokia

Regression tests framework.
Other
2 stars 4 forks source link

For py3.9 use the html module's escape() instead of cgi modules version #70

Closed cdsontag closed 2 years ago

cdsontag commented 2 years ago

For: https://jira.stsci.edu/browse/JETC-1934

When trying to run pyetc with Python3.9 (TP12) we see an old usage of cgi.escape() has bitten us. We should have moved on to using html.escape() before now.

In Python 3.7 we got deprecation warnings and obviously never noticed them (in both HETC and in JETC):

Python 3.7.7 (default, Mar 26 2020, 10:32:53) 
[Clang 4.0.1 (tags/RELEASE_401/final)] :: Anaconda, Inc. on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 
>>> import cgi, html
>>> 
>>> cgi.escape('blah < aaa > bbb & and')
__main__:1: DeprecationWarning: cgi.escape is deprecated, use html.escape instead
'blah &lt; aaa &gt; bbb &amp; and'
>>> 
>>> html.escape('blah < aaa > bbb & and')
'blah &lt; aaa &gt; bbb &amp; and'
>>> 

In Python 3.9 it no longer exists in cgi:

Python 3.9.1 (default, Jan 11 2021, 15:10:49) 
[Clang 11.0.0 (clang-1100.0.33.17)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import cgi
>>> cgi.escape('blah < aaa > bbb & and')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cgi' has no attribute 'escape'

This fix changes the use of the cgi package (which in these files is ONLY used for the escape() function) to use the html package. However, I change it to import ONLY the escape() function, and I name it uniquely to "html_escape" so as to avoid future clashes with the name of the html package and the many many uses of "html" as a variable and a function parameter throughout pandokia.

cdsontag commented 2 years ago

pyetc without the fix:

image