From: Oleg Broytman Date: Sat, 15 Jun 2024 23:10:58 +0000 (+0300) Subject: Feat(Python3): Use `urllib.parse.parse_qs` X-Git-Tag: v0.8~11 X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=00ead935d40917ecfd77bc4b11b1b6e1033ec853;hp=bee03d50e5a6c083962d5d855cea5445bc015472;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git Feat(Python3): Use `urllib.parse.parse_qs` Prepare for Python 3.13 dropping `cgi`. --- diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..22fd5ba --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Cheetah3 +lark diff --git a/search-tags.py b/search-tags.py index a844960..a358a02 100755 --- a/search-tags.py +++ b/search-tags.py @@ -6,7 +6,9 @@ __author__ = "Oleg Broytman " __copyright__ = "Copyright (C) 2014-2024 PhiloSoft Design" __license__ = "GNU GPL" -import cgi +from html import escape +from urllib.parse import parse_qs +import os import sys from lark import ParseError @@ -14,14 +16,14 @@ from lark import ParseError from html.response import redirect, response from parser import parser -form = cgi.FieldStorage() -if 'q' not in form: +qs_dict = parse_qs(os.environ['QUERY_STRING'], encoding='koi8-r') +if 'q' not in qs_dict or len(qs_dict['q']) > 1: status = "400 Bad request" title = "Error!" body = "Required parameter is missing!" else: - q = form['q'].value + q = qs_dict['q'][0] try: tree = parser.parse(q) except ParseError: @@ -44,7 +46,7 @@ else: from tags import find_tags posts = find_tags(tree) status = None - title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + cgi.escape(q) + title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + escape(q) if posts: _posts = ["""\