'Return True or False depending on whether the field value (block contents)
matches the qualifiers as per get_items.
NOTE: Method only finds directly set value matches - not inherited nor default value matches.
For substring matching:
pass a regex object.
For arbitrary function comparison such as date time comparison:
pass the function as in start=lambda x: x < datetime.datetime(2014, 1, 1, 0, tzinfo=pytz.UTC)
Args:
block (dict, XBlock, or BlockData): either the BlockData (transformed from the db) -or-
a dict (from BlockData.fields or get_explicitly_set_fields_by_scope) -or-
the xblock.fields() value -or-
the XBlock from which to get the \'fields\' value.
qualifiers (dict): {field: value} search pairs.'

@contract(block='XBlock    |    BlockData    |    dict', qualifiers=dict)
def _block_matches(self, block, qualifiers):

    if isinstance(block, XBlock):
        (xblock, fields) = (block, block.fields)
    elif isinstance(block, BlockData):
        (xblock, fields) = (None, block.__dict__)
    else:
        (xblock, fields) = (None, block)
    def _is_set_on(key):
        '\n                                                Is    this    key    set    in    fields?    (return    tuple    of    boolean    and    value).    A    helper    which    can\n                                                handle    fields    either    being    the    json    doc    or    xblock    fields.    Is    inner    function    to    restrict\n                                                use    and    to    access    local    vars.\n                                                '
        if (key not in fields):
            return (False, None)
        field = fields[key]
        if (xblock is not None):
            return (field.is_set_on(block), getattr(xblock, key))
        else:
            return (True, field)
    for (key, criteria) in qualifiers.iteritems():
        (is_set, value) = _is_set_on(key)
        if (isinstance(criteria, dict) and ('$exists' in criteria) and (criteria['$exists'] == is_set)):
            continue
        if (not is_set):
            return False
        if (not self._value_matches(value, criteria)):
            return False
    return True
