<s> """<STR_LIT>""" <EOL> import logging <EOL> import os <EOL> import google <EOL> try : <EOL> import apiclient <EOL> except ImportError : <EOL> try : <EOL> import google_sql <EOL> google_sql . fix_sys_path ( google_sql . GOOGLE_SQL_EXTRA_PATHS ) <EOL> except ImportError : <EOL> logging . warning ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> from apiclient import errors <EOL> from apiclient import http <EOL> from apiclient import model <EOL> import httplib2 <EOL> from oauth2client import client <EOL> from oauth2client import file as oauth_file <EOL> from google . storage . speckle . proto import sql_pb2 <EOL> from google . storage . speckle . python . api import rdbms <EOL> __path__ = rdbms . __path__ <EOL> CLIENT_ID = '<STR_LIT>' <EOL> CLIENT_SECRET = '<STR_LIT>' <EOL> USER_AGENT = '<STR_LIT>' <EOL> def GetFlow ( state = None ) : <EOL> """<STR_LIT>""" <EOL> return client . OAuth2WebServerFlow ( <EOL> client_id = CLIENT_ID , <EOL> client_secret = CLIENT_SECRET , <EOL> scope = '<STR_LIT>' , <EOL> user_agent = USER_AGENT , <EOL> state = state ) <EOL> class RdbmsGoogleApiClient ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , api_url = '<STR_LIT>' , <EOL> oauth_credentials_path = None , oauth_storage = None , <EOL> developer_key = None ) : <EOL> """<STR_LIT>""" <EOL> self . _api_url = api_url <EOL> self . _developer_key = developer_key <EOL> if oauth_storage is None : <EOL> if oauth_credentials_path is None : <EOL> oauth_credentials_path = os . path . expanduser ( <EOL> rdbms . OAUTH_CREDENTIALS_PATH ) <EOL> oauth_storage = oauth_file . Storage ( oauth_credentials_path ) <EOL> credentials = oauth_storage . get ( ) <EOL> if credentials is None or credentials . invalid : <EOL> from oauth2client import tools <EOL> credentials = tools . run ( GetFlow ( ) , oauth_storage ) <EOL> self . _transport = credentials . authorize ( httplib2 . Http ( ) ) <EOL> def OpenConnection ( self , request ) : <EOL> return self . _MakeRequest ( <EOL> '<STR_LIT>' , request , sql_pb2 . OpenConnectionResponse ) <EOL> def CloseConnection ( self , request ) : <EOL> return self . _MakeRequest ( <EOL> '<STR_LIT>' , request , sql_pb2 . CloseConnectionResponse ) <EOL> def Exec ( self , request ) : <EOL> return self . _MakeRequest ( '<STR_LIT>' , request , sql_pb2 . ExecResponse ) <EOL> def ExecOp ( self , request ) : <EOL> return self . _MakeRequest ( '<STR_LIT>' , request , sql_pb2 . ExecOpResponse ) <EOL> def GetMetadata ( self , request ) : <EOL> return self . _MakeRequest ( <EOL> '<STR_LIT>' , request , sql_pb2 . MetadataResponse ) <EOL> def _MakeRequest ( self , method , request , response_class ) : <EOL> """<STR_LIT>""" <EOL> pb_model = model . ProtocolBufferModel ( response_class ) <EOL> query_params = { } <EOL> if self . _developer_key : <EOL> query_params [ '<STR_LIT:key>' ] = self . _developer_key <EOL> headers , unused_params , query , body = pb_model . request ( <EOL> { } , { } , query_params , request ) <EOL> request = http . HttpRequest ( <EOL> self . _transport , pb_model . response , self . _api_url + method + query , <EOL> method = '<STR_LIT:POST>' , body = body , headers = headers ) <EOL> return request . execute ( ) <EOL> class GoogleApiConnection ( rdbms . Connection ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . _oauth_credentials_path = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . _oauth_storage = kwargs . pop ( '<STR_LIT>' , None ) <EOL> self . _developer_key = kwargs . pop ( '<STR_LIT>' , None ) <EOL> super ( GoogleApiConnection , self ) . __init__ ( * args , ** kwargs ) <EOL> def SetupClient ( self ) : <EOL> """<STR_LIT>""" <EOL> kwargs = { '<STR_LIT>' : self . _developer_key , <EOL> '<STR_LIT>' : self . _oauth_storage } <EOL> if self . _dsn : <EOL> kwargs [ '<STR_LIT>' ] = self . _dsn <EOL> if self . _oauth_credentials_path : <EOL> kwargs [ '<STR_LIT>' ] = self . _oauth_credentials_path <EOL> self . _client = RdbmsGoogleApiClient ( ** kwargs ) <EOL> def MakeRequestImpl ( self , stub_method , request ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> response = getattr ( self . _client , stub_method ) ( request ) <EOL> except ( errors . Error , client . Error , httplib2 . HttpLib2Error ) , e : <EOL> raise OperationalError ( '<STR_LIT>' + str ( e ) ) <EOL> return response <EOL> apilevel = rdbms . apilevel <EOL> threadsafety = rdbms . threadsafety <EOL> paramstyle = rdbms . paramstyle <EOL> version_info = rdbms . version_info <EOL> Binary = rdbms . Binary <EOL> Date = rdbms . Date <EOL> Time = rdbms . Time <EOL> Timestamp = rdbms . Timestamp <EOL> DateFromTicks = rdbms . DateFromTicks <EOL> TimeFromTicks = rdbms . TimeFromTicks <EOL> TimestampFromTicks = rdbms . TimestampFromTicks <EOL> STRING = rdbms . STRING <EOL> BINARY = rdbms . BINARY <EOL> NUMBER = rdbms . NUMBER <EOL> DATETIME = rdbms . DATETIME <EOL> ROWID = rdbms . ROWID <EOL> Warning = rdbms . Warning <EOL> Error = rdbms . Error <EOL> InterfaceError = rdbms . InterfaceError <EOL> DatabaseError = rdbms . DatabaseError <EOL> DataError = rdbms . DataError <EOL> OperationalError = rdbms . OperationalError <EOL> IntegrityError = rdbms . IntegrityError <EOL> InternalError = rdbms . InternalError <EOL> ProgrammingError = rdbms . ProgrammingError <EOL> NotSupportedError = rdbms . NotSupportedError <EOL> connect = GoogleApiConnection </s>
