Ë
    ZV.jz  ã                   óJ   — d dl Z d dlZd dlmZ  G d„ de j                  «      Zy)é    N)ÚOrderedDictc                   ó¦  ‡ — e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                   ej"                  ej$                  fZdZdZdZd„ Zed„ «       Zd„ Zd„ Zd„ Zd„ Zˆ fd	„Zd
„ Zd„ Z d„ Z!ˆ xZ"S )ÚSampleCodeValidatoraò  
    Class that checks if a string is a valid and "safe" Python expression

    What is considered "safe" for this class is limited to the context of generating
    provider method sample code and output for documentation purposes. The end goal
    is to pass a command string to `eval()` should the string pass the validation
    performed by this class.

    The main assumption this class will make is that the command string passed during
    class instantiation will always be in the form "{generator}.{method}({arguments})".
    In said form, {generator} is a `Generator` object variable that already exists
    within the scope where `eval()` will be called, {method} will be the provider
    method name which is also available within the `eval()` scope, and {arguments}
    will be sample arguments parsed from docstrings. This means that {arguments} can
    potentially be used as a vector for code injection.

    In order to neuter the impact of code injection, the following validation steps
    will be applied:

    - The command string is parsed using 'eval' mode, meaning expressions only.
    - The command string can only have whitelisted code elements. See `_whitelisted_nodes`.
    - The command string can only have one instance of variable access.
    - The command string can only have one instance of attribute access.
    - The command string can only have one instance of a function/method call.
    - The argument values in the command string can only be literals.
    - The only literals allowed are numbers (integers, floats, or complex numbers),
      strings (but not f-strings), bytes, lists, tuples, sets, dictionaries, True,
      False, and None.

    There is, however, an exception. In order to accommodate sample code with custom
    probability distribution, variable access to `OrderedDict` will not count against
    the maximum limit of variable access, and invoking `OrderedDict` constructor calls
    will not count against the maximum limit of function/method calls. In order to
    neuter the impact of code injection, please ensure that `OrderedDict` refers to
    the standard library's `collections.OrderedDict` within the `eval()` scope before
    passing the command string to `eval()` for execution. This can be done in code review.
    é   c                 ó$  — t        «       | _        d| _        d| _        d| _        || _        	 t        j                  |d¬«      | _        | j                  «        y # t        t        f$ r& | j                  t        j                  «       «       Y y w xY w)Nr   Úeval)Úmode)ÚsetÚ_errorsÚ_function_call_countÚ_attribute_access_countÚ_variable_access_countÚ_commandÚastÚparseÚ_treeÚ	_validateÚSyntaxErrorÚ
ValueErrorÚ
_log_errorÚ	tracebackÚ
format_exc)ÚselfÚcommands     úXC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\faker/sphinx/validator.pyÚ__init__zSampleCodeValidator.__init__E   sx   € Ü“uˆŒØ$%ˆÔ!Ø'(ˆÔ$Ø&'ˆÔ#ØˆŒð	ÜŸ™ 7°Ô8ˆDŒJð �N‰NÕøô œZÐ(ò 	4Ø�O‰OœI×0Ñ0Ó2Ö3ð	4ús   ­A Á2BÂBc                 ó   — | j                   S ©N)r   ©r   s    r   ÚerrorszSampleCodeValidator.errorsS   s   € à�|‰|Ðó    c                 ó.   — t        || j                  «      S r   )Ú
isinstanceÚ_whitelisted_nodes)r   Únodes     r   Ú_is_whitelistedz#SampleCodeValidator._is_whitelistedW   s   € Ü˜$ × 7Ñ 7Ó8Ð8r!   c                 ó:   — | j                   j                  |«       y r   )r   Úadd)r   Úmsgs     r   r   zSampleCodeValidator._log_errorZ   s   € Ø�‰×Ñ˜Õr!   c                 ó:   — | j                  | j                  «       y r   )Úvisitr   r   s    r   r   zSampleCodeValidator._validate]   s   € Ø�
‰
�4—:‘:Õr!   c                 óê   — d}t        |t        j                  «      r| j                  |j                  «      }|S t        |t        j
                  «      r|j                  t        j                  k(  rd}|S )NFT)	r#   r   ÚCallÚ_is_node_using_ordereddictÚfuncÚNameÚidr   Ú__name__)r   r%   Úis_valids      r   r.   z.SampleCodeValidator._is_node_using_ordereddict`   s]   € Øˆô �dœCŸH™HÔ%Ø×6Ñ6°t·y±yÓAˆHð ˆô ˜œcŸh™hÔ'¨D¯G©G´{×7KÑ7KÒ,KØˆHàˆr!   c                 ó˜   •— | j                  |«      s*d|j                  j                  z  }| j                  |«       t        ‰| �  |«      S )Nz!Code element `%s` is not allowed.)r&   Ú	__class__r2   r   Úsuperr+   )r   r%   r)   r5   s      €r   r+   zSampleCodeValidator.visitm   s@   ø€ à×#Ñ# DÔ)Ø5¸¿¹×8OÑ8OÑOˆCØ�O‰O˜CÔ ä‰w‰}˜TÓ"Ð"r!   c                 óÌ   — | j                  |«      sB| j                  | j                  k  r| xj                  dz  c_        nd}| j                  |«       | j	                  |«       y )Nr   z9There can only be one instance of a function/method call.)r.   r   Ú_max_function_call_countr   Úgeneric_visit©r   r%   r)   s      r   Ú
visit_CallzSampleCodeValidator.visit_Callu   sV   € Ø×.Ñ.¨tÔ4à×(Ñ(¨4×+HÑ+HÒHØ×)Ò)¨QÑ.Ö)àQ�Ø—‘ Ô$ð 	×Ñ˜4Õ r!   c                 óª   — | j                   | j                  k  r| xj                   dz  c_         nd}| j                  |«       | j                  |«       y )Nr   z3There can only be one instance of attribute access.)r   Ú_max_attribute_access_countr   r9   r:   s      r   Úvisit_Attributez#SampleCodeValidator.visit_Attribute�   sH   € à×'Ñ'¨$×*JÑ*JÒJØ×(Ò(¨AÑ-Ö(àGˆCØ�O‰O˜CÔ ð 	×Ñ˜4Õ r!   c                 óÌ   — | j                  |«      sB| j                  | j                  k  r| xj                  dz  c_        nd}| j                  |«       | j	                  |«       y )Nr   z2There can only be one instance of variable access.)r.   r   Ú_max_variable_access_countr   r9   r:   s      r   Ú
visit_NamezSampleCodeValidator.visit_NameŒ   sV   € Ø×.Ñ.¨tÔ4à×*Ñ*¨T×-LÑ-LÒLØ×+Ò+¨qÑ0Ö+àJ�Ø—‘ Ô$ð 	×Ñ˜4Õ r!   )#r2   Ú
__module__Ú__qualname__Ú__doc__r   Ú
Expressionr-   Ú	Attributer0   ÚLoadÚkeywordÚNumÚStrÚBytesÚListÚTupleÚSetÚDictÚNameConstantr$   r8   r=   r@   r   Úpropertyr    r&   r   r   r.   r+   r;   r>   rA   Ú__classcell__)r5   s   @r   r   r      sÌ   ø„ ñ$ðP 	�‰Ø�‰Ø�‰Ø�‰Ø�‰Ø�‰à�‰Ø�‰Ø�	‰	Ø�‰Ø�	‰	Ø�‰Ø�‰Ø×Ñð!Ðð&  !ÐØ"#ÐØ!"Ðòð ñó ðò9òòòô#ò
!ò	!ö
!r!   r   )r   r   Úcollectionsr   ÚNodeVisitorr   © r!   r   Ú<module>rV      s    ðÛ 
Û å #ôO!˜#Ÿ/™/õ O!r!   