
    j                     $   U d 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mZmZ dZdZdZdZ eej        j                  Zdd	gZg d
Z eeeee ed          eeh          Zee e!e"e#e$e%e&e'e(e)ej*        ej+        hZ, e-e.d          s e-e.d          rde.v re,/                    e0           eh deh deh deh dd e1            e2h de3h de1h de4ddhi	Z5eee
df         ef         e6d<    G d de7          Z8 G d de7          Z9 G d de9          Z: G d de9          Z; G d de9          Z< G d  d!e9          Z= G d" d#e9          Z> G d$ d%e9          Z? G d& d'e9          Z@ G d( d)eA          ZB G d* d+eA          ZC eD            ZE G d, d-          ZFd. ZGd/ ZHd0 ZId1 ZJd2 ZKd3 ZLi ejM        eJejN        ejO        ejP        eIejQ        ejR        ejS        ejT        ejU        eKejV        eLejW        eHejX        ejY        ejZ        ej[        ej\        ej]        ej^        ej_        ej`        eja        ejb        ejc        ejd        eje        ejf        ejg        ejh        eji        ejj        ejk        ejl        ejm        ejn        ejo        ejp        ejq        ejr        ejs        ejt        d4 eju        d5 ejv        d6 ejw        d7 i	ZxeeGeeed8Zyd9d:dd;Zzd9Z{ G d< d=eD          Z| G d> d?e|          Z}dAd@Z~dS )Bu  
SimpleEval - (C) 2013-2026 Daniel Fairhead
-------------------------------------

An short, easy to use, safe and reasonably extensible expression evaluator.
Designed for things like in a website where you want to allow the user to
generate a string, or a number from some other input, without allowing full
eval() or other unsafe or needlessly complex linguistics.

-------------------------------------

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

-------------------------------------

Initial idea copied from J.F. Sebastian on Stack Overflow
( http://stackoverflow.com/a/9558001/1973500 ) with
modifications and many improvements.

-------------------------------------
Contributors:
- corro (Robin Baumgartner) (py3k)
- dratchkov (David R) (nested dicts)
- marky1991 (Mark Young) (slicing)
- T045T (Nils Berg) (!=, py3kstr, obj.
- perkinslr (Logan Perkins) (.__globals__ or .func_ breakouts)
- impala2 (Kirill Stepanov) (massive _eval refactor)
- gk (ugik) (Other iterables than str can DOS too, and can be made)
- daveisfera (Dave Johansen) 'not' Boolean op, Pycharm, pep8, various other fixes
- xaled (Khalid Grandi) method chaining correctly, double-eval bugfix.
- EdwardBetts (Edward Betts) spelling correction.
- charlax (Charles-Axel Dein charlax) Makefile and cleanups
- mommothazaz123 (Andrew Zhu) f"string" support, Python 3.8 support
- lubieowoce (Uryga) various potential vulnerabilities
- JCavallo (Jean Cavallo) names dict shouldn't be modified
- Birne94 (Daniel Birnstiel) for fixing leaking generators, star expressions
- patricksurry (Patrick Surry) or should return last value, even if falsy.
- shughes-uk (Samantha Hughes) python w/o 'site' should not fail to import.
- KOLANICH packaging / deployment / setup help & << + >> & other bit ops
- graingert (Thomas Grainger) packaging / deployment / setup help
- bozokopic (Bozo Kopic) Memory leak fix
- daxamin (Dax Amin) Better error for attempting to eval empty string
- smurfix (Matthias Urlichs) Allow clearing functions / operators / etc completely
- koenigsley (Mikhail Yeremeyev) documentation typos correction.
- kurtmckee (Kurt McKee) Infrastructure updates
- edgarrmondragon (Edgar Ramírez-Mondragón) Address Python 3.12+ deprecation warnings,
  performance fixes
- cedk (Cédric Krier) <ced@b2ck.com> Allow running tests with Werror
- decorator-factory <decorator-factory@protonmail.com> More security fixes
- lkruitwagen (Lucas Kruitwagen) Adding support for dict comprehensions
- ByamB4 (Byambadalai) Reported breakout via module & disallowed functions as object attrs

-------------------------------------
Basic Usage:

>>> s = SimpleEval()
>>> s.eval("20 + 30")
50

You can add your own functions easily too:

if file.txt contents is "11"

>>> def get_file():
...     with open("file.txt", 'r') as f:
...         return f.read()

>>> s.functions["get_file"] = get_file
>>> s.eval("int(get_file()) + 31")
42

For more information, see the full package documentation on pypi, or the github
repo.

-----------

If you don't need to re-use the evaluator (with it's names, functions, etc),
then you can use the simple_eval() function:

>>> simple_eval("21 + 19")
40

You can pass names, operators and functions to the simple_eval function as
well:

>>> simple_eval("40 + two", names={"two": 2})
42

    N)random)TypeDictSetUnioni i'  i 	= _func_)format
format_mapmrotb_framegi_frameag_framecr_frameexechelp__contains__>	   imagrealto_bytes	conjugate	numerator
bit_length
from_bytesdenominatoras_integer_ratio>   hexr   r   fromhexr   
is_integerr   >/   findjoincountindexljustlowerrfindrjustsplitstriptitleupperzfillcenterencoder
   lstriprindexrsplitrstripisalnumisalphaisasciiisdigitislowerisspaceistitleisupperreplacecasefoldendswithswapcase	isdecimal	isnumeric	maketrans	partition	translate
capitalize
expandtabsr   
rpartition
splitlines
startswithisprintableisidentifierremoveprefixremovesuffix>   getpopcopykeysclearitemsupdatevaluespopitemfromkeys
setdefault>   rN   rO   sortrQ   r"   r#   appendextendinsertremovereverse>   addrN   rO   rQ   unionr\   rS   discardissubset
difference
isdisjoint
issupersetintersectiondifference_updateintersection_updatesymmetric_differencesymmetric_difference_updater#   r"   BASIC_ALLOWED_ATTRSc                       e Zd ZdS )TypeNotSpecifiedN)__name__
__module____qualname__     T/lsinfo/ai/hellotax_ai/base_platform/venv/lib/python3.11/site-packages/simpleeval.pyrl   rl   5  s        Drq   rl   c                       e Zd ZdZdS )InvalidExpressionzGeneric ExceptionNrm   rn   ro   __doc__rp   rq   rr   rt   rt   9  s        Drq   rt   c                   "     e Zd ZdZ fdZ xZS )FunctionNotDefinedz#sorry! That function isn't defined!c                     d                     ||          | _        t          | d|           || _        t	          t
          |                               | j                   d S )Nz1Function '{0}' not defined, for expression '{1}'.	func_name)r
   messagesetattr
expressionsuperrt   __init__)selfrz   r}   	__class__s      rr   r   zFunctionNotDefined.__init__B  sa    JQQz
 
 	k9---$&&//=====rq   rm   rn   ro   rv   r   __classcell__r   s   @rr   rx   rx   ?  s>        --> > > > > > > > >rq   rx   c                   "     e Zd ZdZ fdZ xZS )NameNotDefinedza name isn't defined.c                     || _         d                    ||          | _        || _        t	          t
          |                               | j                   d S )Nz)'{0}' is not defined for expression '{1}')namer
   r{   r}   r~   rt   r   )r   r   r}   r   s      rr   r   zNameNotDefined.__init__O  sP    	BII$PZ[[$&&//=====rq   r   r   s   @rr   r   r   L  s>        > > > > > > > > >rq   r   c                   "     e Zd ZdZ fdZ xZS )AttributeDoesNotExistzattribute does not existc                     d                     ||          | _        || _        || _        t	          t
          |                               | j                   d S )Nz2Attribute '{0}' does not exist in expression '{1}'r
   r{   attrr}   r~   rt   r   r   r   r}   r   s      rr   r   zAttributeDoesNotExist.__init__Z  sV    KRR*
 
 	$&&//=====rq   r   r   s   @rr   r   r   W  s>        ""> > > > > > > > >rq   r   c                   "     e Zd ZdZ fdZ xZS )OperatorNotDefinedzoperator does not existc                     d                     ||          | _        || _        || _        t	          t
          |                               | j                   d S )Nz1Operator '{0}' does not exist in expression '{1}'r   r   s      rr   r   zOperatorNotDefined.__init__g  sQ    JQQRVXbcc	$&&//=====rq   r   r   s   @rr   r   r   d  s>        !!> > > > > > > > >rq   r   c                       e Zd ZdZdS )FeatureNotAvailablez(What you're trying to do is not allowed.Nru   rp   rq   rr   r   r   o          22Drq   r   c                       e Zd ZdZdS )NumberTooHighzgSorry! That number is too high. I don't want to spend the
    next 10 years evaluating this expression!Nru   rp   rq   rr   r   r   u  s        1 1 	Drq   r   c                       e Zd ZdZdS )IterableTooLongz(That iterable is **way** too long, baby.Nru   rp   rq   rr   r   r   |  r   rq   r   c                       e Zd ZdZdS )AssignmentAttemptedz$Assignment not allowed in SimpleEvalNru   rp   rq   rr   r   r     s        ..Drq   r   c                       e Zd ZdZdS )MultipleExpressionsz-Only the first expression parsed will be usedNru   rp   rq   rr   r   r     s        77Drq   r   c                        e Zd ZdZddZd ZdS )ModuleWrappera"  Wraps a module to safely expose it in expressions.

    By default, modules are not allowed in simpleeval names to prevent
    accidental or malicious access to dangerous functions. ModuleWrapper
    allows explicit opt-in to module access while still enforcing
    restrictions on dangerous methods and functions.

    Example:
        >>> from simpleeval import SimpleEval, ModuleWrapper
        >>> import os.path
        >>> s = SimpleEval(names={'path': ModuleWrapper(os.path)})
        >>> s.eval('path.exists("/etc/passwd")')  # Works
    Nc                     t          |t          j                  st          dt	          |                     || _        || _        dS )a  
        Args:
            module: The module to wrap
            allowed_attrs: Optional set of allowed attribute names.
                          If None, all public attributes are allowed
                          (but still subject to DISALLOW_METHODS checks).
        z%ModuleWrapper requires a module, got N)
isinstancetypes
ModuleType	TypeErrortype_module_allowed_attrs)r   moduleallowed_attrss      rr   r   zModuleWrapper.__init__  sL     &%"233 	TRDLLRRSSS+rq   c                     |                     d          rt          d| d          |t          v rt          d| d          | j        || j        vrt          d| d          t	          | j        |          S )Nr   zAccess to private attribute 'z' is not allowedzMethod 'z' is not allowed on moduleszAccess to 'z'' is not allowed on this wrapped module)rH   r   DISALLOW_METHODSr   getattrr   )r   r   s     rr   __getattr__zModuleWrapper.__getattr__  s    ??3 	^%&\d&\&\&\]]] ###%&R&R&R&RSSS *t4;N/N/N%&aD&a&a&abbbt|T***rq   N)rm   rn   ro   rv   r   r   rp   rq   rr   r   r     sA         , , , ,+ + + + +rq   r   c                 >    t          t                      | z            S )zreturn a random int below <top>)intr   )tops    rr   
random_intr     s     vxx#~rq   c                     t          |           t          k    st          |          t          k    r#t          d                    | |                    | |z  S )z?a limited exponent/to-the-power-of function, for safety reasonsz*Sorry! I don't want to evaluate {0} ** {1})abs	MAX_POWERr   r
   abs     rr   
safe_powerr     sO     1vv	SVVi//HOOPQSTUUVVVa4Krq   c                     t          | d          r*|t          |           z  t          k    rt          d          t          |d          r*| t          |          z  t          k    rt          d          | |z  S )z8limit the number of times an iterable can be repeated...__len__z/Sorry, I will not evaluate something that long.hasattrlenMAX_STRING_LENGTHr   r   s     rr   	safe_multr     s{     q) QSVV.?!?!?OPPPq) QSVV.?!?!?OPPPq5Lrq   c                     t          | d          rGt          |d          r7t          |           t          |          z   t          k    rt          d          | |z   S )ziterable length limit againr   z?Sorry, adding those two together would make something too long.r   r   s     rr   safe_addr     sc     q) I!6!6 q66CFF?...!Q   q5Lrq   c                     t          |          t          k    st          |           t          k    r#t          d                    | |                    | |z	  S )zrshift, but with input limitsz*Sorry! I don't want to evaluate {0} >> {1}r   	MAX_SHIFTMAX_SHIFT_BASEr   r
   r   s     rr   safe_rshiftr     M    
1vv	SVVn44HOOPQSTUUVVV6Mrq   c                     t          |          t          k    st          |           t          k    r#t          d                    | |                    | |z  S )zlshift, but with input limitsz*Sorry! I don't want to evaluate {0} << {1}r   r   s     rr   safe_lshiftr     r   rq   c                 ,    t          j        ||           S r   opcontainsxys     rr   <lambda>r     s    Q** rq   c                 .    t          j        ||            S r   r   r   s     rr   r   r     s    Aq 1 11 rq   c                 
    | |u S r   rp   r   s     rr   r   r     s
    a rq   c                 
    | |uS r   rp   r   s     rr   r   r     s
    AQJ rq   )randrandintr   floatstrTF)TrueFalseNonec                      e Zd ZdZdZddZd Zd Zed             Z	d dZ
d	 Zd
 Zd Zd Zed             Zed             Zed             Zed             Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z dS )!
SimpleEvalzjA very simple expression parser.
    >>> s = SimpleEval()
    >>> s.eval("20 + 30 - ( 10 * 5)")
    0
     Nc                    |t                                           }|t                                          }|t                                          }|| _        || _        || _        || _        i t          j	        | j
        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j         t          j!        | j"        t          j#        | j$        t          j%        | j&        t          j'        | j(        t          j)        | j*        t          j+        | j,        t          j-        | j.        i| _/        ta          j1                    5  ta          j2        d           tg          t          dd          x}r| j4        | j/        |<   tg          t          dd          x}r| j5        | j/        |<   tg          t          dd          x}r| j.        | j/        |<   ddd           n# 1 swxY w Y   tl          | _6        | j        7                                D ]-}|tp          v r"ts          d:                    |                    .dS )z
        Create the evaluator instance.  Set up valid operators (+,-, etc)
        functions (add, random, get_val, whatever) and names.NignoreNumStrNameConstantz&This function {} is a really bad idea.);DEFAULT_OPERATORSrO   DEFAULT_FUNCTIONSDEFAULT_NAMES	operators	functionsnamesr   astExpr
_eval_exprAssign_eval_assign	AugAssign_eval_aug_assignImport_eval_importName
_eval_nameUnaryOp_eval_unaryopBinOp_eval_binopBoolOp_eval_boolopCompare_eval_compareIfExp_eval_ifexpCall
_eval_callkeyword_eval_keyword	Subscript_eval_subscript	Attribute_eval_attributeIndex_eval_indexSlice_eval_slice	JoinedStr_eval_joinedstrFormattedValue_eval_formattedvalueConstant_eval_constantnodeswarningscatch_warningssimplefilterr   	_eval_num	_eval_strATTR_INDEX_FALLBACKrT   DISALLOW_FUNCTIONSr   r
   )	r   r   r   r   r   r   r   r   fs	            rr   r   zSimpleEval.__init__.  s   
 )..00I)..00I=!&&((E""
*
Hdo
J)
 M40
 J)	

 Hdo
 K+
 It'
 J)
 K+
 It'
 Hdo
 K+
 M4/
 M4/
 It'
  It'!
" M4/#
$  9L$-'
 

, $&& 	? 	?!(+++ c5$///s 1"&.
3c5$///s 1"&.
3&sNDAAA| ?+/+>
<(	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? $7  &&(( 	^ 	^A&&&)*R*Y*YZ[*\*\]]] '	^ 	^s   B
I44I8;I8c                     d | _         d S r   )r  )r   s    rr   __del__zSimpleEval.__del__l  s    


rq   c                    t          |          t          v rdS t          |t                    rdS t          |t          j                  rt          d          t          |t          t          f          r|D ]}| 	                    |           dS t          |t                    r.|                                D ]}| 	                    |           dS t          |          r|t          v rt          d          dS dS )a
  Check if item contains disallowed functions or modules.
        Recursively checks containers (list, dict, tuple).
        Raises FeatureNotAvailable if forbidden content found.
        ModuleWrapper instances are allowed (explicit opt-in to module access).
        NzSorry, modules are not allowedThis function is forbidden)r   _PRIMITIVE_TYPESr   r   r   r   r   listtuple_check_disallowed_itemsdictrT   callabler  )r   itemelementvalues       rr   r!  z"SimpleEval._check_disallowed_itemso  s&    ::)))F dM** 	FdE,-- 	H%&FGGGdT5M** 	D 6 6,,W55556 6d## 	D 4 4,,U33334 4d^^ 	D(: : :%&BCCC	D 	D : :rq   c                    t          j        |                                           }|j        st	          d          t          |j                  dk    r-t          j        d                    |           t                     |j        d         S )z$parse an expression into a node treez#Sorry, cannot evaluate empty string   z@'{}' contains multiple expressions. Only the first will be used.r   )
r   parser)   bodyrt   r   r  warnr
   r   )exprparseds     rr   r)  zSimpleEval.parse  s     4::<<(({ 	K#$IJJJv{aMRYYZ^__#   {1~rq   c                 d    || _         |                     |p|                     |                    S )z[evaluate an expression, using the operators, functions and
        names previously set up.)r,  _evalr)  )r   r,  previously_parseds      rr   evalzSimpleEval.eval  s/    
 	zz+?tzz$/?/?@@@rq   c                    	 | j         t          |                   }nB# t          $ r5 t          d                    t          |          j                            w xY w ||          }|                     |           |S )z<The internal evaluator used on each node in the parsed tree.z-Sorry, {0} is not available in this evaluator)r  r   KeyErrorr   r
   rm   r!  )r   nodehandlerresults       rr   r/  zSimpleEval._eval  s    	jd,GG 	 	 	%?FFtDzzGZ[[  	
 $$V,,,s	    ?Ac                 6    |                      |j                  S r   r/  r&  r   r4  s     rr   r   zSimpleEval._eval_expr      zz$*%%%rq   c                     t          j        d                    | j                  t                     |                     |j                  S Nz.Assignment ({}) attempted, but this is ignoredr  r+  r
   r,  r   r/  r&  r9  s     rr   r   zSimpleEval._eval_assign  B    <CCDINNPc	
 	
 	
 zz$*%%%rq   c                     t          j        d                    | j                  t                     |                     |j                  S r<  r=  r9  s     rr   r   zSimpleEval._eval_aug_assign  r>  rq   c                      t          d          )NzSorry, 'import' is not allowed.)r   r4  s    rr   r   zSimpleEval._eval_import  s    !"CDDDrq   c                     | j         S r   )nrA  s    rr   r  zSimpleEval._eval_num  s	    vrq   c                     t          | j                  t          k    r:t          d                    t          | j                  t                              | j        S )Nz?String Literal in statement is too long! ({0}, when {1} is max))r   sr   r   r
   rA  s    rr   r  zSimpleEval._eval_str  sR    tv;;***!QXXKK!2   
 vrq   c                     t          | j        d          rWt          | j                  t          k    r:t	          d                    t          | j                  t                              | j        S )Nr   z8Literal in statement is too long! ({0}, when {1} is max))r   r&  r   r   r   r
   rA  s    rr   r  zSimpleEval._eval_constant  sf    4:y)) 	c$*oo@Q.Q.Q!JQQ
OO%6   
 zrq   c                     	 | j         t          |j                           }n(# t          $ r t	          |j        | j                  w xY w ||                     |j                            S r   )r   r   r   r3  r   r,  r/  operandr   r4  operators      rr   r   zSimpleEval._eval_unaryop  sj    	9~d47mm4HH 	9 	9 	9$TWdi888	9x

4<00111	   " %Ac                    	 | j         t          |j                           }n(# t          $ r t	          |j        | j                  w xY w ||                     |j                  |                     |j                            S r   )	r   r   r   r3  r   r,  r/  leftrightrI  s      rr   r   zSimpleEval._eval_binop  sz    	9~d47mm4HH 	9 	9 	9$TWdi888	9x

49--tzz$*/E/EFFFrK  c                    d}t          |j        t          j                  r$|j        D ]}|                     |          }|s nnBt          |j        t          j                  r#|j        D ]}|                     |          }|r n|S )NF)r   r   r   AndrT   r/  Or)r   r4  	to_returnr&  s       rr   r   zSimpleEval._eval_boolop  s    	dgsw'' 		   JJu--	  E(( 	   JJu--	 Erq   c                     |                      |j                  }d}t          |j        |j                  D ]D\  }}|s n<|}|                      |          } | j        t          |                   ||          }E|S )NT)r/  rM  zipopscomparatorsr   r   )r   r4  rN  rR  	operationcomprM  s          rr   r   zSimpleEval._eval_compare  s    

49%%	"48T-=>> 	E 	EOIt DJJt$$E7tI7eDDIIrq   c                     |                      |j                  r|                      |j                  n|                      |j                  S r   )r/  testr*  orelser9  s     rr   r   zSimpleEval._eval_ifexp  s<    (,

49(=(=Ztzz$)$$$4::dkCZCZZrq   c                     t          |j        t          j                  r                     |j                  }nv	  j        |j        j                 }nE# t          $ r  t          |j        j         j	                  t          $ r t          d          w xY w|t          v rt          d           | fd|j        D             i t           fd|j        D                       S )Nz Lambda Functions not implementedr  c              3   B   K   | ]}                     |          V  d S r   r/  ).0r   r   s     rr   	<genexpr>z(SimpleEval._eval_call.<locals>.<genexpr>  s-      //djjmm//////rq   c              3   B   K   | ]}                     |          V  d S r   r^  )r_  kr   s     rr   r`  z(SimpleEval._eval_call.<locals>.<genexpr>  s-      7]7]!

17]7]7]7]7]7]rq   )r   funcr   r  r/  r   idr3  rx   r,  AttributeErrorr   r  argsr"  keywords)r   r4  rc  s   `  rr   r   zSimpleEval._eval_call  s   di// 	H::di((DDN~dil3 B B B(tyAAA! N N N)*LMMMN ))))*FGGGt////TY///
377]7]7]7]t}7]7]7]3]3]
 
 	
s   A ABc                 D    |j         |                     |j                  fS r   )argr/  r&  r9  s     rr   r  zSimpleEval._eval_keyword  s    xDJ////rq   c                    	 | j         |j                 S # t          t          f$ r Y nw xY wt	          | j                   r&	 |                      |          S # t
          $ r Y n@w xY wt          | j         d          s't          d                    |j                            |j        | j	        v r| j	        |j                 S t          |j        | j
                  )N__getitem__zITrying to use name (variable) "{0}" when no "names" defined for evaluator)r   rd  r   r3  r#  r   r   rt   r
   r   r,  r9  s     rr   r   zSimpleEval._eval_name  s    		 :dg&&8$ 	 	 	D	 DJ 
	zz$'''!   ]33 	#[bbG    7dn$$>$'**TWdi000s    (( A 
A"!A"c                 z    |                      |j                  }|                      |j                  }||         S r   )r/  r&  slice)r   r4  	containerkeys       rr   r  zSimpleEval._eval_subscript6  s4    JJtz**	jj$$ ~rq   c                    t           D ]C}|j                            |          r't          d                    |j                            D|j        t
          v r't          d                    |j                            |                     |j                  }| j        yt          |          }| j        
                    |t                    }|t          k    rt          d| d|j         d          |j        |vrt          d|j         d| d          t          }	 t          ||j                  }nD# t          t          f$ r0 | j        r&	 ||j                 }n# t"          t          f$ r Y nw xY wY nw xY w|t          urRt%          |t&          j                  rt          d	          t+          |          r|t,          v rt          d
          |S t/          |j        | j                  )NzJSorry, access to __attributes  or func_ attributes is not available. ({0})z*Sorry, this method is not available. ({0})z(Sorry, attribute access not allowed on 'z' (attempted to access `.z`)z	Sorry, '.z' access not allowed on ''z2Sorry, modules are not allowed in attribute accessr  )DISALLOW_PREFIXESr   rH   r   r
   r   r/  r&  r   r   rM   rl   _ATTR_NOT_FOUNDr   re  r   r  r3  r   r   r   r#  r  r   r,  )r   r4  prefixnode_evaluatedtype_to_checkr   r$  s          rr   r  zSimpleEval._eval_attribute=  sG    ( 	 	Fy##F++ )"F49--   9(((%<CCDINN  
 DJ//
 ) 00M .22=BRSSM 000)=} = =/3y= = =   y--)T	TTMTTT   	>4955DD	* 	 	 	' )$)4DD ),   D	 &&$ 011 `)*^___~~ H$*<"<"<)*FGGGK $DIty999s6   #D9 9E:E E: E41E:3E44E:9E:c                 6    |                      |j                  S r   r8  r9  s     rr   r  zSimpleEval._eval_indexw  r:  rq   c                     d x}x}}|j         |                     |j                   }|j        |                     |j                  }|j        |                     |j                  }t	          |||          S r   )r%   r/  r+   steprm  )r   r4  r%   r+   ry  s        rr   r
  zSimpleEval._eval_slicez  st    ###:!JJtz**E:!JJtz**E9 ::di((DUE4(((rq   c                 
   d}g }|j         D ]c}t          |                     |                    }t          |          |z   t          k    rt          d          |                    |           dd                    |          S )Nr   z/Sorry, I will not evaluate something this long.r   )rT   r   r/  r   r   r   rY   r!   )r   r4  lengthevaluated_valuesrC  vals         rr   r  zSimpleEval._eval_joinedstr  s     	) 	)Adjjmm$$C3xx& #444%&WXXX##C((((ww'(((rq   c                     |j         rMd|                     |j                   z   dz   }|                    |                     |j                            S |                     |j                  S )Nz{:})format_specr/  r
   r&  )r   r4  fmts      rr   r  zSimpleEval._eval_formattedvalue  s_     	6D$4555;C::djj44555zz$*%%%rq   NNNNr   )!rm   rn   ro   rv   r,  r   r  r!  staticmethodr)  r1  r/  r   r   r   r   r  r  r  r   r   r   r   r   r   r  r   r  r  r  r
  r  r  rp   rq   rr   r   r   %  s         D<^ <^ <^ <^|  D D D4   \A A A A  & & && & && & & E E \E   \   \   \2 2 2G G G  	 	 	[ [ [
 
 
$0 0 01 1 1:  8: 8: 8:t& & &) ) )) ) )& & & & &rq   r   c                   R     e Zd ZdZdZd fd	Zd fd	Zd Zd Zd Z	d	 Z
d
 Z xZS )EvalWithCompoundTypeszz
    SimpleEval with additional Compound Types, and their respective
    function editions. (list, tuple, dict, set).
    r   Nc                    t          t          |                               ||||           | j                            t
          t          t          t                     | j	                            t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        t          j        | j        i           d S )N)r  r   r"  set)r~   r  r   r   rS   r  r   r"  r  r  r   r   
_eval_dictTuple_eval_tupleList
_eval_listr   	_eval_setListComp_eval_comprehensionGeneratorExpDictComp)r   r   r   r   r   r   s        rr   r   zEvalWithCompoundTypes.__init__  s    #T**33Iy%Q^___4u4SIII
$/	4+$/d6 $":d6
	
 
	
 
	
 
	
 
	
rq   c                 d    d| _         t          t          |                               ||          S )Nr   )
_max_countr~   r  r1  )r   r,  r0  r   s      rr   r1  zEvalWithCompoundTypes.eval  s,    *D1166t=NOOOrq   c                     i }t          |j        |j                  D ][\  }}|)|                    |                     |                     0|                     |          ||                     |          <   \|S r   )rT  rP   rT   rS   r/  )r   r4  r6  ro  r&  s        rr   r  z EvalWithCompoundTypes._eval_dict  sv    di55 	< 	<JC{djj//0000*.**U*;*;tzz#''rq   c                     g }|j         D ]r}t          |t          j                  r.|                    |                     |j                             J|                    |                     |                     s|S r   )eltsr   r   StarredrZ   r/  r&  rY   )r   r4  r6  r$  s       rr   r  z EvalWithCompoundTypes._eval_list  su    I 	0 	0D$,, 0djj445555djj..////rq   c                 D     t           fd|j        D                       S )Nc              3   B   K   | ]}                     |          V  d S r   r^  r_  r   r   s     rr   r`  z4EvalWithCompoundTypes._eval_tuple.<locals>.<genexpr>  s-      66qTZZ]]666666rq   )r   r  r9  s   ` rr   r  z!EvalWithCompoundTypes._eval_tuple  s(    6666DI666666rq   c                 D     t           fd|j        D                       S )Nc              3   B   K   | ]}                     |          V  d S r   r^  r  s     rr   r`  z2EvalWithCompoundTypes._eval_set.<locals>.<genexpr>  s-      44Q4::a==444444rq   )r  r  r9  s   ` rr   r  zEvalWithCompoundTypes._eval_set  s(    4444$)444444rq   c                     t          t          j                  ri ng i  j        t          j                 fd} j                            t          j        |i           fdd fd		                j                            t          j        i           n+#  j                            t          j        i           w xY wS )Nc                 F    | j         v r| j                  S  |           S )zT
            Here we hide our extra scope for within this comprehension
            )rd  )r4  extra_namesprevious_name_evallers    rr   eval_names_extrazCEvalWithCompoundTypes._eval_comprehension.<locals>.eval_names_extra  s0     w+%%"47++((...rq   c                     t          | t          j                  r|| j        <   dS t	          | j        |          D ]\  }} ||           dS )z
                Recursively (enter, (into, (nested, name), unpacking)) =                              and, (assign, (values, to), each
            N)r   r   r   rd  rT  r  )targetr&  tvr  recurse_targetss       rr   r  zBEvalWithCompoundTypes._eval_comprehension.<locals>.recurse_targets  si    
 &#(++ *).FI&&&U33 * *DAq#OAq))))* *rq   r   c                    j         |          }                    |j                  D ]}xj        dz  c_        j        t          k    rt          d           |j        |           t          fd|j        D                       rt          j                   | dz   k    r | dz              t          t                    r6                    j                                      j                  <   t          t                    r-                                        j                             d S )Nr(  z)Comprehension generates too many elementsc              3   B   K   | ]}                     |          V  d S r   r^  )r_  iffr   s     rr   r`  zREvalWithCompoundTypes._eval_comprehension.<locals>.do_generator.<locals>.<genexpr>  s-      883tzz#888888rq   )
generatorsr/  iterr  MAX_COMPREHENSION_LENGTHr   r  allifsr   r   r"  r&  ro  r  rY   elt)gigido_generatorr4  r  r   rR  s      rr   r  z?EvalWithCompoundTypes._eval_comprehension.<locals>.do_generator  sE   #AZZ'' C C1$?%===)*UVVV!,,,8888!%88888 C4?++b1f44$R!V,,,,%i66 C>Bjj>T>TIdjj&:&:;;'	488 C%,,TZZ-A-ABBBC Crq   )r   )r   r   r  r  r   rS   )r   r4  r  r  r  r  r  rR  s   `` @@@@@rr   r  z)EvalWithCompoundTypes._eval_comprehension  s1   dCL)) 	III $
38 4	/ 	/ 	/ 	/ 	/ 	/ 	
38%56777		* 		* 		* 		* 		* 		*	C 	C 	C 	C 	C 	C 	C 	C 	C 	C"	ALNNNJsx)>?@@@@DJsx)>?@@@@s   =
B. .(Cr  r   )rm   rn   ro   rv   r  r   r1  r  r  r  r  r  r   r   s   @rr   r  r    s         
 J
 
 
 
 
 
"P P P P P P

 
 
	 	 	7 7 75 5 55 5 5 5 5 5 5rq   r  c                 R    t          ||||          }|                    |           S )zSimply evaluate an expression)r   r   r   r   )r   r1  )r,  r   r   r   r   rE  s         rr   simple_evalr    s4    #		 	 	A 66$<<rq   r  )rv   r   rJ  r   ossysr   r  r   typingr   r   r   r   r   r  r   r   r   
float_infomaxr   rr  r   	frozensetr   r   boolr   bytescomplexr  r   r1  r   r|   reprcompileopenr   globalslocalspopensystemr  r   __builtins__r^   r   r  r"  r  r   rj   __annotations__	Exceptionrl   rt   rx   r   r   r   r   r   r   UserWarningr   r   objectrs  r   r   r   r   r   r   r   AddSubsubMultDivtruedivFloorDivfloordivRShiftLShiftPowModmodEqeqNotEqneGtgtLtltGtEgeLtEleNotnot_USubnegUAddposBitXorxorBitOror_BitAndand_InvertinvertInNotInIsIsNotr   r   r   r  r   r  r  rp   rq   rr   <module>r     s  h h hT 


     				 



         ) ) ) ) ) ) ) ) ) ) ) )
    		S^'(('N 	 	 	   9c5#tTT$ZZPQQ  	
HI  7<   !GL.))!.4.D.D 4   
  

 

 

 
     0
 0
 0
b 	 
 
 
 	##%%    	     
 
 
& 
GW@5 T%d
+S01 @ @ @N	 	 	 	 	y 	 	 		 	 	 	 		 	 	 	
> 
> 
> 
> 
>* 
> 
> 
>> > > > >& > > >
> 
> 
> 
> 
>- 
> 
> 
>> > > > >* > > >	 	 	 	 	+ 	 	 		 	 	 	 	% 	 	 		 	 	 	 	' 	 	 		 	 	 	 	+ 	 	 		 	 	 	 	+ 	 	 	 &(()+ )+ )+ )+ )+ )+ )+ )+`            GXGRV Hi GRZ	
 L"+ J J GZ GRV FBE Iru FBE FBE GRU GRU  GRW!" Hbf#$ HbfJIrvJJ	F**I11FI&&5  <    t<< m& m& m& m& m& m& m& m&`p p p p pJ p p pf     rq   