U
    dr                     @   s@   d Z ddlmZ ddlmZmZmZmZmZ G dd de	Z
dS )z/Tools for representing JavaScript code in BSON.    )Mapping)Anyr   OptionalTypeUnionc                   @   s   e Zd ZU dZdZeeeef df e	d< de
d  eed f eeeef  ed dddZeeeeef  dd	d
ZedddZeedddZdZee	d< eedddZdS )Codeam  BSON's JavaScript code type.

    Raises :class:`TypeError` if `code` is not an instance of
    :class:`str` or `scope` is not ``None`` or an instance
    of :class:`dict`.

    Scope variables can be set by passing a dictionary as the `scope`
    argument or by using keyword arguments. If a variable is set as a
    keyword argument it will override any setting for that variable in
    the `scope` dictionary.

    :Parameters:
      - `code`: A string containing JavaScript code to be evaluated or another
        instance of Code. In the latter case, the scope of `code` becomes this
        Code's :attr:`scope`.
      - `scope` (optional): dictionary representing the scope in which
        `code` should be evaluated - a mapping from identifiers (as
        strings) to values. Defaults to ``None``. This is applied after any
        scope associated with a given `code` above.
      - `**kwargs` (optional): scope variables can also be passed as
        keyword arguments. These are applied after `scope` and `code`.

    .. versionchanged:: 3.4
      The default value for :attr:`scope` is ``None`` instead of ``{}``.

       N_Code__scope)clscodescopekwargsreturnc                 K   s   t |tstdt| |}z|j|_W n tk
rD   d |_Y nX |d k	r~t |ts`td|jd k	rx|j| n||_|r|jd k	r|j| n||_|S )Nzcode must be an instance of strz!scope must be an instance of dict)	
isinstancestr	TypeError__new__r   r	   AttributeError_Mappingupdate)r
   r   r   r   self r   -/tmp/pip-unpacked-wheel-oblwsawz/bson/code.pyr   4   s$    



zCode.__new__)r   c                 C   s   | j S )z/Scope dictionary for this instance or ``None``.)r	   r   r   r   r   r   T   s    z
Code.scopec                 C   s   dt |  d| jdS )NzCode(z, ))r   __repr__r	   r   r   r   r   r   Y   s    zCode.__repr__)otherr   c                 C   s*   t |tr&| jt| f|jt|fkS dS )NF)r   r   r	   r   r   r   r   r   r   __eq__\   s    
zCode.__eq____hash__c                 C   s
   | |k S )Nr   r   r   r   r   __ne__c   s    zCode.__ne__)N)__name__
__module____qualname____doc__Z_type_markerr   r   r   r   __annotations__r   r   r   propertyr   r   boolr   r   r    r   r   r   r   r      s"   
 
 r   N)r$   collections.abcr   r   typingr   r   r   r   r   r   r   r   r   r   <module>   s   