sregistry/main/workers/tasks.py
def call(url, func, data=None, headers=None, 
                    return_json=True, stream=False, 
                    retry=True):

    '''call will issue the call, and issue a refresh token
    given a 401 response, and if the client has a _update_token function

    Parameters
    ==========
    func: the function (eg, post, get) to call
    url: the url to send file to
    headers: headers for the request
    data: additional data to add to the request
    return_json: return json if successful
    '''
 
    if DISABLE_SSL_CHECK is True:
        bot.warning('Verify of certificates disabled! ::TESTING USE ONLY::')

    if data is not None:
        if not isinstance(data,dict):
            data = json.dumps(data)

    response = func(url=url,
                    headers=headers,
                    data=data,
                    verify=not DISABLE_SSL_CHECK,
                    stream=stream)

    # Errored response, try again with refresh
    if response.status_code in [500, 502]:
        bot.error("Beep boop! %s: %s" %(response.reason,
                                        response.status_code))
        sys.exit(1)

    # Errored response, try again with refresh
    if response.status_code == 404:
        bot.error("Beep boop! %s: %s" %(response.reason,
                                        response.status_code))
        sys.exit(1)


    # Errored response, try again with refresh
    if response.status_code == 401:

        # If client has method to update token, try it once
        if retry is True:

            # A result of None indicates no update to the call
            headers = update_token(response, headers)
            return call(url, func, data=data,
                        headers=headers,
                        return_json=return_json,
                        stream=stream, retry=False)

        bot.error("Your credentials are expired! %s: %s" %(response.reason,
                                                           response.status_code))
        sys.exit(1)

    elif response.status_code == 200:

        if return_json:

            try:
                response = response.json()
            except ValueError:
                bot.error("The server returned a malformed response.")
                sys.exit(1)

    return response
def call(url, func, data=None, headers=None, 
                    return_json=True, stream=False, 
                    retry=True):

    '''call will issue the call, and issue a refresh token
    given a 401 response, and if the client has a _update_token function

    Parameters
    ==========
    func: the function (eg, post, get) to call
    url: the url to send file to
    headers: headers for the request
    data: additional data to add to the request
    return_json: return json if successful
    '''
 
    if DISABLE_SSL_CHECK is True:
        bot.warning('Verify of certificates disabled! ::TESTING USE ONLY::')

    if data is not None:
        if not isinstance(data,dict):
            data = json.dumps(data)

    response = func(url=url,
                    headers=headers,
                    data=data,
                    verify=not DISABLE_SSL_CHECK,
                    stream=stream)

    # Errored response, try again with refresh
    if response.status_code in [500, 502]:
        bot.error("Beep boop! %s: %s" %(response.reason,
                                        response.status_code))
        sys.exit(1)

    # Errored response, try again with refresh
    if response.status_code == 404:
        bot.error("Beep boop! %s: %s" %(response.reason,
                                        response.status_code))
        sys.exit(1)


    # Errored response, try again with refresh
    if response.status_code == 401:

        # If client has method to update token, try it once
        if retry is True:

            # A result of None indicates no update to the call
            headers = update_token(response, headers)
            return call(url, func, data=data,
                        headers=headers,
                        return_json=return_json,
                        stream=stream, retry=False)

        bot.error("Your credentials are expired! %s: %s" %(response.reason,
                                                           response.status_code))
        sys.exit(1)

    elif response.status_code == 200:

        if return_json:

            try:
                response = response.json()
            except ValueError:
                bot.error("The server returned a malformed response.")
                sys.exit(1)

    return response
def call ( url , func , data = None , headers = None , return_json = True , stream = False , retry = True ) : if DISABLE_SSL_CHECK is True : bot . warning ( 'Verify of certificates disabled! ::TESTING USE ONLY::' ) if data is not None : if not isinstance ( data , dict ) : data = json . dumps ( data ) response = func ( url = url , headers = headers , data = data , verify = not DISABLE_SSL_CHECK , stream = stream ) # Errored response, try again with refresh if response . status_code in [ 500 , 502 ] : bot . error ( "Beep boop! %s: %s" % ( response . reason , response . status_code ) ) sys . exit ( 1 ) # Errored response, try again with refresh if response . status_code == 404 : bot . error ( "Beep boop! %s: %s" % ( response . reason , response . status_code ) ) sys . exit ( 1 ) # Errored response, try again with refresh if response . status_code == 401 : # If client has method to update token, try it once if retry is True : # A result of None indicates no update to the call headers = update_token ( response , headers ) return call ( url , func , data = data , headers = headers , return_json = return_json , stream = stream , retry = False ) bot . error ( "Your credentials are expired! %s: %s" % ( response . reason , response . status_code ) ) sys . exit ( 1 ) elif response . status_code == 200 : if return_json : try : response = response . json ( ) except ValueError : bot . error ( "The server returned a malformed response." ) sys . exit ( 1 ) return response
call will issue the call, and issue a refresh token
    given a 401 response, and if the client has a _update_token function

    Parameters
    ==========
    func: the function (eg, post, get) to call
    url: the url to send file to
    headers: headers for the request
    data: additional data to add to the request
    return_json: return json if successful
call will issue the call and issue a refresh token given a 401 response and if the client has a _update_token function