
    .g                     P    S r SSKJr  SSKrSSKrSSKrSrSrS r	S	S jr
 S	S jrg)
zGet user credentials from interactive code environments.

This module contains helpers for getting user credentials from interactive
code environments installed on a development machine, such as Jupyter
notebooks.
    )absolute_importN	localhostd   c                 X   [         R                  " [        R                  " [        R                  [        R                  5      5       n UR                  [        U 45        UR                  S5        SnSSS5        U$ ! [        R                   a    Sn N"f = f! , (       d  f       W$ = f)a  Check if a port is open on localhost.
Based on StackOverflow answer: https://stackoverflow.com/a/43238489/101923
Parameters
----------
port : int
    A port to check on localhost.
Returns
-------
is_open : bool
    True if a socket can be opened at the requested port.
   TFN)	
contextlibclosingsocketAF_INETSOCK_STREAMbind	LOCALHOSTlistenerror)portsockis_opens      eC:\Suresh\moveshuttle\MDcreated\moveengine\venv\Lib\site-packages\google_auth_oauthlib/interactive.pyis_port_openr   "   s     
		FMM&..&:L:LM	NRV	IIy$'(KKN G 
O N	 || 	G		 
O	N Ns0   B
(A>2B>BBBB
B)c                 p    U(       d	  U [         -   n[        X5       H  n[        U5      (       d  M  Us  $    g)a  Find an open port between ``start`` and ``stop``.
Parameters
----------
start : Optional[int]
    Beginning of range of ports to try. Defaults to 8080.
stop : Optional[int]
    End of range of ports to try (not including exactly equals ``stop``).
    This function tries 100 possible ports if no ``stop`` is specified.
Returns
-------
Optional[int]
    ``None`` if no open port is found, otherwise an integer indicating an
    open port.
N)DEFAULT_PORTS_TO_TRYranger   )startstopr   s      r   find_open_portr   9   s6     ++e"K #
     c                     SUUSSS.0n[         R                  R                  R                  XPS9n[	        X4S9nU(       d  [        S5      eUR                  [        US9$ )	a
  Gets credentials associated with your Google user account.

This function authenticates using your user credentials by going through
the OAuth 2.0 flow. You'll open a browser window to authenticate to your
Google account. The permissions it requests correspond to the scopes
you've provided.

To obtain the ``client_id`` and ``client_secret``, create an **OAuth
client ID** with application type **Other** from the `Credentials page on
the Google Developer's Console
<https://console.developers.google.com/apis/credentials>`_. Learn more
with the `Authenticating as an end user
<https://cloud.google.com/docs/authentication/end-user>`_ guide.

Args:
    scopes (Sequence[str]):
        A list of scopes to use when authenticating to Google APIs. See
        the `list of OAuth 2.0 scopes for Google APIs
        <https://developers.google.com/identity/protocols/googlescopes>`_.
    client_id (str):
        A string that identifies your application to Google APIs. Find
        this value in the `Credentials page on the Google Developer's
        Console
        <https://console.developers.google.com/apis/credentials>`_.
    client_secret (str):
        A string that verifies your application to Google APIs. Find this
        value in the `Credentials page on the Google Developer's Console
        <https://console.developers.google.com/apis/credentials>`_.
    minimum_port (int):
        Beginning of range of ports to try for redirect URI HTTP server.
        Defaults to 8080.
    maximum_port (Optional[int]):
        End of range of ports to try (not including exactly equals ``stop``).
        This function tries 100 possible ports if no ``stop`` is specified.

Returns:
    google.oauth2.credentials.Credentials:
        The OAuth 2.0 credentials for the user.

Examples:
    Get credentials for your user account and use them to run a query
    with BigQuery::

        import google_auth_oauthlib

        # TODO: Create a client ID for your project.
        client_id = "YOUR-CLIENT-ID.apps.googleusercontent.com"
        client_secret = "abc_ThIsIsAsEcReT"

        # TODO: Choose the needed scopes for your applications.
        scopes = ["https://www.googleapis.com/auth/cloud-platform"]

        credentials = google_auth_oauthlib.get_user_credentials(
            scopes, client_id, client_secret
        )

        # 1. Open the link.
        # 2. Authorize the application to have access to your account.
        # 3. Copy and paste the authorization code to the prompt.

        # Use the credentials to construct a client for Google APIs.
        from google.cloud import bigquery

        bigquery_client = bigquery.Client(
            credentials=credentials, project="your-project-id"
        )
        print(list(bigquery_client.query("SELECT 1").result()))
	installedz)https://accounts.google.com/o/oauth2/authz#https://oauth2.googleapis.com/token)	client_idclient_secretauth_uri	token_uri)scopes)r   r   zCould not find open port.)hostr   )google_auth_oauthlibflowInstalledAppFlowfrom_client_configr   ConnectionErrorrun_local_serverr   )r#   r   r    minimum_portmaximum_portclient_configapp_flowr   s           r   get_user_credentialsr/   S   sx    R 	"*C>	
M $((99LL M H @D9::$$)$$??r   )i  N)__doc__
__future__r   r   r
   google_auth_oauthlib.flowr%   r   r   r   r   r/    r   r   <module>r4      s=    '     	 .6 GKY@r   