
    x
he                     2   d dl mZmZmZmZ d dlZd dlmZmZm	Z	m
Z
mZ d dlmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZm Z m!Z!m"Z"m#Z# dZ$e$rd dl%Z%d dl&Z& e&jN                   e(d            Z)e)jU                  dd	
      Z+e+jY                  ddde(d       e+jY                  ddde(d       e+jY                  ddde(d       e+jY                  dde(d       e+jY                  ddde(d       e+jY                  ddde(d        G d  d!e!      Z-y)"    )absolute_importdivisionprint_functionunicode_literalsN)is_nullable_typeis_struct_typeis_union_typeis_void_typeunwrap_nullable)fmt_alloc_callfmt_camel_upper	fmt_classfmt_class_prefixfmt_funcfmt_func_argsfmt_func_args_declarationfmt_func_call
fmt_importfmt_property_strfmt_route_obj_classfmt_route_funcfmt_route_varfmt_routes_classfmt_signaturefmt_typefmt_var)base_file_commentcomment_prefixObjCBaseBackendstone_warningundocumentedFargparsezobjc-client-backendzGenerates a ObjC class with an object for each namespace, and in each namespace object, a method for each route. This class assumes that the obj_c_types backend was used with the same output directory.)progdescriptionz-mz--module-nameTzSThe name of the ObjC module to generate. Please exclude the {.h,.m} file extension.)requiredtypehelpz-cz--class-namez}The name of the ObjC class that contains an object for each namespace, and in each namespace object, a method for each route.z-tz--transport-client-namez:The name of the ObjC class that manages network API calls.z-wz--auth-typez(The auth type of the client to generate.)r&   r'   z-yz--client-argszFThe client-side route arguments to append to each route by style type.z-zz--style-to-requestz>The dict that maps a style type to a ObjC request object name.c                   v    e Zd ZdZeZi Zi Zd Zd Z	d Z
d Zd Zd Zd Zd	 Zd
 Zd Zd ZddZ	 ddZd Zy)ObjCBackendz<Generates ObjC client base that implements route interfaces.c           
      F   |j                   j                         D ]Q  }d| j                  |<   |j                  s|j                  D ]$  }| j	                  |      sd| j                  |<    Q S |j                   j                         D ]9  }|j                         D ]$  }t        |      | j                  |j                  <   & ; |j                   j                         D ]q  }|j                  s| j                  |   s!t        |j                  | j                  j                        t        |j                        dj                  | j                  j                        ddg}| j                  dj                  t        |j                  | j                  j                                    5  | j!                  t"               || j%                  | j'                  |      g       z   }| j)                  |       | j+                  |       d d d        | j                  dj                  t        |j                  | j                  j                                    5  | j!                  t,               | j/                  d       | j/                          | j/                  t1        d	             | j/                          d
g}|| j3                  | j'                  |dd            z   }| j5                  |       | j/                  dj                  | j                  j                               | j/                          | j7                  |       d d d        t | j                  dj                  | j                  j8                              5  | j;                  |       d d d        | j                  dj                  | j                  j8                              5  | j=                  |       d d d        y # 1 sw Y   xY w# 1 sw Y   )xY w# 1 sw Y   rxY w# 1 sw Y   y xY w)NFT
{}ProtocolDBStoneBaseDBRequestErrorszRoutes/{}.mzRoutes/{}.h!#import <Foundation/Foundation.h>DBTasksDBNilObject)include_route_argsinclude_route_deep_args@protocol {};zClient/{}.mzClient/{}.h)
namespacesvaluesnamespace_to_has_routesroutes_should_generate_routelinearize_data_typesr   obj_name_to_namespacenamer   args	auth_typer   formattransport_client_nameoutput_to_relative_pathemit_rawr    _get_imports_m_get_namespace_route_imports_generate_imports_m_generate_routes_mr   emitr   _get_imports_h_generate_imports_h_generate_routes_hmodule_name_generate_client_m_generate_client_h)selfapi	namespaceroute	data_typeimport_classesimports_classes_mimport_classes_hs           `/var/www/html/lionshead-backend/venv/lib/python3.12/site-packages/stone/backends/obj_c_client.pygeneratezObjCBackend.generatef   s~   ..0I6;D((3&--E2259BF44Y? . 1 ..0I&;;=	=M>**9>>: > 1
 ..0ID$@$@$K$Y^^TYY5H5HI'	7 ''		(G(GH!%" 11-2F2F()-)<)<>3? @ MM-0(6++ ==iH"N)N% ,,->?++I6@ 11-2F2F()-)<)<>3? @ MM"34IIABIIKIIj34IIK%($ )94;N;N99%/448 : :<; );$
 ,,-=>II'.. II;;=@ IIK++I6+@ @- 1Z ))$$TYY%:%:;=##C(= ))$$TYY%:%:;=##C(= =O@ @@ @.= == =s2   -AO1C0O>PP1O;	>P	PP c                    | j                  t               | j                  j                  g}||j                  j                         D cg c]G  }|j                  r9| j                  |   r*t        |j                  | j                  j                        I c}z  }|j                  dj                  | j                  j                               | j                  |       | j                  | j                  j                         5  t#        ddj                  | j                  j                        fg      }| j%                  d|d      5  | j'                  d       | j)                         5  | j'                  d       |j                  j                         D ]}  }|j                  s| j                  |   s d	}| j'                  |j                  t+        |j                        t        |j                  | j                  j                                      	 d
d
d
       d
d
d
       d
d
d
       y
c c}w # 1 sw Y   xY w# 1 sw Y   #xY w# 1 sw Y   y
xY w)zGenerates client base implementation file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace.r+   clientid<{}>initWithTransportClientinstancetypefuncr<   return_typeself = [super init];z_transportClient = client;z%_{}Routes = [[{} alloc] init:client];N)rA   r   r<   rJ   r4   r5   r7   r6   r   r;   r=   appendr>   r?   rD   block_m
class_namer   
block_funcrF   
block_initr   )rM   rN   rR   nsclient_argsrO   base_strings          rU   rK   zObjCBackend._generate_client_m   s    	'())//0nn++-
-yyT99"= RWWdii&9&9:-
 	

 			 ? ?@	B  0\\$))../3//$))"A"ABD EFK 2$ . ! 0 		01__&II:;%(^^%:%:%<	$++0L0LY0W*QK II + 2 2$+INN$;$4Y^^59YY5H5H%J!KL &= '0	 0/
& '&0 0	 0/sQ   
AH3AI"I-;H8)H89A H8I"I8I=II		IIc                    | j                  t               | j                  d       |j                  j	                         D cg c]G  }|j
                  r9| j                  |   r*t        |j                  | j                  j                        I }}|j                  d       |j                  d       | j                  |       | j                          | j                  d       | j                          | j                  dj                  | j                  j                               | j                          | j                  t               d}| j!                  |t               | j                  t               | j#                  | j                  j$                  dd	j                  | j                  j                        fg
      5  | j                          |j                  j	                         D ]  }|j
                  s| j                  |   s dj                  t'        |j                              }| j!                  |t               dj                  t'        |j                              }dj                  t        |j                  | j                  j                              }| j                  t)        ||             | j                           t+        dd	j                  | j                  j                        fg      }	d}| j!                  |j                  | j                  j$                        t               t-        d|	d      }
| j                  dj                  |
             | j                          ddd       | j                          | j                  d       yc c}w # 1 sw Y   0xY w)zGenerates client base header file. For each namespace, the client will
        have an object field that encapsulates each route in the particular namespace.r.   r-   r/   NS_ASSUME_NONNULL_BEGINr3   zBase client object that contains an instance field for each namespace, each of which contains references to all routes within that namespace. Fully-implemented API clients will inherit this class.prefixtransportClientrY   )	protectedz!Routes within the `{}` namespace.z{}Routes{} *proptyprX   z5Initializes the `{}` object with a networking client.rZ   r[   r\   {};NNS_ASSUME_NONNULL_END)rA   r    rF   r4   r5   r7   r6   r   r;   r<   r=   r`   rD   r>   r?   r   emit_wrapped_textblock_hrb   r   r   r   r   )rM   rN   re   rR   description_strrO   	class_docrp   rq   rf   init_signatures              rU   rL   zObjCBackend._generate_client_h   s    	m$		56 nn++-
-yyT99"= RWWdii&9&9:- 	 

 	/0i(  0				+,				/(()H)HIJ				.!U 	
 	~F		.!\\		$$&__TYY%D%DEG   IIK ^^224	##(D(DY(O C J J	/!1I**9^*L%,,WY^^-DED --(9L9LMOCII.DcBCIIK 5 4//$))"A"ABD EFK
 H ""&&tyy';';<% # ' +. *,N IIell>23IIKAD 					)*u
. s    AN/	:N4N4E1N44N=c                     |j                   j                  d      j                  d      D ]  }|j                         |k(  s y y)Nauth,TF)attrsgetsplitstrip)rM   rP   desired_auth_typer=   s       rU   _auth_type_in_routezObjCBackend._auth_type_in_route  s<    066s;I $55 <     c                 \    | j                  |d      xr | j                  j                  dk(  S )Nnoauthuser)r   r<   r=   rM   rP   s     rU   _route_is_special_noauth_casez)ObjCBackend._route_is_special_noauth_case  s*    ''x8ZTYY=P=PTZ=ZZr   c                 t    | j                  || j                  j                        xs | j                  |      S )N)r   r<   r=   r   r   s     rU   r8   z"ObjCBackend._should_generate_route  s4    ((		0C0CD :2259	;r   c                     | j                  t        |j                  | j                  j                              5  t        ddj                  | j                  j                        fg      }| j                  d|d      5  | j                  d       | j                         5  | j                  d       ddd       ddd       | j                          t        j                  | j                  j                        }|j                  D ]  }| j                  |      s|j                   j#                  d	      }t        j                  | j                  j$                        }||j'                         v r||   D ]  }t)        |      \  }}	||   }
|	d
   }|	d   D cg c]  }t)        |dd        }}t+        |j,                        rF| j/                  |j,                        r+| j1                  ||      \  }}| j3                  |||||
|       | j5                  ||      \  }}| j3                  |||||
|        4||   }
t+        |j,                        rF| j/                  |j,                        r+| j1                  ||      \  }}| j3                  |||g |
d       | j5                  ||      \  }}| j3                  |||g |
d        	 ddd       y# 1 sw Y   #xY w# 1 sw Y   (xY wc c}w # 1 sw Y   yxY w)zoGenerates implementation file for namespace object that has as methods
        all routes within the namespace.rX   rY   initr[   r\   r_   z_client = client;Nstyler       )ra   r   r;   r<   r=   r   r>   r?   rc   rF   rd   jsonloadsstyle_to_requestr7   r8   r|   r}   rf   keystupler   arg_data_type_struct_has_defaults_get_default_route_args_generate_route_m_get_route_args)rM   rO   	init_argsr   rP   
route_typerf   	args_datatask_type_keytype_data_dicttask_type_namefunc_suffix	type_data
extra_args
route_args_s                   rU   rE   zObjCBackend._generate_routes_m  s    \\ 1D1DEG1(//$))*I*IJ4L 3M NI i^ ! M		01__&II12 'M
 IIK#zz$))*D*DE"))2259"[[__W5
"jj)>)>?!1!1!33%0%<	8=i8H5~)9-)H&4Q&7 .<A->&->	 ")CR.1-> # &
 +5+>+>? $ 9 9%:M:M N,0,H,H )5-2MJ 225)3=z3A;P )-(<(<Y(N
A..ui/9>/:<' &=. &6j%AN&u':':; 55e6I6IJ(,(D(D%u).
A..ui/1>2G %)$8$8E$JMJ**5)Z+92?Q *G G '&M M*&5G GsJ   AK4 "K""K4K"<C K4K/
1DK4KK""K,	'K44K=c                    t        |      }ddt        |j                        sdndfg}|D ],  \  }	}
}|j                  |	|f       |j                  |	|
f       . | j	                  dj                  t        |      |      t        |      dj                  |            5  | j                  dj                  t        |j                        t        |j                  |                   t        |j                        rR| j                  dj                  t        |j                        t        |j                  j                                     nt        |j                        st        t!        t        |j                        	      | j#                  |      t%        |D cg c]  }|d
   |d
   f c}            }| j                  dj                  t        |j                        |             t        ddj                  t'        |j(                  j+                  d                  t%        |            }| j                  dj                  |             ddd       | j                          yc c}w # 1 sw Y   xY w)z:Generates route method implementation for the given route.)rP   rP   argnil{}{}rn   r\   zDBRoute *route = {}.{};z{} *arg = {};)callerr   )r   calleer<   zself.clientz	request{}r   z
return {};N)listr
   r   r`   rc   r>   r   r   rF   r   r;   r   r	   r   r   r   r   _cstor_name_from_fields_namesr   r   r|   r}   )rM   rP   rO   r   r   r   r   	user_argstransport_argsr;   valuerq   f	init_callrequest_calls                  rU   r   zObjCBackend._generate_route_mX  s%    $	 e.A.A!BEN

 !+D%dC[)!!4-0 !+ __]]>%#8+F.y9"MM.9  ; II/66#INN3inne46 7 U001		/00$U%8%89E//4457 8 "%"5"56))/0C0CDF==jI&j'Ij1qtj'IJ	L	
 		/00$U%8%899F G($"))#EKKOOG$<=?">2	4L
 IIl)),781;2 			 (J!; ;s    DI7 I21B(I72I77J c                    | j                  t               | j                  dj                  t	        |j
                              t               | j                  t               | j                          | j                  d       | j                          | j                  t        |j
                  | j                  j                              5  d}| j                  |t               | j                  t        ddj                  | j                  j                                     | j                          t        ddj                  | j                  j                        fg      }t        d|d	
      }d}| j                  |j                  t        |j
                  | j                  j                              t               | j                  dj                  |             | j                          t        j                  | j                  j                         }|j"                  D ]  }| j%                  |      s|j&                  j)                  d      }t        j                  | j                  j*                        }||j-                         v r||   D ]  }	t/        |	      \  }
}||
   }|d   }|d   D cg c]  }t/        |dd        }}|d   D cg c]  }|d   |d   f }}t1        |j2                        rL| j5                  |j2                        r1| j7                  ||d      \  }}| j9                  ||||||z   ||       | j;                  ||d      \  }}| j9                  ||||||z   ||        Z||   }t1        |j2                        rI| j5                  |j2                        r.| j7                  ||d      \  }}| j9                  |||g ||d       | j;                  ||d      \  }}| j9                  |||g ||d        	 ddd       | j                          | j                  d       | j                          yc c}w c c}w # 1 sw Y   ExY w)zgGenerates header file for namespace object that has as methods
        all routes within the namespace.zRoutes for the `{}` namespacerj   ri   zRAn instance of the networking client that each route will use to submit a request.rX   rY   ro   r   r[   r\   zIInitializes the `{}` namespace container object with a networking client.rr   r   r   r   Nr   Ttagr   rs   )rF   r   rt   r>   r   r;   ru   r   r<   r=   r   r?   r   r   r   r   r   r7   r8   r|   r}   rf   r   r   r   r   r   r   _generate_route_signaturer   )rM   rO   rv   routes_obj_argsrx   r   rP   r   rf   r   r   r   r   r   r   r   
extra_docsr   doc_lists                      rU   rI   zObjCBackend._generate_routes_h  sN    			.!+229Y^^3LM! 	 	# 			.!				+,		\\ 1D1DEG6  ""?>"JII ! 		779:;
 IIK7//$))"A"ABD EFO +$*,N
,  ""&&$Y^^TYY5H5HIK% # ' IIell>23IIK#zz$))*D*DE"))2259"[[__W5
"jj)>)>?!1!1!33%0%<	8=i8H5~)9-)H&4Q&7 .<A->&->	 ")CR.1-> # &
 8Fa7H&J7H) (1|Yr]&C7H # &J +5+>+>? $ 9 9%:M:M N373O3O )5d 4P 4<0J :: %y*j (: 5~ +-
 04/C/C%u$ 0D 08,
H66!9j*$z1>;P/ &=6 &6j%AN&u':':; 55e6I6IJ/3/K/K%u$ 0L 08,
H66!9j"h*B0 ,0+?+?!5d ,@ ,4(J225)3=r83A2G] *CGd 					)*		M&&JeG Gs,   G0Q>Q
	QQ
-D,Q
QQ'c                    |D ]  \  }}	}
|j                  ||
f        |j                  rdnd}dj                  t        |      |      }| j	                  t
               |j                  r'| j                  |j                  | j                        }ndj                  |      }| j                  ||z   t
        d       | j	                  t
               |D ]5  \  }}| j                  dj                  ||r|nt              t
        d       7 | j	                  t
               d}|j                  t        |j                  d	d
      t        |j                  d	d
            }| j                  |t
        d       | j	                  t
               t        |j                        st        |j                        nd}t        |j                        st        |j                        nd}dj                  |||      }| j                  |      }t!        |t#        |      dj                  |            }| j	                  dj                  ||             | j	                          y)z5Generates route method signature for the given route.zDEPRECATED: r   r   zThe {} routex   )rk   widthz@param {} {}zt@return Through the response callback, the caller will receive a `{}` object on success or a `{}` object on failure.FT)r   no_ptrzDBNilObject *z{}<{}, {}> *z{}r\   z{}{};N)r`   
deprecatedr>   r   rF   r   docprocess_doc_docfrt   r!   r   result_data_typeerror_data_typer
   _get_deprecation_warningr   r   )rM   rP   rO   r   r   r   r   r   r;   r   rq   r   	func_name	route_docr   outputresult_type_strerror_type_strr^   route_signatures                       rU   r   z%ObjCBackend._generate_route_signature  s    'LD!StSk* ' (-'7'7^R
MM."7E			.!99((DJJ?I&--i8I"> 	 	F		.!!ID#""%%d3CLI% #  "
 			.!L 	 U++tDU**dCE 	vnCH		.!BN""C$(5#9#9:)8 	@L!!A#%"7"78(7 	 %++NO,:< 2259
'*:6K02 			'..*=>		r   c                    d}|j                   r|dj                  t        |            }|j                   j                  r;|dj                  t	        |j                   j                  j
                              z  }dj                  |      }|S )z<Returns a deprecation tag / message, if route is deprecated.r   z{} is deprecated.z Use {}.z __deprecated_msg("{}"))r   r>   r   byr   r;   )rM   rP   resultmsgs       rU   r   z$ObjCBackend._get_deprecation_warning  su    %,,^E-BCC""z((1A1A1D1D1I1I)JKK.55c:Fr   c           	      (   t        |j                        \  }}t        |      rg }|j                  D ]H  }|j	                  t        |j                        t        |j                  ||j                        f       J |j                  D cg c]I  }|j                  r;t        |j                        | j                  |j                  | j                        fK }	}||	fS t        |      rt        |j                        t        |j                  |      fg}t        |j                        |j                  r&| j                  |j                  | j                        n#dj                  t!        |j                              fg}	||	fS g }g }	||	fS c c}w )zfReturns a list of name / value string pairs representing the arguments for
        a particular route.)r   has_defaultr   zThe {} union)r   r   r   
all_fieldsr`   r   r;   r   rQ   r   fieldsr   r   r   r	   r>   r   
rM   rO   rP   r   rQ   r   arg_listfieldr   r   s
             rU   r   zObjCBackend._get_route_args'  s    'u':':;	1)$H"--!4hOO%:K:K7M !N O .
 "+!1!1<!1AQUU !$*:*:155$***MN!1  <  !! 9% 0(##3. / 0H !0#,==   JJ #**i ! "H !! HH!!!<s   AFc                 J   t        |j                        \  }}t        |      rg }|j                  D ]`  }|j                  rt        |j                        r&|j                  t        |j                        t        |j                  |      f       b |j                  D cg c]j  }|j                  r\|j                  sPt        |j                        s;t        |j                        | j                  |j                  | j                        fl }	}||	fS g }g }	||	fS c c}w )znReturns a list of name / value string pairs representing the default arguments for
        a particular route.r   )r   r   r   r   r   r   rQ   r`   r   r;   r   r   r   r   r   r   s
             rU   r   z#ObjCBackend._get_default_route_argsC  s    'u':':;	1)$H"--((1A2)OOWUZZ%8(S;2 %3 4 . #,"2"2<"2QEE!---akk: "!&&/4+;+;AEE4::+NO"2  < !! HH!!<s   #A/D c                     |dk(  rdj                  t        |            S |dk(  rKd|v r<|j                  d      \  }}dj                  t        |      | j                  |         S t        |      S |dv r|S |S )NrP   z`{}`r   .z`{}` in `{}`)r&   vallink)r>   r   r~   r   r:   )rM   r   r   cls_namer   s        rU   r   zObjCBackend._docf]  s    '>==#//G^cz"%))C.%&--END$>$>x$HJ K s|#++JJr   N)F)__name__
__module____qualname____doc___cmdline_parsercmdline_parserr:   r6   rV   rK   rL   r   r   r8   rE   r   rI   r   r   r   r   r    r   rU   r)   r)   _   sn    F$N A)F"LHA+F[;9?v'RaF7r"@ 	"4r   r)   ).
__future__r   r   r   r   r   stone.irr   r   r	   r
   r   stone.backends.obj_c_helpersr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   stone.backends.obj_cr   r   r   r    r!   _MYPYtyping	importlibimport_modulestrr"   ArgumentParserr   add_argumentr)   r   r   rU   <module>r      sn   R R      $  	 "9""3z?3))		G * K   		     		A  C   		E  I   		3	  7
   		Q  U   		I  MK/ Kr   