+
    i                      a  0 t $ R t^ RIHt ^ RIt^ RIt^ RIHtHtH	t	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHt RtR]R	&    ^ RIt]f   ]M]P.                  P0                  t ! R
 R]4      tR R lt ! R R]P8                  4      t ! R R]4      t ! R R]4      tRs R]R&   R R lt!R R lt"R R lt#R#   ] d   t]tRt RtALRtAii ; i)z1Module that holds a global gspread.client.Client.)annotationsN)AnyCallableMappingSequence)credentials)
html_utils)ipython_env)	sheets_idzException | None_gspread_import_errorc                      ] tR t^*tRtR# )SpreadsheetNotFoundError N)__name__
__module____qualname____firstlineno____static_attributes__r       ~/Users/igloo/.openclaw/workspace/scratch/fb_ad_env/lib/python3.14/site-packages/google/generativeai/notebook/gspread_client.pyr   r   *   s    r   r   c                   V ^8  d   QhRR/# )   return	Exceptionr   )formats   "r   __annotate__r   .   s     ` `9 `r   c                 >    \        R P                  \        4      4      # )z&"gspread" module not imported, got: {})RuntimeErrorr   r   r   r   r   _get_import_errorr   .   s    @GGH]^__r   c                      ] tR t^2tRt]P                  R R l4       t]P                  R R l4       t]P                  R R l4       t	Rt
R	# )
GSpreadClientzlWrapper around gspread.client.Client.

This adds a layer of indirection for us to inject mocks for testing.
c                    V ^8  d   QhRRRR/# r   sidsheets_id.SheetsIdentifierr   Noner   )r   s   "r   r   GSpreadClient.__annotate__9   s      6 4 r   c                    R# )zValidates that `name` is the name of a Google Sheets document.

Raises an exception if false.

Args:
  sid: The identifier for the document.
Nr   selfr#   s   &&r   validateGSpreadClient.validate8       r   c               $    V ^8  d   QhRRRRRR/# r   r#   r$   worksheet_idintr   z6tuple[Sequence[Mapping[str, str]], Callable[[], None]]r   )r   s   "r   r   r&   C   s.     A A'A A 
@	Ar   c                    R# )z2Returns all records for a Google Sheets worksheet.Nr   r)   r#   r/   s   &&&r   get_all_recordsGSpreadClient.get_all_recordsB   r,   r   c               $    V ^8  d   QhRRRRRR/# r   r#   r$   rowszSequence[Sequence[Any]]r   r%   r   )r   s   "r   r   r&   K   s-     O O'O &O 
	Or   c                    R# )z@Writes results to a new worksheet to the Google Sheets document.Nr   r)   r#   r7   s   &&&r   write_recordsGSpreadClient.write_recordsJ   r,   r   r   N)r   r   r   r   __doc__abcabstractmethodr*   r3   r:   r   r   r   r   r    r    2   sY    
 	  	A A 	O Or   r    c                  V    ] tR t^StRtR R ltR R ltR R ltR R	 ltR
 R lt	Rt
R# )GSpreadClientImplz)Concrete implementation of GSpreadClient.c                    V ^8  d   QhRRRR/# )r   clientr   envipython_env.IPythonEnv | Noner   )r   s   "r   r   GSpreadClientImpl.__annotate__V   s     	  	 s 	 )F 	 r   c                    Wn         W n        R# )zConstructor.

Args:
  client: Instance of gspread.client.Client.
  env: Optional instance of IPythonEnv. This is used to display messages
    such as the URL of the output Worksheet.
N_client_ipython_env)r)   rB   rC   s   &&&r   __init__GSpreadClientImpl.__init__V   s     r   c                   V ^8  d   QhRR/# )r   r#   r$   r   )r   s   "r   r   rE   a   s     M M3 Mr   c                    VP                  4       '       d*   V P                  P                  VP                  4       4      # VP                  4       '       d3   V P                  P	                  \        VP                  4       4      4      # VP                  4       '       d3   V P                  P                  \        VP                  4       4      4      #  \        R4      h  \         d!   p\        RP                  T4      4      ThRp?ii ; i)a  Opens a Sheets document from `sid`.

Args:
  sid: The identifier for the Sheets document.

Raises:
  SpreadsheetNotFoundError: If the Sheets document cannot be found or
    cannot be opened.

Returns:
  A gspread.Worksheet instance representing the worksheet referred to by
  `sid`.
zUnable to find Sheets with {}Nz"Invalid sheets_id.SheetsIdentifier)namerH   openkeyopen_by_keystrurlopen_by_urlGSpreadExceptionr   r   )r)   r#   excs   && r   _openGSpreadClientImpl._opena   s    	axxzz||((44wwyy||//CGGI??wwyy||//CGGI??  ''KLL   	a*+J+Q+QRU+VW]``	as4   C (C C 1C 	C 1C D(DDc                    V ^8  d   QhRRRR/# r"   r   )r   s   "r   r   rE   z   s      6 4 r   c                	(    V P                  V4       R # N)rW   r(   s   &&r   r*   GSpreadClientImpl.validatez   s    

3r   c               $    V ^8  d   QhRRRRRR/# r.   r   )r   s   "r   r   rE   }   s)     8 8'8 8 
@	8r   c                	   aaa V P                  V4      oSP                  V4      oV P                  e   V P                  oVVV3R lpMVV3R lpSP                  4       V3# )Nc                    < S P                  R P                  \        P                  ! \        P
                  ! SP                  4      RP                  SP                  SP                  4      R7      4      4       R# )z Reading inputs from worksheet {}{} in {}rS   textN)display_htmlr   r   get_anchor_tagr
   	SheetsURLrS   title)rC   sheet	worksheets   r   _display_fn6GSpreadClientImpl.get_all_records.<locals>._display_fn   sW      6=="11 ) 3 3IMM B!+!2!29??EKK!Pr   c                 f   < \        R P                  SP                  S P                  4      4       R# )z&Reading inputs from worksheet {} in {}N)printr   rf   )rg   rh   s   r   ri   rj      s$    >EEiooW\WbWbcdr   )rW   get_worksheetrI   r3   )r)   r#   r/   ri   rC   rg   rh   s   &&& @@@r   r3   !GSpreadClientImpl.get_all_records}   s_    
 

3''5	(##C e ((*K77r   c               $    V ^8  d   QhRRRRRR/# r6   r   )r   s   "r   r   rE      s-     d d'd &d 
	dr   c                	H   V P                  V4      p\        P                  P                  4       pR VR RVR R2pVP                  V^^R7      pVP	                  VR7       V P
                  e   V P
                  P                  RP                  \        P                  ! \        P                  ! VP                  4      R	P                  VP                  VP                  4      R
7      4      4       R# \        RP                  VP                  VP                  4      4       R# )zResults z%Y_%m_%dz (z%s))rf   r7   cols)valuesNz#Results written to new worksheet {}r`   ra   z)Results written to new worksheet {} in {})rW   datetimenowadd_worksheetappend_rowsrI   rc   r   r   rd   r
   re   rS   rf   rl   )r)   r#   r7   rg   current_datetimerf   rh   s   &&&    r   r:   GSpreadClientImpl.write_records   s    
 

3
 $,,002+H5R8H7LAN ''e!!'D	T*(**5<<--%//	>'..yL =DDY__V[VaVabcr   rG   N)r   r   r   r   r<   rJ   rW   r*   r3   r:   r   r   r   r   r@   r@   S   s&    3	 M288d dr   r@   c                  >    ] tR t^tRtR R ltR R ltR R ltRtR	# )
NullGSpreadClientzNull-object implementation of GSpreadClient.

This class raises an error if any of its methods are called. It is used when
the gspread library is not available.
c                    V ^8  d   QhRRRR/# r"   r   )r   s   "r   r   NullGSpreadClient.__annotate__   s     " "6 "4 "r   c                	    \        4       hr[   r   r(   s   &&r   r*   NullGSpreadClient.validate   s    !!r   c               $    V ^8  d   QhRRRRRR/# r.   r   )r   s   "r   r   r}      s)     " "'" " 
@	"r   c                	    \        4       hr[   r   r2   s   &&&r   r3   !NullGSpreadClient.get_all_records       
  !!r   c               $    V ^8  d   QhRRRRRR/# r6   r   )r   s   "r   r   r}      s(     " "'" &" 
	"r   c                	    \        4       hr[   r   r9   s   &&&r   r:   NullGSpreadClient.write_records   r   r   r   N)	r   r   r   r   r<   r*   r3   r:   r   r   r   r   r{   r{      s    """ "r   r{   zGSpreadClient | None_gspread_clientc               $    V ^8  d   QhRRRRRR/# )r   credszcredentials.CredentialsrC   rD   r   r%   r   )r   s   "r   r   r      s$     . ., .3P .UY .r   c                r    \         e%   \         P                  ! V 4      p\        W!R7      sR# \	        4       sR# )z Sets up credential for gspreads.N)rB   rC   )gspread	authorizer@   r   r{   )r   rC   rB   s   && r   r   r      s,     ""5)+6C+-r   c                   V ^8  d   QhRR/# )r   r   r    r   )r   s   "r   r   r      s      M r   c                 <    \         '       g   \        R 4      h\         # )zMust call authorize() first)r   r   r   r   r   
get_clientr      s    ?899r   c                    V ^8  d   QhRRRR/# )r   rB   r    r   r%   r   )r   s   "r   r   r      s       $ r   c                
    V s R# )z(Overrides the global client for testing.N)r   )rB   s   &r   testonly_set_clientr      s	     Or   )$__conditional_annotations__r<   
__future__r   r=   rt   typingr   r   r   r   google.authr   google.generativeai.notebookr   r	   r
   r   __annotations__r   ImportErrorer   
exceptionsrU   r   r   r   ABCr    r@   r{   r   r   r   r   )r   s   @r   <module>r      s    8 " 
  3 3 # 3 4 2
 +/ ' . !(9W5G5G5X5X 	| 	`OCGG OBbd bdJ" "4 )-% ,.I  Gs   B8 8C?CC