'Represent this query as a human-readable string.
@param resource: the resource to resolve the query against'

def represent(self, resource):

    op = self.op
    l = self.left
    r = self.right
    if (op == self.AND):
        l = (l.represent(resource) if isinstance(l, S3ResourceQuery) else str(l))
        r = (r.represent(resource) if isinstance(r, S3ResourceQuery) else str(r))
        return ('(%s    and    %s)' % (l, r))
    elif (op == self.OR):
        l = (l.represent(resource) if isinstance(l, S3ResourceQuery) else str(l))
        r = (r.represent(resource) if isinstance(r, S3ResourceQuery) else str(r))
        return ('(%s    or    %s)' % (l, r))
    elif (op == self.NOT):
        l = (l.represent(resource) if isinstance(l, S3ResourceQuery) else str(l))
        return ('(not    %s)' % l)
    else:
        if isinstance(l, S3FieldSelector):
            l = l.represent(resource)
        elif isinstance(l, basestring):
            l = ('"%s"' % l)
        if isinstance(r, S3FieldSelector):
            r = r.represent(resource)
        elif isinstance(r, basestring):
            r = ('"%s"' % r)
        if (op == self.CONTAINS):
            return ('(%s    in    %s)' % (r, l))
        elif (op == self.BELONGS):
            return ('(%s    in    %s)' % (l, r))
        elif (op == self.ANYOF):
            return ('(%s    contains    any    of    %s)' % (l, r))
        elif (op == self.TYPEOF):
            return ('(%s    is    a    type    of    %s)' % (l, r))
        elif (op == self.LIKE):
            return ('(%s    like    %s)' % (l, r))
        elif (op == self.LT):
            return ('(%s    <    %s)' % (l, r))
        elif (op == self.LE):
            return ('(%s    <=    %s)' % (l, r))
        elif (op == self.EQ):
            return ('(%s    ==    %s)' % (l, r))
        elif (op == self.NE):
            return ('(%s    !=    %s)' % (l, r))
        elif (op == self.GE):
            return ('(%s    >=    %s)' % (l, r))
        elif (op == self.GT):
            return ('(%s    >    %s)' % (l, r))
        else:
            return ('(%s    ?%s?    %s)' % (l, op, r))
