'Constructor
@param resource: the S3Resource
@param id: the record ID (or list of record IDs)
@param uid: the record UID (or list of record UIDs)
@param filter: a filter query (S3ResourceQuery or Query)
@param vars: the dict of GET vars (URL filters)
@param extra_filters: extra filters (to be applied on
pre-filtered subsets), as list of
tuples (method, expression)
@param filter_component: the alias of the component the URL
filters apply for (filters for this
component must be handled separately)'

def __init__(self, resource, id=None, uid=None, filter=None, vars=None, extra_filters=None, filter_component=None):

    self.resource = resource
    self.queries = []
    self.filters = []
    self.cqueries = {}
    self.cfilters = {}
    self._extra_filter_methods = None
    if extra_filters:
        self.set_extra_filters(extra_filters)
    else:
        self.efilters = []
    self.query = None
    self.rfltr = None
    self.vfltr = None
    self.transformed = None
    self.multiple = True
    self.distinct = False
    self.ijoins = {}
    self.ljoins = {}
    table = resource.table
    if (resource.accessible_query is not None):
        method = []
        if resource._approved:
            method.append('read')
        if resource._unapproved:
            method.append('review')
        mquery = resource.accessible_query(method, table)
    else:
        mquery = (table._id > 0)
    DELETED = current.xml.DELETED
    if ((DELETED in table.fields) and (not resource.include_deleted)):
        remaining = (table[DELETED] != True)
        mquery = (remaining & mquery)
    if (id is not None):
        if (not isinstance(id, (list, tuple))):
            self.multiple = False
            mquery = (mquery & (table._id == id))
        else:
            mquery = (mquery & table._id.belongs(id))
    UID = current.xml.UID
    if ((uid is not None) and (UID in table)):
        if (not isinstance(uid, (list, tuple))):
            self.multiple = False
            mquery = (mquery & (table[UID] == uid))
        else:
            mquery = (mquery & table[UID].belongs(uid))
    parent = resource.parent
    if (not parent):
        self.mquery = mquery
        if vars:
            resource.vars = Storage(vars)
            if (not vars.get('track')):
                (bbox, joins) = self.parse_bbox_query(resource, vars)
                if (bbox is not None):
                    self.queries.append(bbox)
                    if joins:
                        self.ljoins.update(joins)
            add_filter = self.add_filter
            queries = S3URLQuery.parse(resource, vars)
            for alias in queries:
                if (filter_component == alias):
                    for q in queries[alias]:
                        add_filter(q, component=alias, master=False)
                else:
                    for q in queries[alias]:
                        add_filter(q)
            self.cfilters = queries
    else:
        pf = parent.rfilter
        if (not pf):
            pf = parent.build_query()
        self.mquery = (mquery & pf.get_query())
        self.ijoins[parent._alias] = resource._join(reverse=True)
        add_filter = self.add_filter
        aliases = [resource.alias]
        if (resource.link is not None):
            aliases.append(resource.link.alias)
        elif (resource.linked is not None):
            aliases.append(resource.linked.alias)
        for alias in aliases:
            for filter_set in (pf.cqueries, pf.cfilters):
                if (alias in filter_set):
                    [add_filter(q) for q in filter_set[alias]]
    if (filter is not None):
        self.add_filter(filter)
