'Tries to do the identification'

def identify(self, environ):

    query = parse_dict_querystring(environ)
    if ((('CONTENT_LENGTH' not in environ) or (not environ['CONTENT_LENGTH'])) and ('SAMLResponse' not in query) and ('SAMLRequest' not in query)):
        logger.debug('[identify]    get    or    empty    post')
        return None
    uri = environ.get('REQUEST_URI', construct_url(environ))
    logger.debug(('[sp.identify]    uri:    %s' % (uri,)))
    query = parse_dict_querystring(environ)
    logger.debug(('[sp.identify]    query:    %s' % (query,)))
    if (('SAMLResponse' in query) or ('SAMLRequest' in query)):
        post = query
        binding = BINDING_HTTP_REDIRECT
    else:
        post = self._get_post(environ)
        binding = BINDING_HTTP_POST
    try:
        logger.debug(('[sp.identify]    post    keys:    %s' % (post.keys(),)))
    except (TypeError, IndexError):
        pass
    try:
        path_info = environ['PATH_INFO']
        logout = False
        if (path_info in self.logout_endpoints):
            logout = True
        if (logout and ('SAMLRequest' in post)):
            print 'logout    request    received'
            try:
                response = self.saml_client.handle_logout_request(post['SAMLRequest'][0], self.saml_client.users.subjects()[0], binding)
                environ['samlsp.pending'] = self._handle_logout(response)
                return {}
            except:
                import traceback
                traceback.print_exc()
        elif ('SAMLResponse' not in post):
            logger.info('[sp.identify]    ---    NOT    SAMLResponse    ---')
            environ['post.fieldstorage'] = post
            if ('s2repoze.body' in environ):
                environ['wsgi.input'] = StringIO(environ['s2repoze.body'])
            return {}
        else:
            logger.info('[sp.identify]    ---    SAMLResponse    ---')
            try:
                if logout:
                    response = self.saml_client.parse_logout_request_response(post['SAMLResponse'][0], binding)
                    if response:
                        action = self.saml_client.handle_logout_response(response)
                        if (type(action) == dict):
                            request = self._handle_logout(action)
                        else:
                            request = HTTPSeeOther(headers=[('Location', '/')])
                        if request:
                            environ['samlsp.pending'] = request
                        return {}
                else:
                    session_info = self._eval_authn_response(environ, post, binding=binding)
            except Exception as err:
                environ['s2repoze.saml_error'] = err
                return {}
    except TypeError as exc:
        body = environ.get('s2repoze.body', None)
        if body:
            try:
                session_info = self.do_ecp_response(body, environ)
            except Exception as err:
                environ['post.fieldstorage'] = post
                environ['s2repoze.saml_error'] = err
                return {}
        else:
            exception_trace('sp.identity', exc, logger)
            environ['post.fieldstorage'] = post
            return {}
    if session_info:
        environ['s2repoze.sessioninfo'] = session_info
        return self._construct_identity(session_info)
    else:
        return None
