aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-01-05 21:11:07 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2020-01-05 21:18:15 -0500
commit2dae7d2c3da73653e6de329dc15c55056a0b9ab6 (patch)
treebd333dce394b0b14e74326571e66ce0537eca7a8
parentb06ce6ea566247b306f0531c5716e57b9c7b4876 (diff)
downloadexternal_python_mako-2dae7d2c3da73653e6de329dc15c55056a0b9ab6.tar.gz
external_python_mako-2dae7d2c3da73653e6de329dc15c55056a0b9ab6.tar.bz2
external_python_mako-2dae7d2c3da73653e6de329dc15c55056a0b9ab6.zip
Replace usage of parser.suite with ast.parse
Replaced usage of the long-superseded "parser.suite" module in the mako.util package for parsing the python magic encoding comment with the "ast.parse" function introduced many years ago in Python 2.5, as "parser.suite" is emitting deprecation warnings in Python 3.9. Additionally repair two error-detection unit tests that were using a "print" statement despite the tests running under Python 3; while the tests were passing they were no longer testing the right thing. Fixes: #310 Change-Id: Id436e2c6620438ef16b3f188b989233c82972b29
-rw-r--r--doc/build/unreleased/310.rst10
-rw-r--r--mako/util.py6
-rw-r--r--test/templates/unicode_runtime_error.html2
-rw-r--r--test/templates/unicode_syntax_error.html2
4 files changed, 15 insertions, 5 deletions
diff --git a/doc/build/unreleased/310.rst b/doc/build/unreleased/310.rst
new file mode 100644
index 0000000..e824924
--- /dev/null
+++ b/doc/build/unreleased/310.rst
@@ -0,0 +1,10 @@
+.. change::
+ :tags: bug, py3k
+ :tickets: 310
+
+ Replaced usage of the long-superseded "parser.suite" module in the
+ mako.util package for parsing the python magic encoding comment with the
+ "ast.parse" function introduced many years ago in Python 2.5, as
+ "parser.suite" is emitting deprecation warnings in Python 3.9.
+
+
diff --git a/mako/util.py b/mako/util.py
index 498edbc..16e3c72 100644
--- a/mako/util.py
+++ b/mako/util.py
@@ -3,7 +3,9 @@
#
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
+from __future__ import absolute_import
+from ast import parse
import codecs
import collections
import operator
@@ -257,9 +259,7 @@ def parse_encoding(fp):
m = _PYTHON_MAGIC_COMMENT_re.match(line1.decode("ascii", "ignore"))
if not m:
try:
- import parser
-
- parser.suite(line1.decode("ascii", "ignore"))
+ parse(line1.decode("ascii", "ignore"))
except (ImportError, SyntaxError):
# Either it's a real syntax error, in which case the source
# is not valid python source, or line2 is a continuation of
diff --git a/test/templates/unicode_runtime_error.html b/test/templates/unicode_runtime_error.html
index 862dce5..dda7f62 100644
--- a/test/templates/unicode_runtime_error.html
+++ b/test/templates/unicode_runtime_error.html
@@ -1,2 +1,2 @@
## -*- coding: utf-8 -*-
-<% print 'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »' + int(5/0) %> \ No newline at end of file
+<% x = 'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! »' + int(5/0) %> \ No newline at end of file
diff --git a/test/templates/unicode_syntax_error.html b/test/templates/unicode_syntax_error.html
index 982af33..aa53025 100644
--- a/test/templates/unicode_syntax_error.html
+++ b/test/templates/unicode_syntax_error.html
@@ -1,2 +1,2 @@
## -*- coding: utf-8 -*-
-<% print 'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! » %> \ No newline at end of file
+<% x = 'Alors vous imaginez ma surprise, au lever du jour, quand une drôle de petite voix m’a réveillé. Elle disait: « S’il vous plaît… dessine-moi un mouton! » %> \ No newline at end of file