forked from webpy/webpy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: enable Python 3.12 to parse templates (webpy#785)
* Fix: enable Python 3.12 to parse templates Closes webpy#784. This PR fixes the inability of `web.py` to run on Python 3.12, and it does so by matching any unmatched `"` in a string. In Python 3.12, changes to `tokenize.generate_tokens()` requires all quotes to be matched, and the `web.py` template parser hands unterminated strings to `tokenize.generate_tokens()` quite frequently. This PR makes a tacit assumption that we should avoid rewriting the template parser if possible while also allowing `web.py` to run on Python 3.12. To that end, it handles every `TokenError` that is because of unmatched string literals by adding a `"` to the line. Although this appears to work, I am aware that appending a `"` to each line that has an unmatched `"` is less than ideal. However, it seemed a very easy way to avoid rewriting the template parser. I am absolutely open to other approaches. *IF* this approach looks as if it has legs, I can can look more into where that "extra" `"` goes, why it seems not to matter, and write some unit tests. With regard to testing, I tested this with as many pages on Open Library that I could (via the local development environment), and it seems to work. * noqa: complexity and excess statements for read_expr() * Add suggestions from @tfmorris. * Switch to more-itertools.peekable and set linter limits back down again * Fix off-by-1 error and add test coverage * Linting fixes * Add `more_itertools` as a dependency `more_itertools.peekable()` is used now. `cheroot` already requires `more_itertools`, so this depedency is already installed anyway, but adding it as a dependency for `webpy` itself will ensure that if `cheroot` drops the `more_itertools`, dependency, `webpy` will still require it. --------- Co-authored-by: Tom Morris <tfmorris@gmail.com>
- Loading branch information
1 parent
5709b1f
commit d364932
Showing
9 changed files
with
121 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
cheroot>=6.0.0 | ||
more_itertools>=2.6 | ||
multipart>=0.2.4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
Database API | ||
(part of web.py) | ||
""" | ||
|
||
import ast | ||
import datetime | ||
import os | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ | |
(from web.py) | ||
""" | ||
|
||
|
||
import datetime | ||
import re | ||
import socket | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
"""test utilities | ||
(part of web.py) | ||
""" | ||
|
||
import doctest | ||
import sys | ||
import unittest | ||
|