'S3 framework function
Designed to be used within tasks, which are run in a separate
request & hence don\'t have access to current.auth
@param user_id: auth.user.id or auth.user.email'

def s3_impersonate(self, user_id):

    settings = self.settings
    utable = settings.table_user
    query = None
    if (not user_id):
        user = None
    elif (isinstance(user_id, basestring) and (not user_id.isdigit())):
        query = (utable[settings.login_userfield] == user_id)
    else:
        query = (utable.id == user_id)
    if (query is not None):
        user = current.db(query).select(limitby=(0, 1)).first()
        if (not user):
            raise ValueError('User    not    found')
        else:
            user = Storage(utable._filter_fields(user, id=True))
    self.user = user
    session = current.session
    session.auth = Storage(user=user, last_visit=current.request.now, expiration=settings.expiration)
    self.s3_set_roles()
    if user:
        language = user.language
        current.T.force(language)
        session.s3.language = language
    return user
