Beispiel #1
0
 def search_hooks(self):
     ret = {}
     tokens = isplit(self.searchterm, True )
     for token in tokens:
         hookfound = re.match(r'^\w+:\w+$', token)
         if hookfound:
             h = hookfound.group().split(':')
             ret[ h[0] ] = h[1]
     return ret
Beispiel #2
0
 def tokenize(self, exclude_hooks = [] ):
     tokens = isplit(self.searchterm, True)
     
     next_not = False
     next_and = False
     last = None
     and_line = None
     not_line = []
     or_line = []
     for token in tokens:
         # we ignore hooks. we check if spaces are inside, since
         # hooks dont accept spaces, so we filter "hook:to something"
         for hook in exclude_hooks:
             if token.startswith( '%s:' % hook ) and ' ' not in token:
                 continue
         if token in NOT_TOKENS:
             next_not = True
             next_and = False
             continue
         if token in AND_TOKENS:
             next_and = True
             next_not = False
             continue
         if token in OR_TOKENS:
             next_and = False
             continue
         if token.startswith('-'):
             next_not = True
             next_and = False
             token = token[1:]
             if not token:
                 continue
         # check if this is AND:
         if next_and:
             if and_line:
                 and_line += [ token ]
             else:
                 if last:
                     and_line = [ last, token ]
                 else:
                     and_line = [ token ]
             next_and = False
             last = and_line
             continue
         if next_not:
             not_line += [ token ]
             next_not = False
             continue
         if last:
             if isinstance(last, list):
                 or_line += [ last, ]
             else:
                 or_line += [[ last, ]]
         last = token
     if last:
         if isinstance(last, list):
             or_line += [ last, ]
         else:
             or_line += [[ last, ]]
     print (or_line, not_line)
     return (or_line, not_line)