
 Qc           @   s  d  Z  d d l Z d d l m Z d d l Z d d l Z d d l Z d d l m Z m Z d d l	 m
 Z
 m Z d d l m Z d d l m Z m Z d d l m Z e j d	  Z y d d
 l m Z WnM e k
 rZ e Z e j e  e j d  e j d  e j d  n Xd Z d Z d Z e
 j e
 _ e
 j  e
 _! e
 j" e
 _# e
 j$ e
 _% e j e _ e j& e _' e j$ e _% e j( e _) e j* e _+ d   Z, d   Z- e, e
 _. e- e
 _/ e, e _. e- e _/ d f  d     YZ0 e re j1 Z2 n e0 Z2 d e2 f d     YZ1 d e3 f d     YZ4 d e4 f d     YZ5 d e6 f d     YZ7 e e d  Z8 d   Z9 d   Z: d    Z; e e d!  Z< e e d"  Z= e e d#  Z> d$   Z? d%   Z@ eA d& k re jB d' ZC e jB d( ZD e> eC eD  n  d S()   sA  
Create, parse and write MS Windows Manifest files.
Find files which are part of an assembly, by searching shared and 
private assemblies.
Update or add manifest resources in Win32 PE files.

Commandline usage:
winmanifest.py <dstpath> <xmlpath>
Updates or adds manifest <xmlpath> as resource in Win32 PE file <dstpath>.
iN(   t   glob(   t   Nodet   minidom(   t   Documentt   Element(   t   compat(   t   hashlibt   architecture(   t   logs   PyInstaller.build.winmanifest(   t   winresources9   Cannot check for assembly dependencies - resource access s7   unavailable. To enable resource access, please install s(   http://sourceforge.net/projects/pywin32/s   x-wwt   nonei   c         C   sO   g  } xB |  j  D]7 } t | t  r | j | k rG | j |  qG q q W| S(   s9    Return child elements of type tagName if found, else [] (   t
   childNodest
   isinstanceR   t   tagNamet   append(   t   selfR   t   resultt   child(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   getChildElementsByTagName|   s    c         C   s=   x6 |  j  D]+ } t | t  r
 | j | k r5 | Sq
 q
 Wd S(   s>    Return the first element of type tagName if found, else None N(   R   R   R   R   t   None(   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   getFirstChildElementByTagName   s
    t   _Dummyc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR      s   t   Filec           B   sA   e  Z d  Z d d d d d d d d  Z d d  Z d   Z RS(   s5    A file referenced by an assembly inside a manifest. t    c      	   C   s   t  r t  j j |  |  n	 | |  _ t j j |  |  _ | rR | j   |  _	 n	 d  |  _	 t j j |  r | r t r t t | j    r |  j   n	 | |  _ | p g  |  _ | p g  |  _ | p g  |  _ | p g  |  _ d  S(   N(   R	   R   t   __init__t   filenamet   ost   patht   basenamet   namet   uppert   hashalgR   t   isfileR   t   hasattrt   lowert	   calc_hasht   hasht
   comClassest   typelibst   comInterfaceProxyStubst   windowClasses(   R   R   R!   R&   R'   R(   R)   R*   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR      s    			c         C   sk   t  |  j d  } | j   } | j   | r@ | j   |  _ n  t t |  j j    |  j	   |  _
 d S(   s  
        Calculate the hash of the file.
        
        Will be called automatically from the constructor if the file exists 
        and hashalg is given (and supported), but may also be called manually 
        e.g. to update the hash if the file has changed.
        
        t   rbN(   t   openR   t   readt   closeR    R!   t   getattrR   R$   t	   hexdigestR&   (   R   R!   t   fdt   buf(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR%      s    	
c         C   si   t  j d |  j  t j j | |  j  } t j j |  rQ t  j d |  | St  j d |  d  Sd  S(   Ns   Searching for file %ss   Found file %ss   No such file %s(	   t   loggert   infoR   R   R   t   joinR"   t   warnR   (   R   t
   searchpatht   fn(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   find   s    N(   R   R   t   __doc__R   R   R%   R9   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR      s   t   InvalidManifestErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR;      s   t   ManifestXMLParseErrorc           B   s   e  Z RS(    (   R   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR<      s   t   Manifestc           B   sm  e  Z d  Z d e e d d d d d d d d d d d d d  Z d e e d d d d d d d d d d d d d  Z d d d d d d d d  Z e d  Z	 d d d  Z
 d d d  Z e d d d  Z e d	  Z e d
  Z e d  Z e d  Z d   Z d e j d d  Z d d  Z d d d  Z d d e j d d  Z d d e j d d  Z RS(   s  
    Manifest constructor.
    
    To build a basic manifest for your application:
      mf = Manifest(type='win32', name='YourAppName', language='*', 
                    processorArchitecture='x86', version=[1, 0, 0, 0])
    
    To write the XML to a manifest file:
      mf.writexml("YourAppName.exe.manifest")
    or
      mf.writeprettyxml("YourAppName.exe.manifest")
    
    c         C   s   d  |  _ d  |  _ d |  _ | p* d d g |  _ | |  _ | |  _ | |  _ | |  _ | |  _	 | |  _
 | |  _ |	 |  _ d  |  _ d  |  _ | |  _ | |  _ | p g  |  _ g  |  _ | p g  |  _ | p g  |  _ d  S(   Nt   assemblyi   i    (   R   R   t   optionalt   manifestTypet   manifestVersiont   noInheritablet	   noInheritt   typeR   t   languaget   processorArchitecturet   versiont   publicKeyTokent   applyPublisherPolicyt   descriptiont   requestedExecutionLevelt   uiAccesst   dependentAssembliest   bindingRedirectst   filest   comInterfaceExternalProxyStubs(   R   RA   RB   RC   t   type_R   RE   RF   RG   RH   RJ   RK   RL   RM   RO   RP   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR      s(    																c         C   sr   |  j  j t | | | | | | | | |	 |
 | | | | |   |  j rn d j |  j | f  |  j  d _ n  d S(   sY   
        Shortcut for self.dependentAssemblies.append(Manifest(*args, **kwargs))
        t   :iN(   RM   R   R=   R   R5   (   R   RA   RB   RC   RQ   R   RE   RF   RG   RH   RJ   RK   RL   RM   RO   RP   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   add_dependent_assembly  s    
	
	R   c      	   C   s,   |  j  j t | | | | | | |   d S(   s$    Shortcut for manifest.files.append N(   RO   R   R   (   R   R   R!   R&   R'   R(   R)   R*   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   add_file(  s    c         C   s  g  } g  } |  j  d& k r | j |  j    d |  j  k r] | j |  j  j d  d  n  |  j  d' k r| | j d  n  |  j  d k r | j d  q n  | j |  j d   t j j t j	 d  d	  } t j j
 |  s t j d
 |  n  t j j | d  } t j j
 |  s1t j d
 |  n  | r|  j rt j   d( k  rt j j | d  } t j j
 |  st j d
 |  qq| } n  x$| D]} |  j } | ry| ryt }	 t j j
 |  ryt j d |  j t d |  t j   d) k  r0t j j | |  j t d | d  }
 n( t j j | |  j t d | d  }
 xt |
  D]} t j j |  st j d |  qen  t j d |  y t |  } Wn0 t k
 r} t j d |  t j |  qeXt j d  xc| j D]X} | j |  t  s| j r%qn  x-| j D]"} t j t j   rd j g  | d D]. } d j g  | D] } t! |  ^ qk ^ qX } d j g  | d D] } t! |  ^ q } t j d | |  n  | | d d k r/| | d d k r/| | d k r/t j d d j g  | D] } t! |  ^ q |  | d } t }	 q/q/WqWqeW|	 svt j d  qvqyn  g  } t j j
 |  r| j" t t j j | |  j# d | d |  d    n  |  j$ rt j j% |  j$  } | t& t' f k rhx d* D]^ } | j" t t j j | |  j( |    | j" t t j j | |  j( |  j( |    qWqx: d+ D]2 } | j" t t j j | | |  j( |    qoWxC d, D]8 } | j" t t j j | | |  j( |  j( |    qWn  t j d |  j# d | d |   x| D]} t j j |  sBt j d |  qn  t j j) t j j* |  d  } yT | j+ d  rt j d  |  t, | d g  } n t j d! |  t |  } Wn0 t k
 r} t j d" |  t j |  n X| j- |  rEt j j | |  } t j j
 |  sWt j d
 |  t j d#  g  Sn t j j% |  } | j |  xP |  j. pv| j. D]< } | j/ |  } | r| j |  qwt j d#  g  SqwW| SWqWt j d$  g  S(-   s   Search shared and private assemblies and return a list of files.
        
        If any files are not found, return an empty list.
        
        IMPORTANT NOTE: For the purpose of getting the dependent assembly 
        files of an executable, the publisher configuration (aka policy)
        should be ignored (which is the default). Setting ignore_policies=False 
        is only useful to find out which files are actually loaded at
        runtime.
        
        R   t   *t   neutralt   -i    s   en-ust   ent
   SystemRoott   WinSxSs   No such dir %st	   Manifestsi   t   Policiess,   Searching for publisher configuration %s ...RE   s   .policys	   .manifests   Not a file %ss   Found %ss   Could not parse file %ss/   Checking publisher policy for binding redirectst   .i   s&   Found redirect for version(s) %s -> %nis   Applying redirect %s -> %ss    Publisher configuration not usedRG   s   _*.manifests   .dlls   Searching for assembly %s ...s   Found manifest in %ss   Found manifest %ss   Could not parse manifest %ss   Assembly incompletes   Assembly not foundN(   NR   RU   s   neutral(   s   en-uss   en(   i   (   i   (   s   .dlls	   .manifest(   s   .dlls	   .manifest(   s   .dlls	   .manifest(0   RE   R   R   t   getlanguaget   splitR   R   R5   R   t   getenvt   isdirR3   R6   RG   t   syst   getwindowsversiont   FalseR4   t   getpolicyidt   TrueR    R"   t   ManifestFromXMLFilet	   Exceptiont   errort	   exceptionRM   t   same_idR?   RN   t   isEnabledFort   loggingt   INFOt   strt   extendt   getidR   t   dirnamet   LANGUAGE_NEUTRAL_NT5t   LANGUAGE_NEUTRAL_NT6R   R   t   splitextt   endswitht   ManifestFromResFilet
   startswithRO   R9   (   R   t   ignore_policiesRO   t	   languagest   winsxst	   manifestst   pcfilesRE   RG   t
   redirectedt   policiest   manifestptht   policyt   excR>   t   redirectt   partt   it   oldt   newt   pathst   dirnmt   extt
   assemblynmt   manifestt   assemblydirt   file_R8   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt
   find_files/  s     			
		?	#			
	)			c         C   s   |  j  s t j d  d Sg  } |  j r< | j |  j  n  | j |  j   |  j rh | j |  j  n  | sw |  j r | j d j g  | p |  j D] } t |  ^ q   n  | s |  j	   } n  | r | j |  n  d j |  S(   s  
        Return an identification string which uniquely names a manifest.

        This string is a combination of the manifest's processorArchitecture, 
        name, publicKeyToken, version and language.
        
        Arguments:
        version (tuple or list of integers) - If version is given, use it 
                                              instead of the manifest's 
                                              version.
        
        s   Assembly metadata incompleteR   R]   t   _(
   R   R3   R6   RF   R   RH   RG   R5   Ro   R^   (   R   RE   RG   t   idR   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyRq     s     			;c         C   sB   | s |  j  } n  | d k r> t t f | p6 t j   d k S| S(   s   
        Get and return the manifest's language as string.
        
        Can be either language-culture e.g. 'en-us' or a string indicating 
        language neutrality, e.g. 'x-ww' on Windows XP or 'none' on Vista 
        and later.
        
        R   RU   RV   i   N(   NR   RU   s   neutral(   i   (   RE   R   Rs   Rt   Rb   Rc   (   R   RE   t   windowsversion(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR^     s    	c         C   s
  |  j  s t j d  d Sg  } |  j r< | j |  j  n  g  } | j d  |  j r | j t |  j d   | j t |  j d   n  | j |  j   | j d j |   |  j r | j |  j  n  |  j r=| p t	 j
   d k r=| r| j d  q=| j d j g  |  j D] } t |  ^ q  n  | sX|  j d	 |  } n  | rn| j |  n  | j d  d
 j |  } |  j r| pt	 j
   d k  r| rt j j | d  } qt j j | d j g  |  j D] } t |  ^ q  } n  | S(   s4  
        Return an identification string which can be used to find a policy.

        This string is a combination of the manifest's processorArchitecture, 
        major and minor version, name, publicKeyToken and language.
        
        Arguments:
        fuzzy (boolean)             - If False, insert the full version in 
                                      the id string. Default is True (omit).
        windowsversion              - If not specified (or None), default to 
        (tuple or list of integers)   sys.getwindowsversion().
        
        s   Assembly metadata incompleteR   R   i    i   R]   i   RU   R   R   (   i   (   i   (   R   R3   R6   RF   R   RG   Ro   R5   RH   Rb   Rc   R^   R   R   (   R   t   fuzzyRE   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyRe   (  s<    				!5!=c      
   C   s-  | j  t j k r | j } n8 | j  t j k r9 | } n t d t | j   d   d. } | j | k r t d | j d j |  f   n  | j d k r x| j	 d	  D]0 } x' | j	 d  D] } |  j
 | |  q Wq WnC| r |  j   n  | j |  _ g  | j d
  pd j d  D] } t |  ^ q$|  _ t | j d   |  _ t | j d   |  _ x | j	 d  D] } | j d  pd- |  _ | j d  pd- |  _ | j d  pd- |  _ | j d  pd- |  _ | j d  }	 |	 r(g  |	 j d  D] } t |  ^ q
|  _ n  | j d  p:d- |  _ qWx; | j	 d  D]* }
 |
 j d  pld j   d k |  _ qTWx2 | j	 d  D]! } | j r| j j |  _  qqWx | j	 d  D] } x | j	 d  D]p } xg | j	 d  D]V } xM | j	 d  D]< } | j d  |  _! | j d   p3d j   d! k |  _" q	WqWqWqW| j d k rp| g } n | j	 d"  } x | D] } x | j	 d  D] } t# |  } | j sqn  | j d#  pd j   d k | _$ |  j% j& |  |  j' rd$ j |  j' | j f  |  j% d% _' qqWqWx | j	 d&  D] } g  | j d'  j d(  D]. } g  | j d  D] } t |  ^ qo^ qY} g  | j d)  j d  D] } t |  ^ q} |  j( j& | | f  q:WxN | j	 d*  D]= } |  j) d | j d  d+ | j d+  d, | j d,   qWd- S(/   s   
        Load manifest from DOM tree.
        
        If initialize is True (default), reset existing attributes first.
        
        s   Invalid root element node type s1    - has to be one of (DOCUMENT_NODE, ELEMENT_NODE)R>   t   assemblyBindingt   configurationt   dependentAssemblys1   Invalid root element <%s> - has to be one of <%s>s   >, <t   windowsRA   s   1.0R]   RB   RC   t   assemblyIdentityRD   R   RE   RF   RG   RH   t   publisherPolicyt   applyR   t   yesRJ   t	   trustInfot   securityt   requestedPrivilegesRK   t   levelRL   t   truet
   dependencyR?   RR   it   bindingRedirectt
   oldVersionRW   t
   newVersiont   fileR!   R&   N(   s   assemblys   assemblyBindingR   s   dependentAssembly(*   t   nodeTypeR   t   DOCUMENT_NODEt   documentElementt   ELEMENT_NODER;   Ro   R   R5   t	   getCEByTNt   load_domR   R@   t   getAR_   t   intRA   t   boolt
   getFCEByTNRB   RC   R   RD   R   RE   RF   RG   RH   R$   RI   t
   firstChildt	   wholeTextRJ   RK   RL   t   ManifestFromDOMR?   RM   R   R   RN   RT   (   R   t   domtreet
   initializet   rootElementt   allowed_namesR   R   R   R   RG   R   RJ   R   R   t   reqPrivt	   reqExeLevt   dependenciesR   R   R   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR   Y  s    	
 (.	%			*J.c         C   s  t  | t t f  r | } n	 | j } y t j |  } Wn t j j j	 k
 r } | j
 d g } t  | t  r | j t j   d  } n  | j d d |  t d j g  | D] } t |  ^ q    n X| r |  j   n  | |  _ |  j | t  d S(   s(    Load manifest from file or file object i    t   replaces   
  File "%s"
   t    N(   R   Ro   t   unicodeR   R   t   parset   xmlt   parserst   expatt
   ExpatErrort   argst   encodeRb   t   getdefaultencodingt   insertR<   R5   R   R   R   Rd   (   R   t   filename_or_fileR   R   R   t   eR   t   arg(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR     s    		2	c         C   sR   y t  j |  } Wn( t j j j k
 r= } t |   n X|  j | |  d S(   s    Load manifest from XML string N(   R   t   parseStringR   R   R   R   R<   R   (   R   t   xmlstrR   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   parse_string  s
    c         C   s   | r t  } n |  j | j k } |  j | j k o~ |  j | j k o~ |  j | j k o~ |  j | j k o~ |  j | j k o~ | S(   s   
        Return a bool indicating if another manifest has the same identitiy.
        
        This is done by comparing language, name, processorArchitecture, 
        publicKeyToken, type and version.
        
        (   Rf   RG   RE   R   RF   RH   RD   (   R   R   t   skip_version_checkt   version_check(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyRk     s    	c         C   s  t    } | j |  j  } |  j d k rr | j d  } | j d  } | j |  | j |  | j |  n | j |  |  j d k r | j d d  |  j d k r | j d d j g  |  j D] } t |  ^ q   q n  |  j r
| j | j d	   n  |  j	 r,| j | j d
   n  | j d  } |  j
 rZ| j d |  j
  n  |  j ry| j d |  j  n  |  j r| j d |  j  n  |  j r| j d |  j  n  |  j r| j d d j g  |  j D] } t |  ^ q  n  |  j r| j d |  j  n  | j   r3| j |  n
 | j   |  j d. k r| j d  } |  j rw| j d d  n | j d d  | j |  n  |  j r| j d  } | j | j |  j   | j |  n  |  j d/ k r| j d  }	 |	 j d d  | j d  }
 | j d  } | j d  } | j d |  j  |  j rb| j d  d!  n | j d  d"  | j |  |
 j |  |	 j |
  | j |	  n  |  j rx |  j D] } |  j d k r| j d#  } | j r| j d$ d  qn  | j d  } | j   } x* | j j D] } | j | j t   q'W| j   |  j d k r}| j |  | j |  q| j |  qWn  |  j  rUx |  j  D] } | j d%  } | j d& d' j g  | d( D]. } d j g  | D] } t |  ^ q ^ q  | j d) d j g  | d* D] } t |  ^ q%  | j |  qWn  |  j! rxi |  j! D][ } | j d+  } x6 d0 D]. } t" | |  } | r| j | |  qqW| j |  qhWn  | S(1   s!    Return the manifest as DOM tree R   R   R   R   t   xmlnss    urn:schemas-microsoft-com:asm.v1RA   R]   RB   RC   R   RD   R   RE   RF   RG   RH   R   R   R   t   noRJ   t	   asInvokert   highestAvailablet   requireAdministratorR   s    urn:schemas-microsoft-com:asm.v3R   R   RK   R   RL   R   t   falseR   R?   R   R   RW   i    R   i   R   R!   R&   N(   R   R   R   (   s   names   hashalgs   hash(#   R   t   cER@   t   aChildt   setAR5   RA   Ro   RB   RC   RD   t   setAttributeR   RE   RF   RG   RH   t   hasAttributest   unlinkRI   R   RJ   t   cTRK   RL   RM   R?   t   todomR   R   t	   cloneNodeRd   RN   RO   R/   (   R   t   doct   docEt   cfgt   winR   t   aIdt   ppEt   descEt   tEt   sEt   rpEt   relER>   t   dEt   daEt   adomR   R   t   brER   R   t   fEt   attrt   val(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR     s    		2									/	
						
			@	-	s     s   UTF-8c         C   sy   |  j    } t j d k r3 | j | | |  } n | j | |  } | j t j  j d | d |  } | j   | S(   s+    Return the manifest as pretty-printed XML i   i   s#   <?xml version="1.0" encoding="%s"?>s4   <?xml version="1.0" encoding="%s" standalone="yes"?>(   i   i   (	   R   Rb   t   version_infot   toprettyxmlt   stripR   t   linesepR   R   (   R   t   indentt   newlt   encodingR   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR   L  s    

c         C   s=   |  j    } | j |  j d | d |  } | j   | S(   s    Return the manifest as XML s#   <?xml version="1.0" encoding="%s"?>s4   <?xml version="1.0" encoding="%s" standalone="yes"?>(   R   t   toxmlR   R   (   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR   ^  s    
c         C   s   t  | |  j   | |  d S(   s9    Update or add manifest resource in dll/exe file dstpath N(   t   UpdateManifestResourcesFromXMLR   (   R   t   dstpatht   namesRz   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   update_resourcesk  s    c         C   si   | s |  j  } n  t | t t f  r9 t | d  } n  |  j | | |  } | j |  | j   d S(   s4    Write the manifest as XML to a file or file object t   wbN(   R   R   Ro   R   R,   R   t   writeR.   (   R   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   writeprettyxmlp  s    c         C   si   | s |  j  } n  t | t t f  r9 t | d  } n  |  j | | |  } | j |  | j   d S(   s4    Write the manifest as XML to a file or file object R   N(   R   R   Ro   R   R,   R   R   R.   (   R   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   writexml{  s    N(   R   R   R:   R   Rd   R   RS   RT   Rf   R   Rq   R^   Re   R   R   R   Rk   R   R   R   R   R   R   R   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR=      sD   1\	i
c         C   s   t  |  | |  } g  } | rz | t rz xO t | t  rv | j   rv | j   d } | j t |   | | } q+ Wn  t | t  r t d |    n  t   } d j	 |  g |  | _
 | j | t  | S(   sC    Create and return manifest instance from resource in dll/exe file i    s+   No matching manifest resource found in '%s'RR   (   t   GetManifestResourcest   RT_MANIFESTR   t   dictt   keysR   Ro   R;   R=   R5   R   R   Rd   (   R   R   Rz   t   rest   ptht   keyR   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyRw     s    	c         C   s   t    } | j |   | S(   s3    Create and return manifest instance from DOM tree (   R=   R   (   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR     s    	c         C   s   t    } | j |   | S(   s.    Create and return manifest instance from XML (   R=   R   (   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   ManifestFromXML  s    	c         C   s   t    } | j |   | S(   s/    Create and return manifest instance from file (   R=   R   (   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyRg     s    	c         C   s   t  j |  t g | |  S(   s"    Get manifest resources from file (   R	   t   GetResourcesR   (   R   R   Rz   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR     s    c      	   C   sf   t  j d |   |  j   j d  r. d } n d } t j |  | t | pO | g | p^ d d g  d S(   s3    Update or add manifest XML as resource in dstpath s   Updating manifest in %ss   .exei   i   i    RU   N(   R3   R4   R$   Rv   R	   t   UpdateResourcesR   (   R   R   R   Rz   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR     s    	c      	   C   si   t  j d | |   |  j   j d  r1 d } n d } t j |  | t | pR | g | pa d d g  d S(   s@    Update or add manifest XML from srcpath as resource in dstpath s   Updating manifest from %s in %ss   .exei   i   i    RU   N(   R3   R4   R$   Rv   R	   t   UpdateResourcesFromDataFileR   (   R   t   srcpathR   Rz   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt"   UpdateManifestResourcesFromXMLFile  s    	c         C   s  | sP t  |   } t j j |   } t j j t j j |  d  d | _ nH t | t  rz d | k rz t |  } n t | t	  s t  |  } n  t
 g  | j D] } | j ^ q  } | j |  k r!t  |   } xF | j D]8 } | j | k r | j j |  | j | j  q q Wn  | rqd | k rq| j j t	 d d d d d d d	 t   d
 d d d   n  | j |   | S(   s#   
    Create assembly manifest.
    i    t   <s!   Microsoft.Windows.Common-ControlsRQ   t   win32R   RE   RU   RF   RG   i   RH   t   6595b64144ccf1df(   i   i    i    i    (   Rg   R   R   R   Ru   R   R   t
   basestringR  R=   t   setRM   R   R   t   addt   processor_architectureR   (   R   R   t   consoleR   t   dept	   dep_namest   depmanifestR>   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   create_manifest  s4    ,%		c           C   s   t    d k r d Sd Sd S(   s  
    Detect processor architecture for assembly manifest.

    According to:
    http://msdn.microsoft.com/en-us/library/windows/desktop/aa374219(v=vs.85).aspx
    item processorArchitecture in assembly manifest is

    'x86' - 32bit Windows
    'amd64' - 64bit Windows
    t   32bitt   x86t   amd64N(   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyR    s    t   __main__i   i   (E   R:   R   R    t   reRb   R   t   xml.domR   R   t   xml.dom.minidomR   R   t   PyInstallerR   t   PyInstaller.compatR   R   R   Rm   t	   getLoggerR3   t   PyInstaller.utilsR	   t   ImportErrort   detailR   R6   Rs   Rt   R   t   appendChildR   t   createElementR   t   createTextNodeR   t   getElementsByTagNamet   getEByTNt   getAttributeR   t   removeAttributet   remAR   R   R   R   R   R   R   R   t   _FileRh   R;   R<   t   objectR=   Rw   R   R  Rg   R   R   R  R  R  R   t   argvR   R
  (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winmanifest.pyt   <module>S   s|   	
						5  				&	