X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=search-tags.py;h=6281a1bc6919f7814bd04b2a86cc7b955ae41dde;hb=f44018177d69b84a4e5aeb1ecf037f740dd1aaab;hp=33d141f33107c9f7fcdcc1728f4f160ba74d106d;hpb=8aa42e73690f32c2c6bfdb11ff1f91cd3c90b12b;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git diff --git a/search-tags.py b/search-tags.py index 33d141f..6281a1b 100755 --- a/search-tags.py +++ b/search-tags.py @@ -1,18 +1,22 @@ -#! /usr/bin/env python +#! /usr/bin/env python3 # coding: koi8-r """Search tags CGI""" __author__ = "Oleg Broytman " -__copyright__ = "Copyright (C) 2014-2016 PhiloSoft Design" +__copyright__ = "Copyright (C) 2014-2024 PhiloSoft Design" __license__ = "GNU GPL" -import cgi, sys -from grako.exceptions import FailedParse +from html import escape +import sys -from html.response import redirect, response +from lark import ParseError +import mycgi -form = cgi.FieldStorage() -if not form.has_key('q'): +from html_output.response import redirect, response +from parser import parser + +form = mycgi.Form() +if 'q' not in form: status = "400 Bad request" title = "Error!" body = "Required parameter is missing!" @@ -20,37 +24,38 @@ if not form.has_key('q'): else: q = form['q'].value try: - from parser.parser import TagsParser - from parser.build_ast import TagsSemantics - parser = TagsParser(parseinfo=False) - tree = parser.parse(q, semantics=TagsSemantics()) - except FailedParse: + tree = parser.parse(q) + except ParseError: status = "400 Bad request" title = "Error!" body = "Bad query syntax!" else: - if tree[0] == 'NAME': # Single tag - just do redirect + 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): - redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved") + redirect( + "/Russian/blog/tags/%s.html" % tag, status="301 Moved") sys.exit() status = "404 Tag not found" title = "ïÛÉÂËÁ!" body = "ôÅÇ %s ÎÅ ÓÕÝÅÓÔ×ÕÅÔ!" % tag - else: # Process tree + else: # Process tree from tags import find_tags posts = find_tags(tree) status = None - title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + cgi.escape(q) + title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + escape(q) if posts: _posts = ["""\