'Construct a sub-query from URL selectors, operator and value
@param selectors: the selector(s)
@param op: the operator
@param invert: invert the query
@param value: the value'

@classmethod
def _subquery(cls, selectors, op, invert, value):

    v = cls.parse_value(value)
    like = (lambda s: s3_unicode(s).lower().replace('%', '\\%').replace('_', '\\_').replace('?', '_').replace('*', '%').encode('utf-8'))
    q = None
    escaped = False
    for fs in selectors:
        if (op == S3ResourceQuery.LIKE):
            f = S3FieldSelector(fs).lower()
            if (not escaped):
                if isinstance(v, basestring):
                    v = like(v)
                elif isinstance(v, list):
                    v = [like(s) for s in v if (s is not None)]
                escaped = True
        else:
            f = S3FieldSelector(fs)
        rquery = None
        try:
            rquery = S3ResourceQuery(op, f, v)
        except SyntaxError:
            current.log.error(('Invalid    URL    query    operator:    %s    (sub-query    ignored)' % op))
            q = None
            break
        if invert:
            rquery = (~ rquery)
        if (q is None):
            q = rquery
        elif invert:
            q &= rquery
        else:
            q |= rquery
    return q
