def oauth_handshake2(self, scope=True, scope_type=None, parameters=None, param_type='qs', change_scope=[],
        request_nonce='', access_nonce='', resource_nonce=''):

        # ============= INITIATE =============
        if not request_nonce:
            request_nonce = "request_nonce2"

        oauth_header_request_token_params = "OAuth realm=\"test\","\
               "oauth_consumer_key=\"%s\","\
               "oauth_signature_method=\"HMAC-SHA1\","\
               "oauth_timestamp=\"%s\","\
               "oauth_nonce=\"%s\","\
               "oauth_version=\"1.0\","\
               "oauth_callback=\"http://example.com/access_token_ready\"" % (self.consumer2.key,str(int(time.time())), request_nonce)

        # Add non oauth parameters appropriately
        request_token_params = {}
        if parameters:
            request_token_params = parameters

        if scope:
            if scope_type:
                request_token_params['scope'] = scope_type
            else:
                request_token_params['scope'] = "all"

        if param_type == 'qs':
            request_token_path = "%s?%s" % (INITIATE_ENDPOINT, urllib.urlencode(request_token_params))
        else:
            request_token_path = INITIATE_ENDPOINT

        # Make the params into a dict to pass into from_consumer_and_token
        oauth_header_request_token_params_list = oauth_header_request_token_params.split(",")
        oauth_header_request_token_params_dict = {}
        for p in oauth_header_request_token_params_list:
            item = p.split("=")
            oauth_header_request_token_params_dict[str(item[0]).strip()] = str(item[1]).strip('"')
        
        # get_oauth_request in views ignores realm, must remove so not input to from_token_and_callback
        del oauth_header_request_token_params_dict['OAuth realm']

        if param_type == 'qs':
            oauth_request = oauth.Request.from_consumer_and_token(self.consumer2, token=None, http_method='GET',
                http_url=request_token_path, parameters=oauth_header_request_token_params_dict)
        else:
            oauth_request = oauth.Request.from_consumer_and_token(self.consumer2, token=None, http_method='POST',
                http_url=request_token_path, parameters=dict(oauth_header_request_token_params_dict.items()+request_token_params.items()))

        
        # create signature and add it to the header params
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer2, None)
        oauth_header_request_token_params = oauth_header_request_token_params + signature % ",oauth_signature=%s"
        
        if param_type == 'qs':
            request_resp = self.client.get(request_token_path, Authorization=oauth_header_request_token_params)
        else:
            request_resp = self.client.post(request_token_path, Authorization=oauth_header_request_token_params, data=request_token_params,
                content_type="application/x-www-form-urlencoded")

        self.assertEqual(request_resp.status_code, 200)
        self.assertIn('oauth_token_secret', request_resp.content)
        self.assertIn('oauth_token', request_resp.content)
        self.assertIn('oauth_callback_confirmed', request_resp.content)
        request_token = Token.objects.get(consumer=self.consumer2)
        # ============= END INITIATE =============


        # ============= AUTHORIZE =============
        authorize_param = {'oauth_token': request_token.key}
        authorize_path = "%s?%s" % (AUTHORIZATION_ENDPOINT, urllib.urlencode(authorize_param)) 

        auth_resp = self.client.get(authorize_path)
        self.assertEqual(auth_resp.status_code, 302)
        self.assertIn('/accounts/login?next=/XAPI/OAuth/authorize%3F', auth_resp['Location'])
        self.assertIn(request_token.key, auth_resp['Location'])    
        self.client.login(username='dick', password='lassie')
        self.assertEqual(request_token.is_approved, False)
        # After being redirected to login and logging in again, try get again
        auth_resp = self.client.get(authorize_path)
        self.assertEqual(auth_resp.status_code, 200) # Show return/display OAuth authorized view
        
        auth_form = auth_resp.context['form']
        data = auth_form.initial
        data['authorize_access'] = 1
        data['oauth_token'] = request_token.key

        # Change scope if wanted
        if change_scope:
            data['scope'] = change_scope

        auth_post = self.client.post(AUTHORIZATION_ENDPOINT, data)
        self.assertEqual(auth_post.status_code, 302)
        # Check if oauth_verifier and oauth_token are returned
        self.assertIn('http://example.com/access_token_ready?oauth_verifier=', auth_post['Location'])
        self.assertIn('oauth_token=', auth_post['Location'])
        request_token_after_auth = Token.objects.get(consumer=self.consumer2)
        self.assertIn(request_token_after_auth.key, auth_post['Location'])
        self.assertEqual(request_token_after_auth.is_approved, True)
        #  ============= END AUTHORIZE =============


        # ============= ACCESS TOKEN =============
        if not access_nonce:
            access_nonce = "access_nonce2"

        oauth_header_access_token_params = "OAuth realm=\"test\","\
            "oauth_consumer_key=\"%s\","\
            "oauth_token=\"%s\","\
            "oauth_signature_method=\"HMAC-SHA1\","\
            "oauth_timestamp=\"%s\","\
            "oauth_nonce=\"%s\","\
            "oauth_version=\"1.0\","\
            "oauth_verifier=\"%s\"" % (self.consumer2.key, request_token_after_auth.key, str(int(time.time())), access_nonce, request_token_after_auth.verifier)

        # from_token_and_callback takes a dictionary        
        param_list = oauth_header_access_token_params.split(",")
        oauth_header_access_params_dict = {}
        for p in param_list:
            item = p.split("=")
            oauth_header_access_params_dict[str(item[0]).strip()] = str(item[1]).strip('"')
        
        # from_request ignores realm, must remove so not input to from_token_and_callback
        del oauth_header_access_params_dict['OAuth realm']
        oauth_request = oauth.Request.from_token_and_callback(request_token_after_auth, http_method='GET',
            http_url=TOKEN_ENDPOINT, parameters=oauth_header_access_params_dict)

        # Create signature and add it to the headers
        signature_method = oauth.SignatureMethod_HMAC_SHA1()
        signature = signature_method.sign(oauth_request, self.consumer2, request_token_after_auth)
        oauth_header_access_token_params += ',oauth_signature="%s"' % signature

        access_resp = self.client.get(TOKEN_ENDPOINT, Authorization=oauth_header_access_token_params)
        self.assertEqual(access_resp.status_code, 200)
        content = access_resp.content.split('&')
        access_token_secret = content[0].split('=')[1]
        access_token_key = content[1].split('=')[1]
        access_token = Token.objects.get(secret=access_token_secret, key=access_token_key)
        #  ============= END ACCESS TOKEN =============

        if not resource_nonce:
            resource_nonce = "resource_nonce2"

        oauth_header_resource_params = "OAuth realm=\"test\", "\
            "oauth_consumer_key=\"%s\","\
            "oauth_token=\"%s\","\
            "oauth_signature_method=\"HMAC-SHA1\","\
            "oauth_timestamp=\"%s\","\
            "oauth_nonce=\"%s\","\
            "oauth_version=\"1.0\"" % (self.consumer2.key, access_token.key, str(int(time.time())), resource_nonce)

        self.client.logout()
        return oauth_header_resource_params, access_token
dataset/ETHPy150Open adlnet/ADL_LRS/lrs/tests/test_OAuth.py/OAuthTests.oauth_handshake2/swapped operands of `%`