a
    VŸ$cl  ã                   @   s¤   d dl mZmZmZmZmZ d dlmZmZm	Z	m
Z
mZmZmZmZmZmZmZmZ d dlZd dlZd dlZd dlZd dlZg Zg Zg Zi Zdd„ Zdadd„ ZdS )	é    )ÚdivisionÚabsolute_importÚwith_statementÚprint_functionÚunicode_literals)ÚPY2Ú
basestringÚbchrÚbordÚchrÚopenÚpystrÚrangeÚroundÚstrÚtobytesÚunicodeNc                 C   s8   t  | d ¡}|d u r4tj | ¡}tj |¡}|t | < |S )N)Úfile_exists_cacheÚgetÚrenpyÚparserÚunelide_filenameÚosÚpathÚexists)ÚfnÚrvÚfullfn© r   úrenpy/dump.pyÚfile_exists0   s    r    Fc                    s$  t jj‰ trdS daˆ jsdS ‡ fdd„}i }| |d< t jjt jjg|d< t jj|d< t jj	|d< i }||d	< i  }|d
< t jj
j ¡ D ]8\}}|j}|j}t|tƒs¨qˆ|||ƒs´qˆ||g||< qˆi  }	|d< tD ]"\}}}|||ƒsèqÒ||g|	|< qÒi  }
|d< tD ](\}}}|||ƒs q||g|
|< qi  }|d< tD ](\}}}|||ƒsZq@||g||< q@‡fdd„‰i  }|d< tj ¡  ¡ D ]’\}}|du r¨q|dkr¸d}n"| d¡r|dd… d }nq|j ¡ D ]:\}}t |¡rnzXt |¡|krW qäˆ|ƒ\}}|du r.W qä|||ƒs@W qä||g||| < W n tyl   Y qäY n0 t |¡rä|j ¡ D ]˜\}}zrt |¡|kr¤W q„ˆ|ƒ\}}|du rÀW q„|||ƒsÒW q„|||ƒsäW q„||g||| d | < W n ty   Y q„Y n0 q„qäqzt jj  ¡ |d< W n tyN   Y n0 t j! "ˆ j¡}|dkr|d }t#r°t$|dƒ}t%  ||¡ W d  ƒ n1 s¤0    Y  n8t$|dƒ}t%  ||¡ W d  ƒ n1 sÞ0    Y  t&j' (|¡r t& )|¡ t& *||¡ nt%j |tj+dd dS )z”
    Causes a JSON dump file to be written, if the user has requested it.

    `error`
        An error flag that is added to the written file.
    NTc                    sn   |  dd¡}|  d¡r6ˆ js6|  d¡r2|  d¡r2ndS t|ƒsBdS | d¡sV| d¡r\ˆ jS | d¡sjdS d	S )
zf
        Returns true if the name is included by the name_filter, or false if it is excluded.
        ú\ú/Ú_Ú__Fzcommon/zrenpy/common/zgame/T)ÚreplaceÚ
startswithÚjson_dump_privateÚendswithr    Újson_dump_common)ÚnameÚfilename)Úargsr   r   Úname_filterT   s    
zdump.<locals>.name_filterÚerrorÚsizer*   ÚversionÚlocationÚlabelÚdefineÚscreenÚ	transformc                    s4   t  | ¡rt  | ¡| jjfS t  | ¡r0ˆ | jƒS dS )a"  
        Returns the filename and the first line number of the class or function o. Returns
        None, None if unknown.

        For a class, this doesn't return the first line number of the class, but rather
        the line number of the first method in the class - hopefully.
        )NN)ÚinspectÚ
isfunctionÚgetfileÚ__code__Úco_firstlinenoÚismethodÚ__func__)Úo)Úget_liner   r   r>   ¨   s
    	


zdump.<locals>.get_lineÚcallableÚstoreÚ zstore.é   Ú.Úbuildú-z.newÚwbÚwé   )Úindent),r   Úgamer,   Úcompleted_dumpÚ	json_dumpÚconfigÚscreen_widthÚscreen_heightr*   r0   ÚscriptÚnamemapÚitemsr+   Ú
linenumberÚ
isinstancer   ÚdefinitionsÚscreensÚ
transformsÚsysÚmodulesÚcopyr&   Ú__dict__r6   r7   Ú	getmoduleÚ	ExceptionÚisclassr@   rD   ÚdumpÚexportsÚfsdecoder   r   Újsonr   r   r   ÚunlinkÚrenameÚstdout)r.   r-   Úresultr1   r2   r*   Únr+   Úliner3   r4   r5   ÚcodeÚmodnameÚmodÚprefixr=   ÚmethnameÚmethodÚnewÚfr   )r,   r>   r   r_   @   s¸    








.,
r_   )Ú
__future__r   r   r   r   r   Úrenpy.compatr   r   r	   r
   r   r   r   r   r   r   r   r   r6   rb   rX   r   r   rU   rW   rV   r   r    rK   r_   r   r   r   r   Ú<module>   s   8