def __call__(self, request):
        """
        Pre-request hook that signs a Python-requests Request for OAuth authentication
        """
        # These checkings are necessary because type inconsisntecy of requests library
        # See request Github issue #230 https://github.com/kennethreitz/requests/pull/230
        if not request.params:
            request.params = {}
        if not request.data:
            request.data = {}
        if isinstance(request.params, list):
            request.params = dict(request.params)
        if isinstance(request.data, list):
            request.data = dict(request.data)

        # Dictionary to OAuth1 signing params
        request.oauth_params = {}

        # Adding OAuth params
        request.oauth_params['oauth_consumer_key'] = self.consumer.key
        request.oauth_params['oauth_timestamp'] = str(int(time.time()))
        request.oauth_params['oauth_nonce'] = str(random.randint(0, 100000000))
        request.oauth_params['oauth_version'] = self.OAUTH_VERSION
        if self.token:
            request.oauth_params['oauth_token'] = self.token.key
        if 'oauth_verifier' in request.data:
            request.oauth_params['oauth_verifier'] = request.data.pop('oauth_verifier')
        request.oauth_params['oauth_signature_method'] = self.signature.name

        # oauth_callback is an special parameter, we remove it out of the body
        # If it needs to go in the body, it will be overwritten later, otherwise not
        if 'oauth_callback' in request.data:
            request.oauth_params['oauth_callback'] = request.data.pop('oauth_callback')
        if 'oauth_callback' in request.params:
            request.oauth_params['oauth_callback'] = request.params.pop('oauth_callback')

        request.data_and_params = request.oauth_params.copy()
        request.oauth_params['oauth_signature'] = self.signature.sign(request, self.consumer, self.token)
        request.data_and_params['oauth_signature'] = request.oauth_params['oauth_signature']

        if self.header_auth:
            request.headers['Authorization'] = self.authorization_header(request.oauth_params)
        elif request.method in ("GET", "DELETE"):
            request.url = self.to_url(request)
        elif ('Content-Type' not in request.headers or \
              request.headers['Content-Type'] != 'application/x-www-form-urlencoded') \
              and not isinstance(request.data, basestring):
            # You can pass a string as data. See issues #10 and #12
            request.url = self.to_url(request)
            request.data = {}
        else:
            request.data = request.data_and_params

        return request
dataset/ETHPy150Open maraujop/requests-oauth/oauth_hook/hook.py/OAuthHook.__call__/original