<s> """<STR_LIT>""" <EOL> import json <EOL> import os <EOL> import socket <EOL> from oauth2client . _helpers import _to_bytes <EOL> from oauth2client import client <EOL> DEVSHELL_ENV = '<STR_LIT>' <EOL> class Error ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CommunicationError ( Error ) : <EOL> """<STR_LIT>""" <EOL> class NoDevshellServer ( Error ) : <EOL> """<STR_LIT>""" <EOL> CREDENTIAL_INFO_REQUEST_JSON = '<STR_LIT>' <EOL> class CredentialInfoResponse ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , json_string ) : <EOL> """<STR_LIT>""" <EOL> pbl = json . loads ( json_string ) <EOL> if not isinstance ( pbl , list ) : <EOL> raise ValueError ( '<STR_LIT>' + str ( pbl ) ) <EOL> pbl_len = len ( pbl ) <EOL> self . user_email = pbl [ <NUM_LIT:0> ] if pbl_len > <NUM_LIT:0> else None <EOL> self . project_id = pbl [ <NUM_LIT:1> ] if pbl_len > <NUM_LIT:1> else None <EOL> self . access_token = pbl [ <NUM_LIT:2> ] if pbl_len > <NUM_LIT:2> else None <EOL> def _SendRecv ( ) : <EOL> """<STR_LIT>""" <EOL> port = int ( os . getenv ( DEVSHELL_ENV , <NUM_LIT:0> ) ) <EOL> if port == <NUM_LIT:0> : <EOL> raise NoDevshellServer ( ) <EOL> sock = socket . socket ( ) <EOL> sock . connect ( ( '<STR_LIT:localhost>' , port ) ) <EOL> data = CREDENTIAL_INFO_REQUEST_JSON <EOL> msg = '<STR_LIT>' % ( len ( data ) , data ) <EOL> sock . sendall ( _to_bytes ( msg , encoding = '<STR_LIT:utf-8>' ) ) <EOL> header = sock . recv ( <NUM_LIT:6> ) . decode ( ) <EOL> if '<STR_LIT:\n>' not in header : <EOL> raise CommunicationError ( '<STR_LIT>' ) <EOL> len_str , json_str = header . split ( '<STR_LIT:\n>' , <NUM_LIT:1> ) <EOL> to_read = int ( len_str ) - len ( json_str ) <EOL> if to_read > <NUM_LIT:0> : <EOL> json_str += sock . recv ( to_read , socket . MSG_WAITALL ) . decode ( ) <EOL> return CredentialInfoResponse ( json_str ) <EOL> class DevshellCredentials ( client . GoogleCredentials ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , user_agent = None ) : <EOL> super ( DevshellCredentials , self ) . __init__ ( <EOL> None , <EOL> None , <EOL> None , <EOL> None , <EOL> None , <EOL> None , <EOL> user_agent ) <EOL> self . _refresh ( None ) <EOL> def _refresh ( self , http_request ) : <EOL> self . devshell_response = _SendRecv ( ) <EOL> self . access_token = self . devshell_response . access_token <EOL> @ property <EOL> def user_email ( self ) : <EOL> return self . devshell_response . user_email <EOL> @ property <EOL> def project_id ( self ) : <EOL> return self . devshell_response . project_id <EOL> @ classmethod <EOL> def from_json ( cls , json_data ) : <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) <EOL> @ property <EOL> def serialization_data ( self ) : <EOL> raise NotImplementedError ( <EOL> '<STR_LIT>' ) </s>
