³ò
~×YKc           @   s»   d  d k  Z  d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k Z d  d k l Z l	 Z	 e  i
 Z
 d Z d e f d „  ƒ  YZ d „  Z d e f d „  ƒ  YZ d	 „  Z d S(
   iÿÿÿÿN(   t   loadst   dumpsi   t   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__(    (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR   *   s   c            s&   g  ‰  ‡  ‡ f d †  ‰ ˆ |  ƒ ˆ  S(   sO   
    Returns a flat list containing every statement in the tree
    stmts.
    c            s2   ˆ  i  |  ƒ x |  D] } ˆ | i ƒ  ƒ q Wd  S(   N(   t   extendt   get_children(   t
   block_listt   i(   t	   all_stmtst
   extend_all(    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR   8   s     (    (   t   stmts(    (   R
   R   s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   collapse_stmts0   s    
t   Scriptc           B   sz   e  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(   so  
    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  i i i |  _ |  i d
 j oG t i i t  i	 i
 d ƒ o& t t  i	 i
 d d ƒ i ƒ  |  _ qi n h  |  _ g  |  _ g  |  _ h  |  _ h  |  _ t |  _ |  i ƒ  t  i i ƒ  } g  } g  |  _ xÿ | D]÷ \ } } | i d ƒ o( | d
 j o qÎ n | d  } | } nŠ | i d ƒ o | d  } | } nf | i d ƒ o+ | d
 j o qÎ n | d  } |  i } n+ | i d ƒ o | d	  } |  i } n qÎ | | f | j o | i | | f ƒ qÎ qÎ W| i ƒ  g  } x- | D]% \ } } |  i d d | | | ƒ qàWg  } t | ƒ D]" \ } \ }	 }
 | |	 | |
 f q~ } | i ƒ  g  } | D] \ }	 } }
 | |	 |
 f qZ~ |  _ 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   rbs   .rpyiüÿÿÿs   .rpyciûÿÿÿs   .rpyms   .rpymciúÿÿÿN(   t   renpyt   gamet   optionst   lockt   keyt   Nonet   ost   patht   existst   configt
   renpy_baset   filet   readt   namemapR
   t
   all_pycodet   bytecode_oldcachet   bytecode_newcachet   Falset   bytecode_dirtyt   init_bytecodet   loadert   listdirfilest   module_filest   endswitht   appendt   sortt   load_appropriate_filet	   enumeratet   initcode(   t   selft   dirlistt   script_filest   dirt   fnt   targetR,   t   _[1]t   indext   priot   codet   _[2](    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   __init__[   sX    *						
	 






 5
c         C   sÖ   g  } |  i  D]* \ } } | | j o | | | f q q ~ } | p t d | ƒ ‚ n t | ƒ d j o t d | ƒ ‚ n | d \ } } g  } |  i d d | | | ƒ t i i ƒ  o t d ƒ ‚ n | S(   Ns   Module %s could not be loaded.i   s-   Module %s ambiguous, multiple variants exist.i    s   .rpymcs   .rpymiÿÿÿÿ(   R&   t	   Exceptiont   lenR*   R   t   parsert   report_parse_errorst
   SystemExit(   R-   t   nameR3   R1   R0   t   filesR,   (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   load_module«   s    Ac         C   si   t  | ƒ } t t i ƒ  ƒ } d } x> | D]6 } | i d  j o  | | | f | _ | d 7} q+ q+ Wd  S(   Ni    i   (   R   t   intt   timeR>   R   (   R-   R   R1   R
   t   versiont   serialt   s(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   assign_names¿   s     c      	   C   sò   t  | ƒ } t  | ƒ } g  } | D] } | | i ƒ  q# ~ } g  } | D] } | | i ƒ  qJ ~ } t i d  | | ƒ } xp | i ƒ  D]b \ }	 }
 } xP t | ƒ D]B } | |	 | } | |
 | } | i d  j o | i | _ q¤ q¤ Wqˆ Wd  S(   N(   R   t	   diff_infot   difflibt   SequenceMatcherR   t   get_matching_blockst   rangeR>   (   R-   t	   old_stmtst	   new_stmtsR3   R	   t   old_infoR7   t   new_infot   smt   oldlt   newlt   countt   oldt   new(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   merge_namesÍ   s    ''  c   
   
   C   sS  | i  d ƒ p | i  d ƒ oT| p t d | ƒ ‚ n | d | } t i i | ƒ } h  } t | d <|  i p d | d <| d  j o | g  f Sn y3 |  i | | d ƒ \ } } |  i	 | | ƒ ~ Wn n X|  i
 | | ƒ y t i t | d	 ƒ i ƒ  ƒ i ƒ  } t | d | d d
 ƒ }	 |	 i t | | f d ƒ i d ƒ ƒ |	 i | ƒ |	 i ƒ  WqIqIXnÖ | i  d ƒ p | i  d ƒ o± t i i | ƒ }	 y% t |	 i ƒ  i d ƒ ƒ \ } } Wn
 ‚  n Xt | t ƒ p d Sn |  i o$ | i d d ƒ |  i j o d Sn | d t j o d Sn |	 i ƒ  n d S| | f S(   Ns   .rpys   .rpyms4   Cannot load rpy/rpym file %s from inside an archive.t   /RC   t   unlockedR   t   ct   rUt   wbi   t   zlibs   .rpycs   .rpymc(   NN(   NN(   NN(   NN(   R'   R9   R   R;   t   parset   script_versionR   R   t   load_file_coreRV   RF   t   md5R   R   t   digestt   writeR   t   encodet   closeR$   t   loadR    t   decodet
   isinstancet   dictt   get(
   R-   R0   R1   t   fullfnR   t   datat   old_dataRL   t	   rpydigestt   f(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR_   ß   sP     
$% %&c         C   s®  |  i  | | ƒ \ } } | d  j o t Sn |  i d  j o | d |  _ n) |  i | d j o t | d ƒ ‚ n t | ƒ } t i i | d  ƒ g  } x× | D]Ï } | i	 }	 |	 |  i
 j oB |  i
 |	 }
 t d t |	 ƒ |
 i |
 i | i | i f ƒ ‚ n | |  i
 |	 <| i ƒ  } | o | i | ƒ n |  i i | i ƒ  ƒ t | t i i ƒ o | i | ƒ q¢ q¢ W|  i ƒ  x | D] } | i ƒ  q†W|  i i | ƒ t S(   NR   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.s-   Name %s is defined twice: at %s:%d and %s:%d.(   R_   R   R!   R   R9   R   R   t   astt   chain_blockR>   R   R   t   reprt   filenamet
   linenumbert   get_initR(   R   R   t
   get_pycodeRg   t   EarlyPythont   update_bytecodet   early_executeR
   t   True(   R-   R0   R1   R,   Rk   R   R
   t   earlyt   nodeR>   RT   t   init(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt	   load_file  s@     		
 c         C   s  | d  j o< |  i | | | | ƒ p t d | | f ƒ ‚ n d  Sn | d | | } | d | | } t i i | ƒ oõ t i i | ƒ oâ t i t | d ƒ i ƒ  ƒ i	 ƒ  } t | d ƒ }	 |	 i
 t i d ƒ |	 i t i ƒ }
 |	 i ƒ  | |
 j o@ t i i i o/ |  i | | | | ƒ o d  Sn d | GHn |  i | | | | ƒ p t d | ƒ ‚ qÿn‹ t i i | ƒ o2 |  i | | | | ƒ p t d | ƒ ‚ qÿnF t i i | ƒ o2 |  i | | | | ƒ p t d | ƒ ‚ qÿn d  S(   Ns!   Could not load from archive %s.%sRW   RZ   R   i   s   Could not load s   Could not load file %s.(   R   R}   R9   R   R   R   R`   R   R   Ra   t   seekt   digest_sizeRd   R   R   R   t   compile(   R-   t   compiledt   sourceR0   R1   R,   t   rpyfnt   rpycfnRm   Rn   t
   rpycdigest(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR*   _  s0    &$
c         C   sY   yK t  t i i d ƒ i ƒ  i d ƒ ƒ \ } } | t j o | |  _ n Wn n Xd S(   s0   
        Init/Loads the bytecode cache.
        s   bytecode.rpybR\   N(   R    R   R$   Re   R   Rf   t   BYTECODE_VERSIONR   (   R-   RC   t   cache(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR#   †  s    -c         C   sW  t  i ƒ  } x;|  i D]0} |  i i | i h  ƒ } | | j o | | } nÖ t |  _ t i	 i
 } d | i d | i d f t i	 _
 | i d j o3 t i i | i d | i d d | i d ƒ} nD | i d j o3 t i i | i d | i d d | i d ƒ} n | t i	 _
 | | | <d | _ | | _ | |  i | i <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   execRr   t   linenot   evalN(   t   impt	   get_magicR   R   Ri   t   locationRy   R"   R   R   t   exception_infot   modet   pythont   py_compile_exec_bytecodeR‚   t   py_compile_eval_bytecodeR   t   bytecodeR    (   R-   t   magicR	   t   codesR6   t   old_ei(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyRw   ”  s&    
 	$33
		c         C   s€   |  i  or yd t |  i f } t t i i t i i	 d d ƒ d ƒ } | i
 t | d ƒ i d ƒ ƒ | i ƒ  Wq| q| Xn d  S(   Ni    s   bytecode.rpybR[   i   R\   (   R"   R†   R    R   R   R   t   joinR   R   t
   searchpathRb   R   Rc   Rd   (   R-   Rk   Rn   (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   save_bytecode¼  s    
(c         C   sM   t  i i i | | ƒ } | |  i j o t d t | ƒ ƒ ‚ n |  i | 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'.(   R   R   t   label_overridesRi   R   R   t   str(   R-   t   label(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   lookupÉ  s    c         C   s%   t  i i i | | ƒ } | |  i j S(   sG   
        Returns true if the label exists, or false otherwise.
        (   R   R   Rš   Ri   R   (   R-   Rœ   (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt	   has_labelÖ  s    (   R   R   R   R8   R@   RF   RV   R_   R}   R*   R#   Rw   R™   R   Rž   (    (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyR   E   s   	P				@	@	'		(		c          C   s   t  ƒ  }  |  S(   N(   R   (   t   rv(    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pyt   load_scriptß  s    	(   R   t   os.pathR   R‹   RH   R`   RB   t   cPickleR    R   R^   R†   R9   R   R   t   objectR   R    (    (    (    s4   D:\Version 1-0-7\Games\Katawa Shoujo\renpy\script.pys   <module>   s   		ÿ ›