#NEWLINE# def generate_temp_url( path , seconds , key , method , absolute = False ) : #NEWLINE# #INDENT# 'Generates a temporary URL that gives unauthenticated access to the\n    Swift object.\n\n    :param path: The full path to the Swift object. Example:\n        /v1/AUTH_account/c/o.\n    :param seconds: The amount of time in seconds the temporary URL will\n        be valid for.\n    :param key: The secret temporary URL key set on the Swift\n        cluster. To set a key, run \'swift post -m\n        "Temp-URL-Key: <substitute tempurl key here>"\'\n    :param method: A HTTP method, typically either GET or PUT, to allow\n        for this temporary URL.\n    :raises: ValueError if seconds is not a positive integer\n    :raises: TypeError if seconds is not an integer\n    :return: the path portion of a temporary URL\n    ' #NEWLINE# if ( seconds < 0 ) : #NEWLINE# #INDENT# raise ValueError ( 'seconds must be a positive integer' ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# if ( not absolute ) : #NEWLINE# #INDENT# expiration = int ( ( time . time ( ) + seconds ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# expiration = int ( seconds ) #NEWLINE# #UNINDENT# #UNINDENT# except TypeError : #NEWLINE# #INDENT# raise TypeError ( 'seconds must be an integer' ) #NEWLINE# #UNINDENT# standard_methods = [ 'GET' , 'PUT' , 'HEAD' , 'POST' , 'DELETE' ] #NEWLINE# if ( method . upper ( ) not in standard_methods ) : #NEWLINE# #INDENT# logger = logging . getLogger ( 'swiftclient' ) #NEWLINE# logger . warning ( 'Non default HTTP method %s for tempurl specified, possibly an error' , method . upper ( ) ) #NEWLINE# #UNINDENT# hmac_body = '\n' . join ( [ method . upper ( ) , str ( expiration ) , path ] ) #NEWLINE# sig = hmac . new ( key . encode ( ) , hmac_body . encode ( ) , hashlib . sha1 ) . hexdigest ( ) #NEWLINE# return '{path}?temp_url_sig={sig}&temp_url_expires={exp}' . format ( path = path , sig = sig , exp = expiration )