Revision 2e5c33db lib/query.py
b/lib/query.py | ||
---|---|---|
409 | 409 |
self._hints = None |
410 | 410 |
self._op_handler = None |
411 | 411 |
|
412 |
def __call__(self, hints, filter_):
|
|
412 |
def __call__(self, hints, qfilter):
|
|
413 | 413 |
"""Converts a query filter into a callable function. |
414 | 414 |
|
415 | 415 |
@type hints: L{_FilterHints} or None |
416 | 416 |
@param hints: Callbacks doing analysis on filter |
417 |
@type filter_: list
|
|
418 |
@param filter_: Filter structure
|
|
417 |
@type qfilter: list
|
|
418 |
@param qfilter: Filter structure
|
|
419 | 419 |
@rtype: callable |
420 | 420 |
@return: Function receiving context and item as parameters, returning |
421 | 421 |
boolean as to whether item matches filter |
... | ... | |
431 | 431 |
} |
432 | 432 |
|
433 | 433 |
try: |
434 |
filter_fn = self._Compile(filter_, 0)
|
|
434 |
filter_fn = self._Compile(qfilter, 0)
|
|
435 | 435 |
finally: |
436 | 436 |
self._op_handler = None |
437 | 437 |
|
438 | 438 |
return filter_fn |
439 | 439 |
|
440 |
def _Compile(self, filter_, level):
|
|
440 |
def _Compile(self, qfilter, level):
|
|
441 | 441 |
"""Inner function for converting filters. |
442 | 442 |
|
443 | 443 |
Calls the correct handler functions for the top-level operator. This |
444 | 444 |
function is called recursively (e.g. for logic operators). |
445 | 445 |
|
446 | 446 |
""" |
447 |
if not (isinstance(filter_, (list, tuple)) and filter_):
|
|
447 |
if not (isinstance(qfilter, (list, tuple)) and qfilter):
|
|
448 | 448 |
raise errors.ParameterError("Invalid filter on level %s" % level) |
449 | 449 |
|
450 | 450 |
# Limit recursion |
... | ... | |
453 | 453 |
" nested too deep)" % self._LEVELS_MAX) |
454 | 454 |
|
455 | 455 |
# Create copy to be modified |
456 |
operands = filter_[:]
|
|
456 |
operands = qfilter[:]
|
|
457 | 457 |
op = operands.pop(0) |
458 | 458 |
|
459 | 459 |
try: |
... | ... | |
581 | 581 |
" (op '%s', flags %s)" % (op, field_flags)) |
582 | 582 |
|
583 | 583 |
|
584 |
def _CompileFilter(fields, hints, filter_):
|
|
584 |
def _CompileFilter(fields, hints, qfilter):
|
|
585 | 585 |
"""Converts a query filter into a callable function. |
586 | 586 |
|
587 | 587 |
See L{_FilterCompilerHelper} for details. |
... | ... | |
589 | 589 |
@rtype: callable |
590 | 590 |
|
591 | 591 |
""" |
592 |
return _FilterCompilerHelper(fields)(hints, filter_)
|
|
592 |
return _FilterCompilerHelper(fields)(hints, qfilter)
|
|
593 | 593 |
|
594 | 594 |
|
595 | 595 |
class Query: |
596 |
def __init__(self, fieldlist, selected, filter_=None, namefield=None):
|
|
596 |
def __init__(self, fieldlist, selected, qfilter=None, namefield=None):
|
|
597 | 597 |
"""Initializes this class. |
598 | 598 |
|
599 | 599 |
The field definition is a dictionary with the field's name as a key and a |
... | ... | |
620 | 620 |
self._requested_names = None |
621 | 621 |
self._filter_datakinds = frozenset() |
622 | 622 |
|
623 |
if filter_ is not None:
|
|
623 |
if qfilter is not None:
|
|
624 | 624 |
# Collect requested names if wanted |
625 | 625 |
if namefield: |
626 | 626 |
hints = _FilterHints(namefield) |
... | ... | |
628 | 628 |
hints = None |
629 | 629 |
|
630 | 630 |
# Build filter function |
631 |
self._filter_fn = _CompileFilter(fieldlist, hints, filter_)
|
|
631 |
self._filter_fn = _CompileFilter(fieldlist, hints, qfilter)
|
|
632 | 632 |
if hints: |
633 | 633 |
self._requested_names = hints.RequestedNames() |
634 | 634 |
self._filter_datakinds = hints.ReferencedData() |
Also available in: Unified diff