X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=search-tags.py;h=c2884fab2942aeeeb7374451770cbd556d5c0581;hb=e34c70c04914c3884b0a474956edf36496038533;hp=35fd288773e0b5f34f8ed4ece6a333fa967c4d99;hpb=cfbfec9a97de714aa89aa3ebbbf1e09221c986e8;p=phdru.name%2Fcgi-bin%2Fblog-ru%2Fsearch-tags.git
diff --git a/search-tags.py b/search-tags.py
index 35fd288..c2884fa 100755
--- a/search-tags.py
+++ b/search-tags.py
@@ -3,14 +3,13 @@
"""Search tags CGI"""
__author__ = "Oleg Broytman "
-__copyright__ = "Copyright (C) 2014 PhiloSoft Design"
+__copyright__ = "Copyright (C) 2014-2017 PhiloSoft Design"
__license__ = "GNU GPL"
import cgi, sys
-from ply.lex import LexError
-
+from lark import ParseError
from html.response import redirect, response
-from parser.parser import parser
+from parser import parser
form = cgi.FieldStorage()
if not form.has_key('q'):
@@ -22,40 +21,39 @@ else:
q = form['q'].value
try:
tree = parser.parse(q)
- except LexError:
- tree = None
- if tree is None:
+ except ParseError:
status = "400 Bad request"
title = "Error!"
body = "Bad query syntax!"
- elif 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")
- sys.exit()
- status = "404 Tag not found"
- title = "ïÛÉÂËÁ!"
- body = "ôÅÇ %s ÎÅ ÓÕÝÅÓÔ×ÕÅÔ!" % tag
- else: # Process tree
- from tags import find_tags
- posts = find_tags(tree)
- status = None
- title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + q
- if posts:
- _posts = ["""\
-
-
-"""]
- for year, month, day, suburl, title in posts:
- _posts.append('- %s-%s-%s %s
\n' % (year, month, day, suburl, title))
- _posts .append("""\
-
-
-""")
- body = ''.join(_posts)
- else:
- body = "îÅ ÎÁÊÄÅÎÏ ÎÉ ÏÄÎÏÊ ÚÁÐÉÓÉ."
+ 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):
+ redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved")
+ sys.exit()
+ status = "404 Tag not found"
+ title = "ïÛÉÂËÁ!"
+ body = "ôÅÇ %s ÎÅ ÓÕÝÅÓÔ×ÕÅÔ!" % tag
+ else: # Process tree
+ from tags import find_tags
+ posts = find_tags(tree)
+ status = None
+ title = "úÁÐÉÓÉ, ÎÁÊÄÅÎÎÙÅ ÄÌÑ ×ÙÒÁÖÅÎÉÑ " + cgi.escape(q)
+ if posts:
+ _posts = ["""\
+
+
+ """]
+ for year, month, day, suburl, _title in posts:
+ _posts.append('- %s-%s-%s %s
\n' % (year, month, day, suburl, _title))
+ _posts .append("""\
+
+
+ """)
+ body = ''.join(_posts)
+ else:
+ body = "îÅ ÎÁÊÄÅÎÏ ÎÉ ÏÄÎÏÊ ÚÁÐÉÓÉ."
response(title, body, status)