
    &                     F   S r SSKrSSKrSSKrSSKrSSKrSSKrSSKrSSK	J
r
  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSKJr  SS	KJr  SS
KJr  SSKJr  \R<                  rSr   SS\ S\
\!   S\ S\"S\ 4
S jjr#  SS\$S\ S\ S\!4S jjr%S\ 4S jr&g)z+BQ CLI helper functions for error handling.    N)Optional)app)flags)
exceptions)bq_to_gcloud_config_classes)bq_error)bq_gcloud_utils)
bq_logging)
stringutilaz  In order to get started, please visit the Google APIs Console to create a project and agree to our Terms of Service:
	https://console.cloud.google.com/

For detailed sign-up instructions, please see our Getting Started Guide:
	https://cloud.google.com/bigquery/docs/quickstarts/quickstart-command-line

Once you have completed the sign-up process, please try your command again.textlengthindentdrop_whitespacereturnc                    Uc  [         R                  " 5       nUc  Sn[        U5      U:  a  [        S5      eU R	                  S5      n / n[
        R                  " UUUUS9nS U R                  5        5        H[  nU(       a@  UR                  UR                  U5       Vs/ s H  owR                  5       PM     sn5        MJ  UR                  S5        M]     SR                  U5      $ s  snf )a8  Wraps a given text to a maximum line length and returns it.

It turns lines that only contain whitespace into empty lines, keeps new lines,
and expands tabs using 4 spaces.

Args:
  text: str, text to wrap.
  length: int, maximum length of a line, includes indentation. If this is None
    then use get_help_width()
  indent: str, indent for all but first line.
  drop_whitespace: bool, whether to drop whitespace from the text after
    wrapping.

Returns:
  str, the wrapped text.

Raises:
  ValueError: Raised if indent or firstline_indent not shorter than length.
 zLength of indent exceeds length   )widthinitial_indentsubsequent_indentr   c              3   @   #    U  H  oR                  5       v   M     g 7f)N)rstrip).0ps     #platform/bq/utils/bq_error_utils.py	<genexpr>*text_wrap_error_message.<locals>.<genexpr>[   s     :(91HHJJ(9s   
)r   get_help_widthlen
ValueError
expandtabstextwrapTextWrapper
splitlinesextendwrapr   appendjoin)r   r   r   r   resultwrapper	paragraphlines           r   text_wrap_error_messager.   +   s    4 ^!!#F^F[F
6
77		$&  %	' ;(9:immw||I/FG/Ft[[]/FGHmmB	 ; 
6	 Hs   !C)
errnamemessage_prefixc           	         [         R                  " [        R                  5        [        R
                  " [        5      n[        U [        5      (       a  UR                  SU S9  U R                  $ / nSn[        R                  " 5       u  pgnSR                  [        R                  " XgU5      5      n	[!        5       n
["        R$                  " 5       n[&        R(                  " S5      U[*        R,                  " ["        R.                  5      [        R0                   Vs/ s H  n[*        R,                  " U5      PM     sn[2        R4                  " S[2        R6                  " 5       5      [*        R,                  " U	5      4-  n[8        R:                  " S[8        R<                  5        [         R>                  " U 5      n[        U [@        RB                  [@        RD                  45      (       a  URG                  SU< S	U< 35        S
nGO[        U [@        RH                  5      (       a4  URG                  [K        U 5      S-   5        URG                  [L        5        GO4[        U [@        RN                  5      (       a  URG                  SU< 35        GO[        U [@        RP                  5      (       a"  SU;   a  URG                  SU< S	U< S35        GO[        U [@        RR                  5      (       a:  [        U [@        RT                  5      (       d  URG                  SU< S	U< 35        GOd[        U [V        RX                  [@        RZ                  45      (       a  URG                  U5        GO"[        U [\        R^                  5      (       a  URG                  U5        GO[        U [`        5      (       d  [        U [@        Rb                  5      (       a  URG                  SU< 35        GO[        U [d        Rf                  5      (       a  URG                  SU< 35        GOo[        U [h        5      (       a  URG                  S5        GOG[        U [@        RT                  5      (       a  SU< S	U< S3nO[        U [j        Rl                  Rf                  5      (       a  SnO[        U [n        Rp                  5      (       a  SnSU-  nOs[        U [r        Rl                  Rt                  5      (       dH  [        U [v        Rx                  Rf                  5      (       d  [        U [z        R|                  5      (       a  SnUS-   U
-   nSnU(       a  [d        R~                  " U5      n[        U5        [        U5        URG                  SU< S	U< 35        SR                  U5      nSnU(       a(  SU;   a  [        U5      nO[d        R~                  " U5      nUR                  UU S9  [        U5        U$ s  snf )z@Translate an error message into some printing and a return code.z$An error has caused the tool to exit)exc_info   r   a       ========================================
     == Platform ==
       %s
     == bq version ==
       %s
     == Command line ==
       %s
     == UTC timestamp ==
       %s
     == Error trace ==
     %s
     ========================================
     z%Y-%m-%d %H:%M:%SstrictzBigQuery error in z operation:    r   zError in query string: z9API requires a quota project, which is not set by defaultz&Bigquery service returned an error in z.

Please make sure you have the correct quota project ID set through --quota_project_id or gcloud config set billing/quota_project. zInvalid input: zError parsing command: z.Bigquery service returned an invalid reply in z.

Please make sure you are using the latest version of the bq tool and try again. If this problem persists, you may have encountered a bug in the bigquery client.aX  Authorization error. This may be a network connection problem, so please try again. If this problem persists, the credentials may be corrupt. Try deleting and re-creating your credentials. You can delete your credentials using "bq init --delete_credentials".

If this problem still occurs, you may have encountered a bug in the bigquery client.zservice accounta&  Authorization error. If you used %s credentials, the server likely returned an Unauthorized response. Verify that you are using the correct account with the correct permissions to access the service endpoint.

If this problem still occurs, you may have encountered a bug in the bigquery client.zNetwork connection problem encountered, please try again.

If this problem persists, you may have encountered a bug in the bigquery client. TzUnexpected exception in 	Traceback)Br
   ConfigurePythonLoggerFLAGSapiloglogging	getLogger__name__
isinstance
SystemExit	exceptioncodesysr3   r)   	tracebackformat_exception_generate_contact_us_messagebq_utilsGetPlatformStringr#   dedentr   
ensure_strVERSION_NUMBERargvtimestrftimegmtimecodecsregister_errorreplace_errorsEncodeForPrintingr   BigqueryNotFoundErrorBigqueryDuplicateErrorr(   BigqueryTermsOfServiceErrorstr_BIGQUERY_TOS_MESSAGEBigqueryInvalidQueryErrorBigqueryServiceErrorBigqueryErrorBigqueryInterfaceErrorr   
UsageErrorBigqueryTypeErrorr   !BigqueryGcloudDelegationUserErrorSyntaxErrorBigquerySchemaErrorr   ErrorKeyboardInterruptoauth2client_4_0clientgoogle_auth_exceptionsRefreshErrorhttpHTTPExceptiongoogleapiclienterrorshttplib2HttpLib2Error	text_wrapprintr.   )r/   r0   r1   loggerresponseretcodeetypevaluetbtracecontact_us_msgplatform_stritemerror_detailsmessagecredential_typewrap_error_messageresponse_messages                     r   process_errorr   e   s}    ""5<<0X&&Z  
;cJ88O('\\^%
''),,U2>
?%/1.++-,oo 	 
 


 7 7
83688
<84:  &8
<
--+T[[]
;



&	 0 	&"7"78((-'	H**H,K,KL  OOD'JKG#x;;<<OOCHtO$OO)*#x99::OO7<=h3344
E
POO
 		 #x--..z	8**8 8 OOD'JK#(B(BCDDOOG	'II  OOG#{##z	8''( ( OO745#u{{##OO7<=#())OOB
 #x6677 !%g/  
C)0066	7	7$  
C/<<	=	=)o$ (78  	31122c?117788c81122  s"^3G(g	'N	-OO6:GD YYx(&&01AB)9:#c2	.e =s    W-
c                      Sn  [         R                  " 5       nUR                  S5      nSU;   a+  SUS   ;   a"  U R                  SS5      R                  SS5      n U $ ! [         a     U $ f = f)	z!Generates the Contact Us message.a  Please file a bug report in our public issue tracker:
  https://issuetracker.google.com/issues/new?component=187149&template=0
Please include a brief description of the steps that led to this issue, as well as any rows that can be made public from the following information: 

coreaccountz@google.compublicinternalzFhttps://issuetracker.google.com/issues/new?component=187149&template=0z3http://b/issues/new?component=60322&template=178900)r	   load_configgetreplace	Exception)rw   gcloud_configsgcloud_core_propertiess      r   rF   rF     s    ( 	$002N+//7++3I>>%--h
CKK
R
?n 
	 
 				s   AA 
A+*A+)Nr   F)unknownz/You have encountered a bug in the BigQuery CLI.)'__doc__rP   http.clientrh   r<   rC   r#   rM   rD   typingr   abslr   r   google.authr   rf   rj   rl   oauth2client_4_0.clientrd   rG   gcloud_wrapperr   utilsr   r	   r
   pyglibr   r:   rX   rW   intboolr.   BaseExceptionr   rF        r   <module>r      s    1    
       <     6  !   	  !!	7
7SM7 7 	7
 	7x KY	Y
Y Y 		Yxc r   