EVOLUTION-MANAGER
Edit File: __init__.cpython-36.opt-1.pyc
3 �f � @ sn d dl Z yd dlZdZW n ek r0 dZY nX d dlZd dlmZmZ dZdZe j d�Z G dd � d �ZdS ) � NTF)�datetime� timedeltaz sos-toolsz,urn:ietf:params:oauth:grant-type:device_codeZsosc @ sZ e Zd ZdZdd� Zdd� Zdd� Zdd � Zd d� Zdd � Z dd� Z dd� Zddd�ZdS )�DeviceAuthorizationClassz$ Device Authorization Class c C s* d | _ d | _d | _|| _|| _| j� d S )N)� _access_token�_access_expires_at�&_DeviceAuthorizationClass__device_code�client_identifier_url�token_endpoint�_use_device_code_grant)�selfr r � r �/usr/lib/python3.6/__init__.py�__init__ s z!DeviceAuthorizationClass.__init__c C s$ | j � td| j� �� | j� dS )zv Start the device auth flow. In the future we will store the tokens in an in-memory keyring. z<Please visit the following URL to authenticate this device: N)�_request_device_code�print�_verification_uri_complete�poll_for_auth_completion)r r r r r ) s z/DeviceAuthorizationClass._use_device_code_grantc C s� dj t�}ddi}tstd��ybtj| j||d�}|j� |j� }|j d�| _ |j d�| _|j d�| _|j d �| _ |j d �| _W n< tjk r� } ztjd|j� d|� ���W Y d d }~X nX d S )zm Initialize new Device Authorization Grant attempt by requesting a new device code. zclient_id={}zcontent-typez!application/x-www-form-urlencodedzRpython3-requests is not installed and is required for obtaining device auth token.)�data�headersZ user_codeZverification_uriZinterval�device_codeZverification_uri_completezNHTTP request failed while attempting to acquire the tokens.Error returned was � N)�format�DEVICE_AUTH_CLIENT_ID�REQUESTS_LOADED� Exception�requests�postr Zraise_for_status�json�getZ _user_codeZ_verification_uri� _intervalr r Z HTTPError�status_code)r r r �resZresponse�er r r r 7 s&