X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=search-tags.py;h=6281a1bc6919f7814bd04b2a86cc7b955ae41dde;hb=HEAD;hp=a844960b2f4601016de12085a5b0d4cc9c82790a;hpb=bee03d50e5a6c083962d5d855cea5445bc015472;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/search-tags.py b/search-tags.py index a844960..228866b 100755 --- a/search-tags.py +++ b/search-tags.py @@ -6,22 +6,24 @@ __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 -from html.response import redirect, response +from html_output.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: @@ -32,10 +34,12 @@ else: if tree[0] == 'NAME': # Single tag - just do redirect tag = tree[1] assert isinstance(tag, str) - from tags import tag_exists - if tag_exists(tag): + from tags import real_tag + rtag = real_tag(tag) + if rtag: redirect( - "/Russian/blog/tags/%s.html" % tag, status="301 Moved") + "/Russian/blog/tags/%s.html" % rtag.replace(' ', '_'), + status="301 Moved") sys.exit() status = "404 Tag not found" title = "ïÛÉÂËÁ!" @@ -44,7 +48,7 @@ else: from tags import find_tags posts = find_tags(tree) status = None - title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + cgi.escape(q) + title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + escape(q) if posts: _posts = ["""\