コード例 #1
0
def fas_request_classifier(environ): 
    classifier = default_request_classifier(environ) 
    if classifier == 'browser': 
        request = webob.Request(environ) 
        if not request.accept.best_match(['application/xhtml+xml','text/html']): 
            classifier = 'app' 
    return classifier 
コード例 #2
0
def classifier_for_flash_uploads(environ):
    """Normally classifies the request as browser, dav or xmlpost.

    When the Flash uploader is sending a file, it appends the authtkt session
    ID to the POST data so we spoof the cookie header so that the auth code
    will think this was a normal request. In the process, we overwrite any
    pseudo-cookie data that is sent by Flash.

    TODO: Currently overwrites the HTTP_COOKIE, should ideally append.
    """
    classification = default_request_classifier(environ)
    if classification != 'browser':
        return classification
    user_agent = environ.get('HTTP_USER_AGENT', '')
    if environ['REQUEST_METHOD'] == 'POST' and ('Flash' in user_agent):
        session_key = environ['repoze.who.plugins']['cookie'].cookie_name
        # Construct a temporary request object since this is called before
        # pylons.request is populated. Re-instantiation later comes cheap.
        request = Request(environ)
        try:
            session_id = str(request.POST[session_key])
            environ['HTTP_COOKIE'] = '%s=%s' % (session_key, session_id)
        except (KeyError, UnicodeEncodeError):
            pass
    return classification
コード例 #3
0
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """


    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        login_form_url = '/login'
        login_handler = '/login_handler'
        logout_handler = '/logout_handler'
        logout_url = '/logout'
        # Decide if the client is a (user-driven) browser or an application
        if config.has_key("who.config_file"):
            config_file = config["who.config_file"]
            config_who = ConfigParser.ConfigParser()
            config_who.readfp(open(config_file))
            login_form_url = config_who.get("plugin:friendlyform", "login_form_url")
            login_handler = config_who.get("plugin:friendlyform", "login_handler_path")
            logout_handler = config_who.get("plugin:friendlyform", "logout_handler_path")
            logout_url = config_who.get("plugin:friendlyform", "post_logout_url")

        path_info = environ['PATH_INFO']
        #request = Request(environ)
        #if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
        #    # In our view, any client who doesn't support HTML/XHTML is an "app",
        #    #   not a (user-driven) "browser".
        #    classifier = 'app'
        if not path_info in [login_form_url, login_handler, logout_handler, logout_url]:
            # In our view, any client who hasn't come in from the login url is an app
            classifier = 'app'
    return classifier
コード例 #4
0
ファイル: middleware.py プロジェクト: mkrysiak/mediadrop
def classifier_for_flash_uploads(environ):
    """Normally classifies the request as browser, dav or xmlpost.

    When the Flash uploader is sending a file, it appends the authtkt session
    ID to the POST data so we spoof the cookie header so that the auth code
    will think this was a normal request. In the process, we overwrite any
    pseudo-cookie data that is sent by Flash.

    TODO: Currently overwrites the HTTP_COOKIE, should ideally append.
    """
    classification = default_request_classifier(environ)
    if classification != 'browser':
        return classification
    user_agent = environ.get('HTTP_USER_AGENT', '')
    if environ['REQUEST_METHOD'] == 'POST' and ('Flash' in user_agent):
        session_key = environ['repoze.who.plugins']['cookie'].cookie_name
        # Construct a temporary request object since this is called before
        # pylons.request is populated. Re-instantiation later comes cheap.
        request = Request(environ)
        try:
            session_id = str(request.POST[session_key])
            environ['HTTP_COOKIE'] = '%s=%s' % (session_key, session_id)
        except (KeyError, UnicodeEncodeError):
            pass
    return classification
コード例 #5
0
def fas_request_classifier(environ):
    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        request = webob.Request(environ)
        if not request.accept.best_match(
            ['application/xhtml+xml', 'text/html']):
            classifier = 'app'
    return classifier
コード例 #6
0
def bisque_request_classifier(environ):
    request_method = REQUEST_METHOD(environ)
    content_type = CONTENT_TYPE(environ)
    if request_method == "POST" and content_type.startswith(
            "application/json"):
        return "json"
    if content_type.startswith("application/xml"):
        return "xml"
    return default_request_classifier(environ)
コード例 #7
0
ファイル: auth.py プロジェクト: inpho/inphosite
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """
    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        # Decide if the client is a (user-driven) browser or an application
        request = Request(environ)
        if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
            # In our view, any client who doesn't support HTML/XHTML is an "app",
            #   not a (user-driven) "browser".
            classifier = 'app'
    
    return classifier
コード例 #8
0
ファイル: auth.py プロジェクト: teamwalkr/walkr
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """
    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        # Decide if the client is a (user-driven) browser or an application
        request = Request(environ)
        if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
            # In our view, any client who doesn't support HTML/XHTML is an "app",
            #   not a (user-driven) "browser".
            classifier = 'app'
    
    return classifier
コード例 #9
0
ファイル: classifier.py プロジェクト: vigilo/turbogears
def vigilo_classifier(environ):
    from paste.httpheaders import PATH_INFO
    if '/api/' in PATH_INFO(environ):
        return 'vigilo-api'

    # Sinon, on s'en remet au classifier par défaut (qui identifie
    # le type "browser" correspondant à une requête de navigateur HTTP).
    default = default_request_classifier(environ)

    # S'il s'agit d'une requête de navigateur et qu'une authentification
    # externe a été utilisée, on l'indique ici.
    # @TODO:    repoze.who permet de définir une autre clé que REMOTE_USER;
    #           il faudrait réutiliser celle définie via repoze.who.
    if default == 'browser' and environ.get('REMOTE_USER'):
        return 'browser-external'
    return default
コード例 #10
0
ファイル: auth.py プロジェクト: 86me/mediacore
def classifier_for_flash_uploads(environ):
    """Normally classifies the request as browser, dav or xmlpost.

    When the Flash uploader is sending a file, it appends the authtkt session ID
    to the POST data so we spoof the cookie header so that the auth code will
    think this was a normal request. In the process, we overwrite any
    pseudo-cookie data that is sent by Flash.

    TODO: Currently overwrites the HTTP_COOKIE, should ideally append.
    """
    classification = default_request_classifier(environ)
    if classification == 'browser' and environ['REQUEST_METHOD'] == 'POST'\
                                   and 'Flash' in environ['HTTP_USER_AGENT']:
        try:
            session_key = environ['repoze.who.plugins']['cookie'].cookie_name
            session_id = parse_formvars(environ)[session_key]
            environ['HTTP_COOKIE'] = '%s=%s' % (session_key, session_id)
            del environ['paste.cookies']
            del environ['paste.cookies.dict']
        except (KeyError, AttributeError):
            pass
    return classification
コード例 #11
0
def custom_request_classifier(environ):
    """ Returns one of the classifiers 'app', 'browser' or any
    standard classifiers returned by
    repoze.who.classifiers:default_request_classifier
    """

    classifier = default_request_classifier(environ)
    if classifier == 'browser':
        login_form_url = '/login'
        login_handler = '/login_handler'
        logout_handler = '/logout_handler'
        logout_url = '/logout'
        # Decide if the client is a (user-driven) browser or an application
        if config.has_key("who.config_file"):
            config_file = config["who.config_file"]
            config_who = ConfigParser.ConfigParser()
            config_who.readfp(open(config_file))
            login_form_url = config_who.get("plugin:friendlyform",
                                            "login_form_url")
            login_handler = config_who.get("plugin:friendlyform",
                                           "login_handler_path")
            logout_handler = config_who.get("plugin:friendlyform",
                                            "logout_handler_path")
            logout_url = config_who.get("plugin:friendlyform",
                                        "post_logout_url")

        path_info = environ['PATH_INFO']
        #request = Request(environ)
        #if not request.accept.best_match(['application/xhtml+xml', 'text/html']):
        #    # In our view, any client who doesn't support HTML/XHTML is an "app",
        #    #   not a (user-driven) "browser".
        #    classifier = 'app'
        if not path_info in [
                login_form_url, login_handler, logout_handler, logout_url
        ]:
            # In our view, any client who hasn't come in from the login url is an app
            classifier = 'app'
    return classifier
コード例 #12
0
ファイル: auth.py プロジェクト: nguyennamtien/mediacore
def classifier_for_flash_uploads(environ):
    """Normally classifies the request as browser, dav or xmlpost.

    When the Flash uploader is sending a file, it appends the authtkt session
    ID to the POST data so we spoof the cookie header so that the auth code
    will think this was a normal request. In the process, we overwrite any
    pseudo-cookie data that is sent by Flash.

    TODO: Currently overwrites the HTTP_COOKIE, should ideally append.
    """
    classification = default_request_classifier(environ)
    if classification == 'browser' \
    and environ['REQUEST_METHOD'] == 'POST' \
    and 'Flash' in environ.get('HTTP_USER_AGENT', ''):
        try:
            session_key = environ['repoze.who.plugins']['cookie'].cookie_name
            session_id = parse_formvars(environ)[session_key]
            environ['HTTP_COOKIE'] = '%s=%s' % (session_key, session_id)
            del environ['paste.cookies']
            del environ['paste.cookies.dict']
        except (KeyError, AttributeError):
            pass
    return classification
コード例 #13
0
def static_request_classifier(environ):
    classifier = default_request_classifier(environ)
    if environ['PATH_INFO'].startswith('/static') and classifier == 'browser':
        return 'browser_static'
    return classifier