B
    b                 @   sZ   d Z ddlZi aG dd dejjZG dd dejjZG dd dejjZ	dd	d
Z
dS )zPython nodes.    Nc               @   s2   e Zd ZdZdZdgZdd Zdd Zdd	 Zd
S )ValueNodeInfo)csig   r   c             C   s   t |S )N)ValueWithMemo)selfs r   0lib/python3.7/site-packages/SCons/Node/Python.pystr_to_node%   s    zValueNodeInfo.str_to_nodec             C   s   t | di  }xBt|  D ]2}x,t |ddD ]}t| |r0t | |||< q0W qW | j|d< y
|d= W n tk
r|   Y nX |S )a0  
        Return all fields that shall be pickled. Walk the slots in the class
        hierarchy and add those to the state dictionary. If a '__dict__' slot
        is available, copy all entries to the dictionary. Also include the
        version id, which is fixed for all instances of a class.
        __dict__	__slots__r   _version_id__weakref__)getattrcopytypemrohasattrcurrent_version_idKeyError)r   stateobjnamer   r   r	   __getstate__(   s    


zValueNodeInfo.__getstate__c             C   s4   |d= x(|  D ]\}}|dkrt| || qW dS )z>
        Restore the attributes from a pickled state.
        r   )r   N)itemssetattr)r   r   keyvaluer   r   r	   __setstate__=   s    zValueNodeInfo.__setstate__N)	__name__
__module____qualname__r   r   Z
field_listr
   r   r   r   r   r   r	   r      s   r   c               @   s   e Zd ZdZdZdS )ValueBuildInfor   r   N)r   r    r!   r   r   r   r   r   r	   r"   H   s   r"   c                   s   e Zd ZdZeZeZd fdd	Zdd Z	dd Z
d	d
 Zdd ZejjjZdd Zdd Zdd ZedddZedddZdddZ  ZS )ValuezA class for Python variables, typically passed on the command line
    or generated by a script, but not from a file or some other source.
    Nc                sD   t    || _d| _d| _|d k	r*|| _|r6|| _n
t|| _d S )N   r   )super__init__r   Zchanged_since_last_buildZ
store_infobuilt_valuer   str)r   r   r'   r   )	__class__r   r	   r&   U   s    
zValue.__init__c             C   s
   t | jS )N)reprr   )r   r   r   r	   str_for_displayd   s    zValue.str_for_displayc             C   s
   t | jS )N)r(   r   )r   r   r   r	   __str__g   s    zValue.__str__c             C   s   |    d S )N)get_csig)r   r   r   r	   
make_readyj   s    zValue.make_readyc             K   s    t | dstjjj| f| d S )Nr'   )r   SConsNodebuild)r   kwr   r   r	   r1   m   s    
zValue.buildc             C   s   dS )N   r   )r   dirr   r   r	   is_unders   s    zValue.is_underc             C   s
   || _ dS )zSet the value of the node.N)r'   )r   r'   r   r   r	   writey   s    zValue.writec             C   s    |    t| ds| j| _| jS )z3Return the value. If necessary, the value is built.r'   )r1   r   r   r'   )r   r   r   r	   read}   s    
z
Value.read)returnc             C   s.   t | j}x| dD ]}||  }qW |S )a2  By the assumption that the node.built_value is a
        deterministic product of the sources, the contents of a Value
        are the concatenation of all the contents of its sources.  As
        the value need not be built when get_contents() is called, we
        cannot use the actual node.built_value.N)r(   r   Zchildrenr-   )r   contentsZkidr   r   r	   get_text_contents   s    
zValue.get_text_contentsc             C   s   |    S )z(Get contents for signature calculations.)r:   encode)r   r   r   r	   get_contents   s    zValue.get_contentsc             C   s4   y| j jS  tk
r   Y nX |  }||  _|S )zBecause we're a Python value node and don't have a real
        timestamp, we get to ignore the calculator and just use the
        value contents.

        Returns string. Ideally string of hex digits. (Not bytes)
        )Zninfor   AttributeErrorr:   Z	get_ninfo)r   Zcalcr9   r   r   r	   r-      s    
zValue.get_csig)NN)N)r   r    r!   __doc__r   ZNodeInfor"   Z	BuildInfor&   r+   r,   r.   r1   r/   r0   Zchildren_are_up_to_dateZis_up_to_dater5   r6   r7   r(   r:   bytesr<   r-   __classcell__r   r   )r)   r	   r#   M   s   
r#   c             C   sv   |rt | ||dS yt| |f}W n tk
r>   t | |dS X yt| S  tk
rp   t | ||}|t|< |S X dS )z(
    Memoized Value() node factory.
    )r   N)r#   hash	TypeError_memo_lookup_mapr   )r   r'   r   Zmemo_lookup_keyvr   r   r	   r      s    r   )NN)r>   Z
SCons.Noder/   rC   r0   ZNodeInfoBaser   ZBuildInfoBaser"   r#   r   r   r   r   r	   <module>   s   )Z