<s> """<STR_LIT>""" <EOL> import cookielib <EOL> import commands <EOL> import fancy_urllib <EOL> import logging <EOL> import os <EOL> import re <EOL> import socket <EOL> import sys <EOL> import urllib <EOL> import urllib2 <EOL> import urlparse <EOL> from google . appengine . tools import dev_appserver_login <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> APPSCALE_DASHBOARD_IP_LOC = "<STR_LIT>" <EOL> def GetPlatformToken ( os_module = os , sys_module = sys , platform = sys . platform ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( os_module , "<STR_LIT>" ) : <EOL> uname = os_module . uname ( ) <EOL> return "<STR_LIT>" % ( uname [ <NUM_LIT:0> ] , uname [ <NUM_LIT:2> ] ) <EOL> else : <EOL> return "<STR_LIT>" <EOL> def HttpRequestToString ( req , include_data = True ) : <EOL> """<STR_LIT>""" <EOL> headers = "<STR_LIT>" <EOL> for header in req . header_items ( ) : <EOL> headers += "<STR_LIT>" % ( header [ <NUM_LIT:0> ] , header [ <NUM_LIT:1> ] ) <EOL> template = ( "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> if include_data : <EOL> template = template + "<STR_LIT>" <EOL> return template % { <EOL> '<STR_LIT>' : req . get_method ( ) , <EOL> '<STR_LIT>' : req . get_selector ( ) , <EOL> '<STR_LIT:type>' : req . get_type ( ) . upper ( ) , <EOL> '<STR_LIT:host>' : req . get_host ( ) , <EOL> '<STR_LIT>' : headers , <EOL> '<STR_LIT:data>' : req . get_data ( ) , <EOL> } <EOL> class ClientLoginError ( urllib2 . HTTPError ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , url , code , msg , headers , args ) : <EOL> urllib2 . HTTPError . __init__ ( self , url , code , msg , headers , None ) <EOL> self . args = args <EOL> self . _reason = args . get ( "<STR_LIT>" ) <EOL> self . info = args . get ( "<STR_LIT>" ) <EOL> def read ( self ) : <EOL> return '<STR_LIT>' % ( self . code , self . msg , self . reason ) <EOL> @ property <EOL> def reason ( self ) : <EOL> return self . _reason <EOL> class AbstractRpcServer ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , host , auth_function , user_agent , source , <EOL> host_override = None , extra_headers = None , save_cookies = False , <EOL> auth_tries = <NUM_LIT:3> , account_type = None , debug_data = True , secure = True , <EOL> ignore_certs = False , rpc_tries = <NUM_LIT:3> ) : <EOL> """<STR_LIT>""" <EOL> self . _APPSCALE_LOGIN_PAGE = "<STR_LIT>" <EOL> self . _APPSCALE_AUTH_PAGE = "<STR_LIT>" <EOL> if secure : <EOL> self . scheme = "<STR_LIT>" <EOL> else : <EOL> self . scheme = "<STR_LIT:http>" <EOL> self . ignore_certs = ignore_certs <EOL> self . host = host <EOL> self . host_override = host_override <EOL> self . auth_function = auth_function <EOL> self . source = source <EOL> self . authenticated = False <EOL> self . auth_tries = auth_tries <EOL> self . debug_data = debug_data <EOL> self . rpc_tries = rpc_tries <EOL> self . account_type = account_type <EOL> self . read_credentials = False <EOL> self . username = None <EOL> self . password = None <EOL> self . appserver_url = None <EOL> self . last_appserver_ip = None <EOL> self . extra_headers = { } <EOL> if user_agent : <EOL> self . extra_headers [ "<STR_LIT>" ] = user_agent <EOL> if extra_headers : <EOL> self . extra_headers . update ( extra_headers ) <EOL> self . save_cookies = save_cookies <EOL> self . cookie_jar = cookielib . MozillaCookieJar ( ) <EOL> self . opener = self . _GetOpener ( ) <EOL> if self . host_override : <EOL> logger . debug ( "<STR_LIT>" , self . host , self . host_override ) <EOL> else : <EOL> logger . debug ( "<STR_LIT>" , self . host ) <EOL> if ( ( self . host_override and self . host_override == "<STR_LIT:localhost>" ) or <EOL> self . host == "<STR_LIT:localhost>" or self . host . startswith ( "<STR_LIT>" ) ) : <EOL> self . _DevAppServerAuthenticate ( ) <EOL> def _GetOpener ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NotImplementedError <EOL> def _CreateRequest ( self , url , data = None ) : <EOL> """<STR_LIT>""" <EOL> req = fancy_urllib . FancyRequest ( url , data = data ) <EOL> if self . host_override : <EOL> req . add_header ( "<STR_LIT>" , self . host_override ) <EOL> for key , value in self . extra_headers . iteritems ( ) : <EOL> req . add_header ( key , value ) <EOL> return req <EOL> def _GetAuthToken ( self , email , password ) : <EOL> """<STR_LIT>""" <EOL> account_type = self . account_type <EOL> if not account_type : <EOL> if ( self . host . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] . endswith ( "<STR_LIT>" ) <EOL> or ( self . host_override <EOL> and self . host_override . split ( '<STR_LIT::>' ) [ <NUM_LIT:0> ] . endswith ( "<STR_LIT>" ) ) ) : <EOL> account_type = "<STR_LIT>" <EOL> else : <EOL> account_type = "<STR_LIT>" <EOL> data = { <EOL> "<STR_LIT>" : email , <EOL> "<STR_LIT>" : password , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT:source>" : self . source , <EOL> "<STR_LIT>" : account_type <EOL> } <EOL> req = self . _CreateRequest ( <EOL> url = ( "<STR_LIT>" % <EOL> os . getenv ( "<STR_LIT>" , "<STR_LIT>" ) ) , <EOL> data = urllib . urlencode ( data ) ) <EOL> try : <EOL> response = self . opener . open ( req ) <EOL> response_body = response . read ( ) <EOL> response_dict = dict ( x . split ( "<STR_LIT:=>" ) <EOL> for x in response_body . split ( "<STR_LIT:\n>" ) if x ) <EOL> return response_dict [ "<STR_LIT>" ] <EOL> except urllib2 . HTTPError , e : <EOL> if e . code == <NUM_LIT> : <EOL> body = e . read ( ) <EOL> response_dict = dict ( x . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) for x in body . split ( "<STR_LIT:\n>" ) if x ) <EOL> raise ClientLoginError ( req . get_full_url ( ) , e . code , e . msg , <EOL> e . headers , response_dict ) <EOL> else : <EOL> raise <EOL> def _GetAppDashboardPublicIP ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> file_handle = open ( APPSCALE_DASHBOARD_IP_LOC ) <EOL> ip = file_handle . read ( ) <EOL> file_handle . close ( ) <EOL> except IOError : <EOL> logger . info ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> ip = "<STR_LIT:localhost>" <EOL> logger . info ( "<STR_LIT>" % ip ) <EOL> return ip <EOL> def _GetAuthCookie ( self , auth_token ) : <EOL> """<STR_LIT>""" <EOL> continue_location = "<STR_LIT>" % self . _GetAppDashboardPublicIP ( ) <EOL> args = { "<STR_LIT>" : continue_location , "<STR_LIT>" : auth_token } <EOL> login_path = os . environ . get ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> req = self . _CreateRequest ( "<STR_LIT>" % <EOL> ( self . scheme , self . host , login_path , <EOL> urllib . urlencode ( args ) ) ) <EOL> try : <EOL> response = self . opener . open ( req ) <EOL> except urllib2 . HTTPError , e : <EOL> response = e <EOL> if ( response . code != <NUM_LIT> or <EOL> response . info ( ) [ "<STR_LIT:location>" ] != continue_location ) : <EOL> raise urllib2 . HTTPError ( req . get_full_url ( ) , response . code , response . msg , <EOL> response . headers , response . fp ) <EOL> self . authenticated = True <EOL> def _Authenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> for unused_i in range ( self . auth_tries ) : <EOL> credentials = self . auth_function ( ) <EOL> try : <EOL> auth_token = self . _GetAuthToken ( credentials [ <NUM_LIT:0> ] , credentials [ <NUM_LIT:1> ] ) <EOL> if os . getenv ( "<STR_LIT>" , "<STR_LIT:0>" ) == "<STR_LIT:1>" : <EOL> return <EOL> except ClientLoginError , e : <EOL> if e . reason == "<STR_LIT>" : <EOL> if e . info == "<STR_LIT>" : <EOL> print >> sys . stderr , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> print >> sys . stderr , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> else : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> continue <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> break <EOL> if e . reason == "<STR_LIT>" : <EOL> print >> sys . stderr , "<STR_LIT>" <EOL> break <EOL> raise <EOL> self . _GetAuthCookie ( auth_token ) <EOL> return <EOL> def _AppScaleAuthenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . read_credentials : <EOL> credentials = self . auth_function ( ) <EOL> self . username = credentials [ <NUM_LIT:0> ] <EOL> self . password = credentials [ <NUM_LIT:1> ] <EOL> self . read_credentials = True <EOL> curl_command = "<STR_LIT>" <EOL> curl_command += "<STR_LIT>" % self . _GetAppScaleCookiePath ( ) <EOL> curl_command += "<STR_LIT>" % self . username <EOL> curl_command += "<STR_LIT>" % self . password <EOL> curl_command += "<STR_LIT>" <EOL> curl_command += "<STR_LIT>" <EOL> curl_command += "<STR_LIT:%s>" % self . _GetAppScaleDashboardAuthUrl ( ) <EOL> _ , _ = self . _RunCommand ( curl_command ) <EOL> self . _LoadAppScaleCookie ( ) <EOL> self . cookie_jar . load ( ) <EOL> def _GetAppServerName ( self ) : <EOL> """<STR_LIT>""" <EOL> tokens = self . appserver_url . split ( '<STR_LIT::>' ) <EOL> if len ( tokens ) == <NUM_LIT:0> : <EOL> return None <EOL> return tokens [ <NUM_LIT:0> ] <EOL> def _GetAppScaleDashboardHost ( self ) : <EOL> """<STR_LIT>""" <EOL> host = self . host . split ( '<STR_LIT::>' ) <EOL> if len ( host ) < <NUM_LIT:1> : <EOL> raise AppScaleAuthenticationError ( "<STR_LIT>" + "<STR_LIT>" % self . host ) <EOL> return host [ <NUM_LIT:0> ] <EOL> def _GetAppScaleDashboardAuthUrl ( self ) : <EOL> """<STR_LIT>""" <EOL> host = self . _GetAppScaleDashboardHost ( ) <EOL> scheme = self . scheme if self . scheme . endswith ( '<STR_LIT:s>' ) else self . scheme + '<STR_LIT:s>' <EOL> return "<STR_LIT>" % ( scheme , host , <EOL> self . _APPSCALE_AUTH_PAGE ) <EOL> def _RunCommand ( self , command ) : <EOL> """<STR_LIT>""" <EOL> cmd_status , cmd_output = commands . getstatusoutput ( command ) <EOL> if cmd_status != <NUM_LIT:0> : <EOL> raise BadCommandError ( cmd_status , command ) <EOL> return ( cmd_status , cmd_output ) <EOL> def _GetAppScaleCookiePath ( self ) : <EOL> """<STR_LIT>""" <EOL> app_server_name = None <EOL> if self . appserver_url is not None : <EOL> app_server_name = self . _GetAppServerName ( ) <EOL> else : <EOL> app_server_name = '<STR_LIT>' <EOL> return os . path . expanduser ( "<STR_LIT>" % ( HttpRpcServer . APPSCALE_COOKIE_FILE_PATH , app_server_name ) ) <EOL> def _LoadAppScaleCookie ( self ) : <EOL> """<STR_LIT>""" <EOL> self . cookie_jar . clear_session_cookies ( ) <EOL> self . cookie_jar . filename = self . _GetAppScaleCookiePath ( ) <EOL> if os . path . exists ( self . cookie_jar . filename ) : <EOL> try : <EOL> self . cookie_jar . load ( ) <EOL> logger . info ( "<STR_LIT>" % self . cookie_jar . filename ) <EOL> except ( OSError , IOError , cookielib . LoadError ) , e : <EOL> logger . debug ( "<STR_LIT>" % ( e . __class__ . __name__ , e ) ) <EOL> def _ExtractRemoteApiPath ( self , request_path ) : <EOL> """<STR_LIT>""" <EOL> remoteApiPath = request_path <EOL> if request_path . endswith ( "<STR_LIT>" ) : <EOL> return "<STR_LIT>" <EOL> return remoteApiPath <EOL> def _DevAppServerAuthenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> credentials = self . auth_function ( ) <EOL> value = dev_appserver_login . CreateCookieData ( credentials [ <NUM_LIT:0> ] , True ) <EOL> self . extra_headers [ "<STR_LIT>" ] = ( '<STR_LIT>' % value ) <EOL> def Send ( self , request_path , payload = "<STR_LIT>" , <EOL> content_type = "<STR_LIT>" , <EOL> timeout = None , <EOL> ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> auth_domain = '<STR_LIT>' <EOL> if '<STR_LIT>' in os . environ : <EOL> auth_domain = os . environ [ '<STR_LIT>' ] . lower ( ) <EOL> old_timeout = socket . getdefaulttimeout ( ) <EOL> socket . setdefaulttimeout ( timeout ) <EOL> try : <EOL> tries = <NUM_LIT:0> <EOL> while True : <EOL> tries += <NUM_LIT:1> <EOL> if auth_domain == "<STR_LIT>" : <EOL> self . _LoadAppScaleCookie ( ) <EOL> url = "<STR_LIT>" % ( self . scheme , self . host , request_path ) <EOL> if kwargs : <EOL> url += "<STR_LIT:?>" + urllib . urlencode ( sorted ( kwargs . items ( ) ) ) <EOL> req = self . _CreateRequest ( url = url , data = payload ) <EOL> req . add_header ( "<STR_LIT:Content-Type>" , content_type ) <EOL> req . add_header ( "<STR_LIT>" , "<STR_LIT:1>" ) <EOL> try : <EOL> logger . debug ( '<STR_LIT>' , <EOL> self . scheme . upper ( ) , <EOL> HttpRequestToString ( req , include_data = self . debug_data ) ) <EOL> f = self . opener . open ( req ) <EOL> response = f . read ( ) <EOL> f . close ( ) <EOL> return response <EOL> except urllib2 . HTTPError , e : <EOL> logger . debug ( "<STR_LIT>" , tries ) <EOL> if tries > self . rpc_tries : <EOL> raise AppScaleAuthenticationError ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> if e . code == <NUM_LIT> or e . code == <NUM_LIT> : <EOL> if auth_domain == '<STR_LIT>' : <EOL> self . _AppScaleAuthenticate ( ) <EOL> else : <EOL> self . _Authenticate ( ) <EOL> elif e . code >= <NUM_LIT> and e . code < <NUM_LIT> : <EOL> continue <EOL> elif e . code == <NUM_LIT> : <EOL> if tries >= <NUM_LIT:2> : <EOL> if auth_domain == '<STR_LIT>' : <EOL> logger . info ( "<STR_LIT>" % self . cookie_jar . filename ) <EOL> if os . path . isfile ( self . cookie_jar . filename ) : <EOL> os . remove ( self . cookie_jar . filename ) <EOL> raise AppScaleAuthenticationError ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> else : <EOL> raise <EOL> loc = e . info ( ) [ "<STR_LIT:location>" ] <EOL> logger . debug ( "<STR_LIT>" , loc ) <EOL> if loc . startswith ( "<STR_LIT>" ) : <EOL> self . _Authenticate ( ) <EOL> elif re . match ( r"<STR_LIT>" , <EOL> loc ) : <EOL> self . account_type = os . getenv ( "<STR_LIT>" , <EOL> "<STR_LIT>" ) <EOL> self . _Authenticate ( ) <EOL> elif auth_domain == '<STR_LIT>' : <EOL> loc = urlparse . urlparse ( loc ) <EOL> self . scheme = loc . scheme <EOL> self . host = loc . netloc <EOL> self . _AppScaleAuthenticate ( ) <EOL> elif loc . startswith ( "<STR_LIT>" % ( self . host , ) ) : <EOL> self . _DevAppServerAuthenticate ( ) <EOL> else : <EOL> raise <EOL> elif e . code == <NUM_LIT> : <EOL> if auth_domain == '<STR_LIT>' : <EOL> logger . info ( "<STR_LIT>" % self . cookie_jar . filename ) <EOL> os . remove ( self . cookie_jar . filename ) <EOL> raise AppScaleAuthenticationError ( "<STR_LIT>" + "<STR_LIT>" ) <EOL> else : <EOL> raise <EOL> else : <EOL> raise <EOL> finally : <EOL> socket . setdefaulttimeout ( old_timeout ) <EOL> class HttpRpcServer ( AbstractRpcServer ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_COOKIE_FILE_PATH = "<STR_LIT>" <EOL> APPSCALE_COOKIE_DIR = "<STR_LIT>" <EOL> APPSCALE_COOKIE_FILE_PATH = "<STR_LIT>" % APPSCALE_COOKIE_DIR <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> self . certpath = os . path . normpath ( os . path . join ( <EOL> os . path . dirname ( __file__ ) , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT:..>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' ) ) <EOL> self . cert_file_available = ( ( not kwargs . get ( "<STR_LIT>" , False ) ) <EOL> and os . path . exists ( self . certpath ) ) <EOL> super ( HttpRpcServer , self ) . __init__ ( * args , ** kwargs ) <EOL> def _CreateRequest ( self , url , data = None ) : <EOL> """<STR_LIT>""" <EOL> req = super ( HttpRpcServer , self ) . _CreateRequest ( url , data ) <EOL> if self . cert_file_available and fancy_urllib . can_validate_certs ( ) : <EOL> req . set_ssl_info ( ca_certs = self . certpath ) <EOL> return req <EOL> def _Authenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . cert_file_available and not fancy_urllib . can_validate_certs ( ) : <EOL> logger . warn ( """<STR_LIT>""" ) <EOL> super ( HttpRpcServer , self ) . _Authenticate ( ) <EOL> if self . cookie_jar . filename is not None and self . save_cookies : <EOL> logger . debug ( "<STR_LIT>" , <EOL> self . cookie_jar . filename ) <EOL> self . cookie_jar . save ( ) <EOL> def _AppScaleAuthenticate ( self ) : <EOL> """<STR_LIT>""" <EOL> super ( HttpRpcServer , self ) . _AppScaleAuthenticate ( ) <EOL> if self . cookie_jar . filename is not None and not self . save_cookies : <EOL> logger . info ( "<STR_LIT>" % self . cookie_jar . filename ) <EOL> os . remove ( self . cookie_jar . filename ) <EOL> def _GetOpener ( self ) : <EOL> """<STR_LIT>""" <EOL> opener = urllib2 . OpenerDirector ( ) <EOL> opener . add_handler ( fancy_urllib . FancyProxyHandler ( ) ) <EOL> opener . add_handler ( urllib2 . UnknownHandler ( ) ) <EOL> opener . add_handler ( urllib2 . HTTPHandler ( ) ) <EOL> opener . add_handler ( urllib2 . HTTPDefaultErrorHandler ( ) ) <EOL> opener . add_handler ( urllib2 . HTTPSHandler ( ) ) <EOL> opener . add_handler ( urllib2 . HTTPErrorProcessor ( ) ) <EOL> auth_domain = '<STR_LIT>' <EOL> if '<STR_LIT>' in os . environ : <EOL> auth_domain = os . environ [ '<STR_LIT>' ] . lower ( ) <EOL> if self . save_cookies : <EOL> if auth_domain == '<STR_LIT>' : <EOL> cookies_dir = os . path . expanduser ( HttpRpcServer . APPSCALE_COOKIE_DIR ) <EOL> if not os . path . exists ( cookies_dir ) : <EOL> os . mkdir ( cookies_dir ) <EOL> else : <EOL> self . cookie_jar . filename = os . path . expanduser ( <EOL> HttpRpcServer . DEFAULT_COOKIE_FILE_PATH ) <EOL> if os . path . exists ( self . cookie_jar . filename ) : <EOL> try : <EOL> self . cookie_jar . load ( ) <EOL> self . authenticated = True <EOL> logger . info ( "<STR_LIT>" , <EOL> self . cookie_jar . filename ) <EOL> except ( OSError , IOError , cookielib . LoadError ) , e : <EOL> logger . debug ( "<STR_LIT>" , <EOL> e . __class__ . __name__ , e ) <EOL> self . cookie_jar . filename = None <EOL> else : <EOL> try : <EOL> fd = os . open ( self . cookie_jar . filename , os . O_CREAT , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . close ( fd ) <EOL> except ( OSError , IOError ) , e : <EOL> logger . debug ( "<STR_LIT>" + "<STR_LIT>" % ( e . __class__ . __name__ , e ) ) <EOL> self . cookie_jar . filename = None <EOL> opener . add_handler ( urllib2 . HTTPCookieProcessor ( self . cookie_jar ) ) <EOL> return opener <EOL> class HttpRpcServerWithOAuth2Suggestion ( HttpRpcServer ) : <EOL> """<STR_LIT>""" <EOL> SUGGEST_OAUTH2 = True <EOL> class BadCommandError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , exit_status , command ) : <EOL> """<STR_LIT>""" <EOL> self . exit_status = exit_status <EOL> self . command = command <EOL> Exception . __init__ ( self , command ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( str ( self . command ) , <EOL> str ( self . exit_status ) ) <EOL> class AppScaleRedirectionError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , reason ) : <EOL> """<STR_LIT>""" <EOL> self . reason = reason <EOL> Exception . __init__ ( self , reason ) <EOL> def __str__ ( self ) : <EOL> return str ( self . reason ) <EOL> class AppScaleAuthenticationError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , reason ) : <EOL> """<STR_LIT>""" <EOL> self . reason = reason <EOL> Exception . __init__ ( self , reason ) <EOL> def __str__ ( self ) : <EOL> return str ( self . reason ) </s>
