~nimit-svnit/gtg/bug-1102453

« back to all changes in this revision

Viewing changes to GTG/core/search.py

  • Committer: Izidor Matušov
  • Date: 2013-02-25 07:35:07 UTC
  • Revision ID: izidor.matusov@gmail.com-20130225073507-vgts69uthx7z2run
PEP8ification by Nimit

Show diffs side-by-side

added added

removed removed

Lines of Context:
84
84
# Generate keywords and their possible translations
85
85
# They must be listed because of gettext
86
86
KEYWORDS = {
87
 
  "not": _("not"),
88
 
  "or": _("or"),
89
 
  "after": _("after"),
90
 
  "before": _("before"),
91
 
  "today": _("today"),
92
 
  "tomorrow": _("tomorrow"),
93
 
  "nodate": _("nodate"),
94
 
  "now": _("now"),
95
 
  "soon": _("soon"),
96
 
  "someday": _("someday"),
97
 
  "notag": _("notag"),
 
87
    "not": _("not"),
 
88
    "or": _("or"),
 
89
    "after": _("after"),
 
90
    "before": _("before"),
 
91
    "today": _("today"),
 
92
    "tomorrow": _("tomorrow"),
 
93
    "nodate": _("nodate"),
 
94
    "now": _("now"),
 
95
    "soon": _("soon"),
 
96
    "someday": _("someday"),
 
97
    "notag": _("notag"),
98
98
}
99
99
 
100
100
# transform keywords and their translations into a list of possible commands
149
149
            yield token_type, token_value
150
150
    if pos != len(query):
151
151
        raise InvalidQuery('tokenizer stopped at pos %r of %r left of "%s"' % (
152
 
            pos, len(query), query[pos:pos+10]))
 
152
            pos, len(query), query[pos:pos + 10]))
153
153
 
154
154
 
155
155
def parse_search_query(query):
174
174
        if require_date:
175
175
            if token not in ['date', 'word', 'literal']:
176
176
                raise InvalidQuery("Unexpected token '%s' after '%s'" % (
177
 
                            token, require_date))
 
177
                    token, require_date))
178
178
 
179
179
            value = value.strip('"')
180
180
            try:
200
200
                        raise InvalidQuery("!or cann't follow !not")
201
201
 
202
202
                    if commands == []:
203
 
                        raise InvalidQuery( \
 
203
                        raise InvalidQuery(
204
204
                            "Or is not allowed at the beginning of query")
205
205
 
206
206
                    if commands[-1][0] != "or":
293
293
 
294
294
        return True
295
295
 
296
 
 
297
296
    return check_commands(parameters['q'])