5 __author__ = "Oleg Broytman <phd@phdru.name>"
6 __copyright__ = "Copyright (C) 2014-2016 PhiloSoft Design"
7 __license__ = "GNU GPL"
10 from grako.exceptions import FailedParse
12 from html.response import redirect, response
14 form = cgi.FieldStorage()
15 if not form.has_key('q'):
16 status = "400 Bad request"
18 body = "Required parameter is missing!"
23 from parser.parser import TagsParser
24 from parser.build_ast import TagsSemantics
25 parser = TagsParser(parseinfo=False)
26 tree = parser.parse(q, semantics=TagsSemantics())
28 status = "400 Bad request"
30 body = "Bad query syntax!"
32 if tree[0] == 'NAME': # Single tag - just do redirect
34 assert isinstance(tag, str)
35 from tags import tag_exists
37 redirect("/Russian/blog/tags/%s.html" % tag, status="301 Moved")
39 status = "404 Tag not found"
41 body = "Тег %s не существует!" % tag
43 from tags import find_tags
44 posts = find_tags(tree)
46 title = "Записи, найденные для выражения " + cgi.escape(q)
52 for year, month, day, suburl, _title in posts:
53 _posts.append('<li>%s-%s-%s <a href="../../../../Russian/blog/%s">%s</a></li>\n' % (year, month, day, suburl, _title))
58 body = ''.join(_posts)
60 body = "Не найдено ни одной записи."
62 response(title, body, status)