'Constructor
@param prefix: the table name prefix
@param name: the table name
@param c: the controller prefix
@param f: the controller function
@param args: list of request arguments
@param vars: dict of request variables
@param extension: the format extension (representation)
@param get_vars: the URL query variables (overrides vars)
@param post_vars: the POST variables (overrides vars)
@param http: the HTTP method (GET, PUT, POST, or DELETE)
@note: all parameters fall back to the attributes of the
current web2py request object'

def __init__(self, prefix=None, name=None, r=None, c=None, f=None, args=None, vars=None, extension=None, get_vars=None, post_vars=None, http=None):

    auth = current.auth
    self.XSLT_PATH = 'static/formats'
    self.XSLT_EXTENSION = 'xsl'
    self.files = Storage()
    self.controller = (c or self.controller)
    self.function = (f or self.function)
    if ('.' in self.function):
        (self.function, ext) = self.function.split('.', 1)
        if (extension is None):
            extension = ext
    if (c or f):
        if (not auth.permission.has_permission('read', c=self.controller, f=self.function)):
            auth.permission.fail()
    if (args is not None):
        if isinstance(args, (list, tuple)):
            self.args = args
        else:
            self.args = [args]
    if (get_vars is not None):
        self.get_vars = get_vars
        self.vars = get_vars.copy()
        if (post_vars is not None):
            self.vars.update(post_vars)
        else:
            self.vars.update(self.post_vars)
    if (post_vars is not None):
        self.post_vars = post_vars
        if (get_vars is None):
            self.vars = post_vars.copy()
            self.vars.update(self.get_vars)
    if ((get_vars is None) and (post_vars is None) and (vars is not None)):
        self.vars = vars
        self.get_vars = vars
        self.post_vars = Storage()
    self.extension = (extension or current.request.extension)
    self.http = (http or current.request.env.request_method)
    if (r is not None):
        if (not prefix):
            prefix = r.prefix
        if (not name):
            name = r.name
    self.prefix = (prefix or self.controller)
    self.name = (name or self.function)
    self.__parse()
    self.custom_action = None
    get_vars = Storage(self.get_vars)
    self.interactive = (self.representation in self.INTERACTIVE_FORMATS)
    include_deleted = False
    if ((self.representation == 'xml') and ('include_deleted' in get_vars)):
        include_deleted = True
    if ('components' in get_vars):
        cnames = get_vars['components']
        if isinstance(cnames, list):
            cnames = ','.join(cnames)
        cnames = cnames.split(',')
        if ((len(cnames) == 1) and (cnames[0].lower() == 'none')):
            cnames = []
    else:
        cnames = None
    component_name = self.component_name
    component_id = self.component_id
    if (component_name and component_id):
        varname = ('%s.id' % component_name)
        if (varname in get_vars):
            var = get_vars[varname]
            if (not isinstance(var, (list, tuple))):
                var = [var]
            var.append(component_id)
            get_vars[varname] = var
        else:
            get_vars[varname] = component_id
    _filter = current.response.s3.filter
    components = component_name
    if (components is None):
        components = cnames
    tablename = ('%s_%s' % (self.prefix, self.name))
    if (not current.deployment_settings.get_auth_record_approval()):
        (approved, unapproved) = (True, False)
    elif (self.method == 'review'):
        (approved, unapproved) = (False, True)
    elif auth.s3_has_permission('review', tablename, self.id):
        (approved, unapproved) = (True, True)
    else:
        (approved, unapproved) = (True, False)
    self.resource = S3Resource(tablename, id=self.id, filter=_filter, vars=get_vars, components=components, approved=approved, unapproved=unapproved, include_deleted=include_deleted, context=True, filter_component=component_name)
    self.tablename = self.resource.tablename
    table = self.table = self.resource.table
    self.record = None
    uid = self.vars.get(('%s.uid' % self.name))
    if (self.id or (uid and (not isinstance(uid, (list, tuple))))):
        self.resource.load()
        if (len(self.resource) == 1):
            self.record = self.resource.records().first()
            _id = table._id.name
            self.id = self.record[_id]
            s3_store_last_record_id(self.tablename, self.id)
        else:
            raise KeyError(current.ERROR.BAD_RECORD)
    self.component = None
    if self.component_name:
        c = self.resource.components.get(self.component_name)
        if c:
            self.component = c
        else:
            error = ('%s    not    a    component    of    %s' % (self.component_name, self.resource.tablename))
            raise AttributeError(error)
    self.link = None
    self.link_id = None
    if (self.component is not None):
        self.link = self.component.link
    if (self.link and self.id and self.component_id):
        self.link_id = self.link.link_id(self.id, self.component_id)
        if (self.link_id is None):
            raise KeyError(current.ERROR.BAD_RECORD)
    self._handlers = {}
    set_handler = self.set_handler
    set_handler('export_tree', self.get_tree, http=('GET',), transform=True)
    set_handler('import_tree', self.put_tree, http=('GET', 'PUT', 'POST'), transform=True)
    set_handler('fields', self.get_fields, http=('GET',), transform=True)
    set_handler('options', self.get_options, http=('GET',), representation=('__transform__', 'json'))
    sync = current.sync
    set_handler('sync', sync, http=('GET', 'PUT', 'POST'), transform=True)
    set_handler('sync_log', sync.log, http=('GET',), transform=True)
    set_handler('sync_log', sync.log, http=('GET',), transform=False)
    self.resource.crud(self, method='_init')
    if (self.component is not None):
        self.component.crud(self, method='_init')
