3
O6b                  @   s0   d Z ddlmZmZmZmZ G dd deZdS )z0Tools for representing JavaScript code in BSON.
    )abcstring_typePY3	text_typec               @   sF   e Zd ZdZdZdddZedd Zdd	 Zd
d Z	dZ
dd ZdS )Codea  BSON's JavaScript code type.

    Raises :class:`TypeError` if `code` is not an instance of
    :class:`basestring` (:class:`str` in python 3) 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 ``{}``.

       Nc             K   s   t |tstdtj t r<t |tr<tj| |jd}ntj| |}y|j	|_
W n tk
rn   d |_
Y nX |d k	rt |tjstd|j
d k	r|j
j| n||_
|r|j
d k	r|j
j| n||_
|S )Nzcode must be an instance of %sutf8z!scope must be an instance of dict)
isinstancer   	TypeError__name__r   r   str__new__encodescope_Code__scopeAttributeErrorr   Mappingupdate)clscoder   kwargsself r   H/var/www/html/sandeepIITI/myenv/lib/python3.6/site-packages/bson/code.pyr   3   s*    



zCode.__new__c             C   s   | j S )z8Scope dictionary for this instance or ``None``.
        )r   )r   r   r   r   r   R   s    z
Code.scopec             C   s   dt j| | jf S )NzCode(%s, %r))r   __repr__r   )r   r   r   r   r   X   s    zCode.__repr__c             C   s*   t |tr&| jt| f|jt|fkS dS )NF)r	   r   r   r   )r   otherr   r   r   __eq__[   s    
zCode.__eq__c             C   s
   | |k S )Nr   )r   r   r   r   r   __ne__b   s    zCode.__ne__)N)r   
__module____qualname____doc__Z_type_markerr   propertyr   r   r   __hash__r   r   r   r   r   r      s   
r   N)r    Zbson.py3compatr   r   r   r   r   r   r   r   r   r   <module>   s   