
66ic           @  s   d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l	 Z	 d  d l
 Z
 d  d l m Z m Z d  d l Z e j Z d Z e j   Z d Z d Z d e f d     YZ d	   Z d
 e f d     YZ d S(   i(   t   print_functionN(   t   loadst   dumpsi   s
   RENPY RPC2s   cache/bytecode.rpybt   ScriptErrorc           B  s   e  Z d  Z RS(   sa   
    Exception that is raised if the script is somehow inconsistent,
    or otherwise wrong.
    (   t   __name__t
   __module__t   __doc__(    (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR   8   s   c         C  s+   g  } x |  D] } | j  | j  q W| S(   sO   
    Returns a flat list containing every statement in the tree
    stmts.
    (   t   get_childrent   append(   t   stmtst   rvt   i(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   collapse_stmts?   s    t   Scriptc           B  s   e  Z d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z	 d   Z
 d	 d
  Z e d d  Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z d   Z RS(   sk  
    This class represents a Ren'Py script, which is parsed out of a
    collection of script files. Once parsing and initial analysis is
    complete, this object can be serialized out and loaded back in,
    so it shouldn't change at all after that has happened.

    @ivar namemap: A map from the name of an AST node to the AST node
    itself.  This is used for jumps, calls, and to find the current
    node when loading back in a save. The names may be strings or
    integers, strings being explicit names provided by the user, and
    integers being names synthesised by renpy.

    @ivar initcode: A list of priority, Node tuples that should be
    executed in ascending priority order at init time.

    @ivar all_stmts: A list of all statements, that have been found
    in every file. Useful for lint, but tossed if lint is not performed
    to save memory.

    c         C  s  |  t  j _ t j j t  j j d  rM t t  j j d d  j	   |  _
 n	 d |  _
 i  |  _ g  |  _ g  |  _ g  |  _ t |  _ i  |  _ i  |  _ t |  _ t  j j   |  _ |  j   |  j   |  j j   d |  _ t j t  j  |  _  t |  _! g  |  _" g  |  _# d S(   s   
        Loads the script by parsing all of the given files, and then
        walking the various ASTs to initialize this Script object.
        s	   /lock.txtt   rbi    N($   t   renpyt   gamet   scriptt   ost   patht   existst   configt
   renpy_baset   filet   readt   keyt   Nonet   namemapt	   all_stmtst
   all_pycodet   need_analysist   Truet   record_pycodet   bytecode_oldcachet   bytecode_newcachet   Falset   bytecode_dirtyt   translationt   ScriptTranslatort
   translatort   init_bytecodet   scan_script_filest   chain_translatest   serialt   hashlibt   md5t   version_onlyt   digestt
   loaded_rpyt   backup_listt   duplicate_labels(   t   self(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   __init__c   s*    %									

			c         C  s   t  j r d  Sx- d d d g D] } t  j j |  r d  Sq Wd d  l } | j t  j j d  } | d  k rq d  St	 j
 j t  j j  } t  j	 j
 j t  j j |  t  j j |   } t  j j d |  | S(   Ns   script_version.txts   script_version.rpys   script_version.rpycit   backupss   Backing up script files to %r:(   R   t   mobileR   t   loadert   loadablet   __main__t   path_to_savesR   t   gamedirR   R   t   basenamet   basedirt   joint   exportst   fsencodet	   write_log(   R3   R   R9   R5   R<   t	   backupdir(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   choose_backupdir   s    	c   	      C  s  |  j  } g  |  _  t j j d d  d k r1 d  S|  j s> d  St j rK d  S|  j   } | d  k rg d  Sx| D]\ } } | j	 t j
 j  s qn n  t j j |  s qn n  t j j | t t j
 j  d  } t j j |  \ } } t j j | | d | d  j d  |  } t j j |  r1qn n  y  t j t j j |  d  Wn n Xy t j | |  Wqn qn Xqn Wd  S(	   Nt   RENPY_DISABLE_BACKUPSt    s   I take responsibility for this.i   t   .i   t   hexi  (   R1   R   t   environt   getR0   R   R6   RC   R   t
   startswithR   R;   R   R   R?   R@   t   lent   splitextR>   t   encodet   makedirst   dirnamet   shutilt   copy(	   R3   R1   RB   t   fnt   checksumt   short_fnt   baset   extt	   target_fn(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   make_backups   s>    				&	" c         C  s  t  j j   } g  |  _ g  |  _ x | D] \ } } | j d  rk | d k rU q( n  | d  } |  j } n | j d  r | d  } |  j } n_ | j d  r | d k r q( n  | d  } |  j } n( | j d  r( | d  } |  j } n q( | | f | k r( | j | | f  q( q( Wd S(	   s8   
        Scan the directories for script files.
        s   .rpyis   .rpycis   .rpyms   .rpymciN(   R   R7   t   listdirfilest   script_filest   module_filest   endswithR   R   (   R3   t   dirlistt   dirRR   t   target(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR)      s.    		



c         C  s   |  j  } | j   g  } x- | D]% \ } } |  j d d | | |  q  Wg  t |  D]! \ } \ } } | | | f ^ qV } | j   g  | D] \ } } } | | f ^ q |  _ d  S(   Ns   .rpycs   .rpy(   RZ   t   sortt   load_appropriate_filet	   enumeratet   initcode(   R3   RZ   Rc   RR   R^   t   indext   priot   code(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   load_script   s    	
1
c         C  s   g  |  j  D]$ \ } } | | k r
 | | f ^ q
 } | sM t d |   n  t |  d k rr t d |   n  | d \ } } g  } |  j d d | | |  t j j   r t d   n  |  j j	   | S(   Ns   Module %s could not be loaded.i   s-   Module %s ambiguous, multiple variants exist.i    s   .rpymcs   .rpymi(
   R[   t	   ExceptionRK   Ra   R   t   parsert   report_parse_errorst
   SystemExitR'   R*   (   R3   t   nameRR   R^   t   filesRc   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   load_module  s    4c         C  si   t  |  } t t j    } xD | D]< } | j d  k r% | | |  j f | _ |  j d 7_ q% q% Wd  S(   Ni   (   R   t   intt   timeRl   R   R+   (   R3   R	   RR   R   t   versiont   s(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   assign_names)  s    c         C  s   t  |  } t  |  } g  | D] } | j   ^ q } g  | D] } | j   ^ q> } t j d  | |  } xn | j   D]` \ } } }	 xN t |	  D]@ } | | | }
 | | | } | j d  k r |
 j | _ q q Wqx Wd  S(   N(   R   t	   diff_infot   difflibt   SequenceMatcherR   t   get_matching_blockst   rangeRl   (   R3   t	   old_stmtst	   new_stmtsR   t   old_infot   new_infot   smt   oldlt   newlt   countt   oldt   new(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   merge_names5  s    i   c         C  sm   t  j j | | d | } | d k r+ d S|  j | |  |  j |  g  } |  j | | t  } | | f S(   s9  
        Loads Ren'Py script from a string.

        `filename`
            The filename that's assigned to the data.

        `filedata`
            A unicode string to be loaded.

        Return the list of statements making up the root block, and a
        list of init statements that need to be run.
        t
   linenumberN(   NN(   R   Ri   t   parseR   Rs   t   static_transformst   finish_loadR#   (   R3   t   filenamet   filedataR   R	   Rc   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   load_stringG  s    c         C  sT  | s
 | St  j j | d  g  } x | D] } | j | j  q* W|  j j |  | d k	 r t  j j	 |  } | d j
 j   j | j    s | d 7} x | D] } | | _
 q Wq n  | rt  j rd } d } d }	 x | D] }
 |
 j } | |  j k r| } |
 } |  j | }	 t | t  sat d t |  |	 j
 |	 j | j
 | j f   q|  j j d j | |	 j
 |	 j | j
 | j   n  |
 |  j | <q Wn  |  j   xh | D]` }
 |
 j } |
 |  j | <|
 j r|
 j   } | r| j |  qn  |
 j r|
 j   qqW|  j d k	 r@|  j j |  n  |  j j |  | S(   s  
        Given `stmts`, a list of AST nodes comprising the root block,
        finishes loading it.

        `initcode`
            A list we append init statements to.

        `check_names`
            If true, produce duplicate name errors.

        `filename`
            If given, a filename that overrides the filename found inside the
            file.

        Returns a list of statements that corresponds to the top-level block
        in initcode after transformation.
        i    t   cs-   Name %s is defined twice, at %s:%d and %s:%d.uP   The label {} is defined twice, at
  File "{}", line {} and
  File "{}", line {}.N(   R   t   astt   chain_blockR   R   R   R'   t   take_translatesRi   t   elide_filenameR   t   lowerR\   R6   Rl   R   t
   isinstancet
   basestringR   t   reprR   R2   t   formatt   update_bytecodet   get_initt   early_executeR   t   extendR   (   R3   R	   Rc   t   check_namesR   R   R   t   bad_namet   bad_nodet   old_nodet   nodeRl   t   init(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR   c  s\    "
			%
			c         C  sG   | j  t  x3 t d  D]% } | j  t j d d d d   q Wd S(   sU   
        Writes an empty version 2 .rpyc header to the open binary file `f`.
        i   t   IIIi    N(   t   writet   RPYC2_HEADERRx   t   structt   pack(   R3   t   ft   _i(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   write_rpyc_header  s    c         C  s   | j  d d  | j   } t j | d  } | j |  | j  t t  d | d d  | j t j d | | t |    | j  d d  d S(   s   
        Writes data into `slot` of a .rpyc file. The data should be a binary
        string, and is compressed before being written.
        i    i   i	   i   i   R   N(	   t   seekt   tellt   zlibt   compressR   RK   R   R   R   (   R3   R   t   slott   datat   start(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   write_rpyc_data  s    "%c         C  s!   | j  d d  | j |  d S(   s<   
        Writes the md5 to the end of a .rpyc file.
        i    i   N(   R   R   (   R3   R   R/   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   write_rpyc_md5  s    c   	      C  s   | j  d  } | t t   t k r[ | d k r5 d S| j d  | j    } | j d  St t  } xZ t r t j d | | | d ! \ } } } | | k r Pn  | d k r d S| d 7} qj W| j |  | j  |  } t	 j
 |  S(   s   
        Reads the binary data from `slot` in a .rpyc (v1 or v2) file. Returns
        the data if the slot exists, or None if the slot does not exist.
        i   i   i    R   R   i   N(   R   RK   R   R   R   t   decodeR   R   t   unpackR   t
   decompress(	   R3   R   R   t   header_dataR   t   post   header_slotR   t   length(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   read_rpyc_data  s$    	&c         C  s   t  j j |  d S(   s   
        This performs transformations on the script that can be performed
        statically. When possible, these transforms are stored in slot 2
        of the rpyc file.
        N(   R   R%   t   restructure(   R3   R	   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR     s    c         C  si  | j  d  s | j  d  r| s7 t d |   n  | d | } | d } t j j |  } i  } t | d <|  j p} d | d <| d  k r | g  f Szm y_ t |  _	 t
 | d	   } |  j | d
  } Wd  QXt |  \ }	 }
 |  j |
 |  ~	 ~
 Wn n XWd  t |  _	 X|  j | |  t j s|yB t | d  } |  j |  |  j | d
 t | | f d   Wq|q|Xn  |  j |  t j sys |  j | d t | | f d   t
 | d  " } t j | j    j   } Wd  QX|  j | |  | j   WqqXn  t |  _ nA| j  d  s<| j  d  r[d  } d  } t j j |  } z xa d d
 g D]O } y2 |  j | |  } | rt |  \ } } Pn  Wn n X| j d  qjWd S| d  k rt  d |  d St! | t"  sd S|  j r| j# d d  |  j k rd S| d t k r-d S| d k  rI|  j |  n  Wd  | j   Xn d S| | f S(   Ns   .rpys   .rpyms4   Cannot load rpy/rpym file %s from inside an archive.t   /R   Rq   t   unlockedR   R   i   t   wbi   t   rUs   .rpycs   .rpymci    s   Failed to load(   NN(   NN(   NN(   NN(   NN(   NN($   R\   Rh   R   Ri   R   t   script_versionR   R   R#   R    t   openR   R   R   R   Rs   t   macappR   R   R   R   R   R,   R-   R   R/   R   t   closeR0   R7   t   loadR   t   printR   t   dictRI   (   R3   R^   RR   t   fullfnt   rpycfnR	   R   t   rpycft   bindatat   old_dataRy   R   t   fullft	   rpydigestR   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt	   load_file  s    


 	
	&	"!$c         C  s  | d  k r | | } | | } |  j | | |  \ } }	 | d  k r^ t d | f   n  t j j | |  }
 |
 j t j   j	 d  |
 j
 t j   j	  } |
 j   n| d | | } | d | | } t j j |  t j j |  r/t | d  " }
 t j |
 j
    j   } Wd  QXn d  } yi t j j |  rt | d  9 }
 |
 j t j   j	 d  |
 j
 t j   j	  } Wd  QXn d  } Wn d  } n Xt j j |  rt j j |  rt j j j } | } d \ } }	 yS | | k rE| rE|  j | | |  \ } }	 | d  k rEt d |  qEn  Wn) d t j k rrt d |    qrn X| d  k r|  j | | |  \ } }	 n  | } nz t j j |  r| } |  j | | |  \ } }	 | } n= t j j |  r | } |  j | | |  \ } }	 | } n  |  j j | | f  | d  k rUt d	 |   n  |  j d  k rt| d
 |  _ n& |  j | d
 k rt | d   n  |  j |	 | d | | |  j j |  d  S(   Ns   Could not load from archive %s.i   R   R   R   s   Could not load t   RENPY_RPYC_EXCEPTIONSs   While loadings   Could not load file %s.R   s{    does not share a key with at least one .rpyc file. To fix, delete all .rpyc files, or rerun Ren'Py with the --lock option.R   (   NN(   R   R   Rh   R   R7   R   R   R,   R-   t   digest_sizeR   R   t   add_autoR   R   R   R   R/   R   t   argst   compileR   RH   R1   R   R   R   t   update(   R3   t   compiledt   sourceR^   RR   Rc   t   rpyfnt   lastfnR   R	   R   R/   R   R   t
   rpycdigestt   force_compile(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyRa     sv    

$!

$			c         C  sW   yI t  t j j t  j   j d   \ } } | t k rH | |  _ n  Wn n Xd S(   s0   
        Init/Loads the bytecode cache.
        R   N(	   R   R   R7   R   t   BYTECODE_FILER   R   t   BYTECODE_VERSIONR!   (   R3   Rq   t   cache(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR(     s    -c         C  s  x|  j  D]} | j   t } |  j j | d  } | d k rt |  _ t j	 j
 } d | j d | j d f t j	 _
 y | j d k r t j j | j d | j d d | j d } nA | j d k r t j j | j d | j d d | j d } n  Wn t k
 r} | j } | d k r0d } n  y | j d	  } Wn | j d
  } n Xt j j d | j d | j d | j d | d | j  } t j j j | j  q
 n X| t j	 _
 n  | |  j | <t j |  | _  q
 Wg  |  _  d S(   sy   
        Compiles the PyCode objects in self.all_pycode, updating the
        cache. Clears out self.all_pycode.
        s7   While compiling python block starting at line %d of %s.i   i    t   execR   t   linenot   evalRE   s   utf-8s   latin-1t   numbert   msgt   lineR   N(!   R   t   get_hasht   MAGICR!   RI   R   R   R$   R   R   t   exception_infot   locationt   modet   pythont   py_compile_exec_bytecodeR   t   py_compile_eval_bytecodet   SyntaxErrort   textR   Ri   t
   ParseErrorR   R   R   t   offsett   parse_errorsR   t   messageR"   t   marshalR   t   bytecode(   R3   R   R   Rf   t   old_eit   eR   t   pem(    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR     s@    	$26					c         C  s   t  j r d  S|  j r y\ t  j j t  } t | d  5 } t |  j f } | j	 t
 | d  j d   Wd  QXWq q Xn  d  S(   NR   i   R   (   R   R   R$   R7   t   get_pathR   R   R   R"   R   R   RM   (   R3   RR   R   R   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   save_bytecode<  s    		)c         C  s   t  j j j | |  } | } |  j j | d  } | d k r{ t  j j d k	 r{ t  j j |  } |  j j | d  } n  | d k r t d t |    n  |  j | S(   sp   
        Looks up the given label in the game. If the label is not found,
        raises a ScriptError.
        s   could not find label '%s'.N(	   R   R   t   label_overridesRI   R   R   t   missing_label_callbackR   t   str(   R3   t   labelt   originalR
   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   lookupJ  s    c         C  s%   t  j j j | |  } | |  j k S(   sG   
        Returns true if the label exists, or false otherwise.
        (   R   R   R   RI   R   (   R3   R   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt	   has_label^  s    c         C  s+   x |  j  D] } | j   q
 Wg  |  _  d S(   s=   
        Analyzes all statements that need analysis.
        N(   R   t   analyze(   R3   R   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR   g  s    c         C  sQ   t  j j s d  St  j j r  d  S|  j t  j _ t  j j   rM t d   n  d  S(   Ni(	   R   R   t	   developert   ignore_duplicate_labelsR2   Ri   R   Rj   Rk   (   R3   (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   report_duplicate_labelsq  s    N(   R   R   R   R4   RC   RX   R)   Rg   Rn   Rs   R   R   R   R   R   R   R   R   R   R   R   Ra   R(   R   R   R   R   R   R   (    (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyR   M   s2   	-		/	)				c	
			(	
	u	e		:					
(   t
   __future__R    R   R,   R   t   impRu   Rp   R   R   R   t   cPickleR   R   RP   R   R   t	   get_magicR   R   R   Rh   R   R   t   objectR   (    (    (    s[   Z:\home\souce\.local\share\Steam\steamapps\common\Doki Doki Literature Club\renpy\script.pyt   <module>   s&   		