
    PJ`6                        d Z ddlmZmZmZmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddlZddlZddlmZ ddlmZmZ ddlmZ ddlmZ d	ZerddlZddlZ ej6                   ed
            ZdZdZejA                  e      Z!e!jE                  dddd       ddjG                  e      z   Z$e!jE                  dejJ                  e$       e!jE                  dejJ                  d       e!jE                  ddejJ                  d       e!jE                  ddd       e!jE                  d d!ejJ                  d"       e!jE                  d#d$ejJ                  d%       e!jE                  d&d'd(eg d)*       e!jM                         Z'e'jE                  d+d,d(eg d-*       e'jE                  d.d/d(eg d0*       d1 Z(e)d2k(  r e(       Z*yy)3z(
A command-line interface for StoneAPI.
    )absolute_importdivisionprint_functionunicode_literalsN   )parse_route_attr_filter)BackendExceptionCompiler)InvalidSpec)specs_to_irFargparse)obj_c_clientobj_c_typesobj_c_tests	js_clientjs_types
tsd_client	tsd_typespython_typespython_type_stubspython_clientswift_typesswift_clienta*  Write your APIs in Stone. Use backends to translate your specification into a target language or format. The following describes arguments to the Stone CLI. To specify arguments that are specific to a backend, add "--" followed by arguments. For example, "stone python_client . example.spec -- -h".)descriptionz-vz	--verbosecountzPrint debugging statements.)actionhelpzEither the name of a built-in backend or the path to a backend module. Paths to backend modules must end with a .stoneg.py extension. The following backends are built-in: z, backend)typer   outputz&The folder to save generated files to.spec*zPath to API specifications. Each must have a .stone extension. If omitted or set to "-", the spec is read from stdin. Multiple namespaces can be provided over stdin by concatenating multiple specs together.)nargsr   r   z--clean-build
store_truez5The path to the template SDK for the target language.z-fz--filter-by-route-attra  Removes routes that do not match the expression. The expression must specify a route attribute on the left-hand side and a value on the right-hand side. Use quotes for strings and bytes. The only supported operators are "=" and "!=". For example, if "hide" is a route attribute, we can use this filter: "hide!=true". You can combine multiple expressions with "and"/"or" and use parentheses to enforce precedence.z-rz--route-whitelist-filtera+  Restrict datatype generation to only the routes specified in the whitelist and their dependencies. Input should be a file containing a JSON dict with the following form: {"route_whitelist": {}, "datatype_whitelist": {}} where each object maps namespaces to lists of routes or datatypes to whitelist.z-az--attributeappendzRoute attributes that the backend will have access to and presumably expose in generated code. Use ":all" to select all attributes defined in stone_cfg.Route. Note that you can filter (-f) by attributes that are not listed here.)r   r   defaultr   z-wz--whitelist-namespace-routeszIIf set, backends will only see the specified namespaces as having routes.z-bz--blacklist-namespace-routeszFIf set, backends will not see any routes for the specified namespaces.c                     dt         j                  v rdt         j                  dt         j                  j                  d       } t         j                  t         j                  j                  d      dz   d }nt         j                  dd } g }t        j	                  |       }d}|j
                  t        j                  }nr|j
                  dk(  rt        j                  }nR|j
                  dk(  rt        j                  }d}n0t        dt         j                         t        j                  d       t        j                  	       |j                  rl|j                  d
   j                  d      rN|j                  d
   j!                  d      r0	 t#        j$                  d|j&                  d
         j&                  }n|j                  rg }d}|j                  D ]  }	|	dk(  rd}|	j!                  d      s4t        d|	z  t         j                         t        j                  d       Pt*        j,                  j/                  |	      s4t        d|	z  t         j                         t        j                  d       t1        |	      5 }
|j3                  |	|
j5                         f       ddd        |r2|r0t        dt         j                         t        j                  d       |j                  rrVg }|rt        d       t6        j8                  rSt;        j<                  d      } |t         j>                        t         _        t         j>                  j5                         }n?t         j>                  j@                  }tC        jD                  |d      j5                         }|jG                  d      }tI        |      dk(  r|j3                  d|d
   f       no|j3                  d|jK                  d
      d|jK                  d
      f       |r7|j3                  dtI        |      dz   z  d|jK                  d
      z  f       |r7|jL                  rntO        |jL                  |      \  }}|rUt        dt         j                         |D ]  }t        |t         j                          t        j                  d       nd}|jP                  rBt1        |jP                        5 }
tS        jT                  |
j5                               }ddd       nd}	 tW        |      }0t        d!t         j                         t        j                  d       |jb                  r|jb                  D ]D  }||jd                  vst        d"|z  t         j                         t        j                  d       F |jd                  jg                         D ]0  }|jh                  |jb                  vsg |_5        i |_6        i |_7        2 |jp                  rw|jp                  D ]h  }||jd                  vr4t        d#|z  t         j                         t        j                  d       E|jd                  |   }g |_5        i |_6        i |_7        j |r|jd                  jg                         D ]e  }g }|jj                  D ]%  }|js                  |      s|j3                  |       ' g |_5        i |_6        i |_7        |D ]  }|ju                  |        g |jv                  rGty        |jv                        }d$|v r8|jz                  j|                  D ch c]  }|jh                   }}n
ty               }|jd                  jg                         D ]M  }|jj                  D ]<  }t        |j                  j                               D ]  }||vs|j                  |=  > O |jz                  j|                  dd D ]r  }|jh                  |vrG|jz                  j|                  j                  |       |jz                  j                  |jh                  = X|j                  |jh                         t |rC|jK                         }t        d%|z  t         j                         t        j                  d       |j                  t        v rt        d&|j                  z  d'g(      }nt*        j,                  j/                  |j                        s?t        d)|j                  z  t         j                         t        j                  d       n?t*        j,                  j                  |j                        s>t        d*|j                  z  t         j                         t        j                  d       nt        j                  |j                        s>t        d+|j                  z  t         j                         t        j                  d       n{t*        j,                  j                  |j                        }|t         j,                  vrt         j,                  j3                  |       	 t#        j$                  d,|j                        }t        ||j                  |j                  .      }	 |j                          t         j                  d
   j!                  d0      s|S y# t(        $ r<}t        d|t         j                         t        j                  d       Y d}~pd}~ww xY w# 1 sw Y   	OxY w# 1 sw Y   xY w# tX        $ r}t        |j,                  d|jZ                  d|j\                  t         j                         |r.t        d t_        j`                         t         j                         t        j                  d       Y d}~d}~ww xY wc c}w # t        $ r* t        d-|j                  z  t         j                          w xY w# t        $ ra}t        |j                  d|j                  d/|j^                  t         j                         t        j                  d       Y d}~d}~ww xY w)1z The entry point for the program.z--r   NF   Tz+error: I can only be so garrulous, try -vv.)file)levelr   +z.pyapiz/error: Could not import API description due to:-z.stonez7error: Specification '%s' must have a .stone extension.z*error: Specification '%s' cannot be found.zCerror: Do not specify stdin and specification files simultaneously.z!Reading specification from stdin.utf8zutf-8)encoding	namespacezstdin.1zstdin.%sznamespace%szError(s) in route filter:)debugroute_whitelist_filter:z	: error: z>A traceback is included below in case this is a bug in Stone.
zAYou must fix the above parsing errors for generation to continue.z2error: Whitelisted namespace missing from spec: %sz2error: Blacklisted namespace missing from spec: %sz:allz3error: Attribute not defined in stone_cfg.Route: %szstone.backends.%s )fromlistz$error: Backend '%s' cannot be found.z#error: Backend '%s' must be a file.z5error: Backend '%s' must have a .stoneg.py extension.user_backendz9error: Importing backend '%s' module raised an exception:)clean_buildz raised an exception:
stone)Qsysargvindex_cmdline_parser
parse_argsverboseloggingWARNINGINFODEBUGprintstderrexitbasicConfigr!   
startswithendswithimpload_sourcer,   ImportErrorospathexistsopenr%   readsixPY2codecs	getreaderstdinbufferioTextIOWrappersplitlenpopfilter_by_route_attrr   r2   jsonloadsr   r   linenomsg	traceback
format_excwhitelist_namespace_routes
namespacesvaluesnameroutesroute_by_nameroutes_by_nameblacklist_namespace_routeseval	add_route	attributesetroute_schemafieldslistattrskeysremove_fields_by_namer   _builtin_backends
__import__isfiler
   is_stone_backenddirname	Exceptionr    r7   buildr	   backend_name)cli_argsbackend_argsargsr1   logging_levelr,   especsread_from_stdin	spec_pathf
UTF8Reader
stdin_textstdin_bufferpartsroute_filterroute_filter_errorserrr2   namespace_namer0   filtered_routesrouterr   fieldkattrbackend_modulenew_python_pathcs                                 )lib/python3.12/site-packages/stone/cli.pymainr      s	    sxx88AchhnnT23xxt 4q 8 9:88AB<%%h/DE||				;#**Mm,yyTYYq\,,S1diil6K6KE6R
	//%!599C 99E#O!YY <	#&*O"++H5S%&"zz+ HHQK	2FR"zz+HHQKi <Ai%:;< << 5 (.1jj:yyOE9:ww#--f5
&syy1	 YY^^-
"yy//--lWMRRT
$$[1E5zQiq23599Q<1 NOQLL*E
Q"?"/%))A,">"@ A  $$0G))512-L-"1

C. 0C#CJJ/0  L&&d112 >a)-AFFH)=&> > &*"		e55KMC ; $'JJ0HHQK**"&"A"A  !7N()/2zz;HHQK	 
 !^^224 2	>>)H)HH')I$.0I+/1I,	2 **"&"A"A 	2!7N()/2zz;HHQK #~ >I')I$.0I+/1I,	2  ^^224 
/	"$&-- 6E#((/'..u56 $&	 *,	'+-	(, /E''./
/ >>'E141A1A1H1HIIIEE..0 	+I")) +ekk..01 +A~!KKN++	+ %%,,Q/ 	)Ezz&  ''..u5$$44UZZ@UZZ(	) 99;DG ZZ)HHQK||((#$,,."?WW^^DLL)4t||C::	WW^^DLL)3dllB::	&&t||4Ell!$	-
 ''//$,,7#((*HHOOO,	 __^T\\JN 	$$	A		 88A;( 
 )C  	C#**&HHQKK	*< <V> >  	!%%@szzR !"+"6"6"8szzKHHQKK	f Jb  	M,,%(ZZ1	  ||Q^^Q[[:::	 		st   -k "l"-$l/l< o  o %p 	l#1ll"l,	/l9<	oBoo3p	q>Aq99q>__main__)+__doc__
__future__r   r   r   r   rS   rI   rW   r]   r?   rL   rQ   r9   ra   cli_helpersr   compilerr	   r
   frontend.exceptionr   frontend.frontendr   _MYPYtyping	importlibimport_modulestrr   rv   _cmdline_descriptionArgumentParserr<   add_argumentjoin_backend_help	text_typeadd_mutually_exclusive_group_filter_ns_groupr   __name__r,        r   <module>r      sC   S R  
 	   	 
 
  0 , * "9""3z?3 "  ))6J)K   	&	  ,.2ii8I.JK    		  
   		1  
   

		     	@  
   	#	     	\	     	9  
 #??A    "		T     "		Q  dN z
&C r   