U
    'cif                     @  s   d dl mZ ddgZd dlZd dlZd dlZd dlmZ d dlZd dl	Z	d dl
Z
eeZdddd	d
ZejZdddZdd Zdd ZG dd de	jZdS )    )annotationsCLIENT_CREDS_ENV_VARSprompt_for_user_tokenN)TracebackTypeSPOTIPY_CLIENT_IDSPOTIPY_CLIENT_SECRETZSPOTIPY_CLIENT_USERNAMESPOTIPY_REDIRECT_URI)	client_idclient_secretZclient_usernameredirect_uriFc              	   C  s   t dt |sV|std}|s,td}|s:td}|sVtd tddd|pptj	|||||| |d	}|
|j }	|	s| }
|j|
d
d}n|	d S |r|S dS dS )a2   Prompt the user to login if necessary and returns a user token
        suitable for use with the spotipy.Spotify constructor.

        .. deprecated::
            This method is deprecated and may be removed in a future version.

        Parameters:
            - username - the Spotify username. (optional)
            - scope - the desired scope of the request. (optional)
            - client_id - the client ID of your app. (required)
            - client_secret - the client secret of your app. (required)
            - redirect_uri - the redirect URI of your app. (required)
            - cache_path - path to location to save tokens. (required)
            - oauth_manager - OAuth manager object. (optional)
            - show_dialog - If True, a login prompt always shows or defaults to False. (optional)
    z'prompt_for_user_token' is deprecated.Use the following instead:     auth_manager=SpotifyOAuth(scope=scope)    spotipy.Spotify(auth_manager=auth_manager)r   r   r   a  
                You need to set your Spotify API credentials.
                You can do this by setting environment variables like so:

                export SPOTIPY_CLIENT_ID='your-spotify-client-id'
                export SPOTIPY_CLIENT_SECRET='your-spotify-client-secret'
                export SPOTIPY_REDIRECT_URI='your-app-redirect-url'

                Get your credentials at
                    https://developer.spotify.com/my-applications
            i&  zno credentials set)scope
cache_pathusernameshow_dialogF)Zas_dictZaccess_tokenN)warningswarnDeprecationWarningosgetenvloggerwarningspotipyZSpotifyExceptionZSpotifyOAuthZvalidate_tokenZcache_handlerZget_cached_tokenZget_auth_responseZget_access_token)r   r   r	   r
   r   r   Zoauth_managerr   Zsp_oauthZ
token_infocodetoken r   0/tmp/pip-unpacked-wheel-5vxoxy0m/spotipy/util.pyr      sB    


c                 C  s2   d| kr"|  dd\}}t|}n| }d}||fS )z Split the network location string into host and port and returns a tuple
        where the host is a string and the the port is an integer.

        Parameters:
            - netloc - a string representing the network location.
    :   N)splitint)netlochostportr   r   r   get_host_portw   s    
r$   c                 C  sR   | rJt | tr| d}n"t | ts.t | tr4| }ntddt|S dS dS )a;  Normalize the scope to verify that it is a list or tuple. A string
    input will split the string by commas to create a list of scopes.
    A list or tuple input is used directly.

    Parameters:
        - scope - a string representing scopes separated by commas,
                  or a list/tuple of scopes.
    ,zkUnsupported scope value, please either provide a list of scopes, or a string of scopes separated by commas. N)
isinstancestrr   listtuple	Exceptionjoinsorted)r   Zscopesr   r   r   normalize_scope   s    	
r.   c                	      s4   e Zd ZdZddddddddd	 fd
dZ  ZS )RetryzS
    Custom class for printing a warning when a rate/request limit is reached.
    Nz
str | Nonezurllib3.BaseHTTPResponse | NonezException | Nonez,urllib3.connectionpool.ConnectionPool | NonezTracebackType | Nonezurllib3.Retry)methodurlresponseerror_pool_stacktracereturnc                   sV   |r>|j d}| ||jt|r>|p*d}td| d t j||||||dS )NzRetry-Afterr   zKYour application has reached a rate/request limit. Retry will occur after: z s)r2   r3   r4   r5   )	headersgetis_retrystatusboolr   r   super	increment)selfr0   r1   r2   r3   r4   r5   Zretry_header	__class__r   r   r=      s    	zRetry.increment)NNNNNN)__name__
__module____qualname____doc__r=   __classcell__r   r   r?   r   r/      s         r/   )NNNNNNNF)
__future__r   __all__loggingr   r   typesr   requestsurllib3r   	getLoggerrA   r   r   SessionZREQUESTS_SESSIONr   r$   r.   r/   r   r   r   r   <module>   s6   
        
Y