ó
¥ –Qc           @   sà   d  Z  d d l Z d d l Z d d l j Z e j e ƒ Z d Z	 d Z
 d Z d Z d Z d Z d	 e f d
 „  ƒ  YZ d d d d „ Z d d d d „ Z d d d „ Z d d d „ Z d d d d „ Z d d d d „ Z d S(   sª   
Read and write resources from/to Win32 PE files.

Commandline usage:
winresource.py <dstpath> <srcpath>
Updates or adds resources from file <srcpath> in file <dstpath>.
iÿÿÿÿNi   iÁ   i  i  i  i  t   Filec           B   sk   e  Z d  Z d „  Z d d d d „ Z d d d „ Z d d d „ Z d d d d „ Z d d d d „ Z	 RS(   s   
    Win32 PE file class.
    c         C   s   | |  _  d  S(   N(   t   filename(   t   selfR   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   __init__(   s    c         C   s   t  |  j | | | ƒ S(   s€  
        Get resources.

        types = a list of resource types to search for (None = all)
        names = a list of resource names to search for (None = all)
        languages = a list of resource languages to search for (None = all)
        Return a dict of the form {type_: {name: {language: data}}} which
        might also be empty if no matching resources were found.
        (   t   GetResourcesR   (   R   t   typest   namest	   languages(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   get_resources+   s    
c         C   s   t  |  j | | | | ƒ d S(   sß   
        Update or add resource data.

        type_ = resource type to update
        names = a list of resource names to update (None = all)
        languages = a list of resource languages to update (None = all)
        N(   t   UpdateResourcesR   (   R   t   datat   type_R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   update_resources7   s    c         C   s   t  |  j | | | | ƒ d S(   sñ   
        Update or add resource data from file srcpath.

        type_ = resource type to update
        names = a list of resource names to update (None = all)
        languages = a list of resource languages to update (None = all)
        N(   t   UpdateResourcesFromDataFileR   (   R   t   srcpathR   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   update_resources_from_datafileA   s    	c         C   s   t  |  j | | | | ƒ d S(   s  
        Update or add resources from resource dict.

        types = a list of resource types to update (None = all)
        names = a list of resource names to update (None = all)
        languages = a list of resource languages to update (None = all)
        N(   t   UpdateResourcesFromDictR   (   R   t   resR   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   update_resources_from_dictM   s    	c         C   s   t  |  j | | | | ƒ d S(   s  
        Update or add resources from dll/exe file srcpath.

        types = a list of resource types to update (None = all)
        names = a list of resource names to update (None = all)
        languages = a list of resource languages to update (None = all)
        N(   t   UpdateResourcesFromResFileR   (   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   update_resources_from_resfileY   s    	N(
   t   __name__t
   __module__t   __doc__R   t   NoneR   R   R   R   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR    $   s   	
c            sâ  ˆ r t  ˆ ƒ ‰ n  ˆ r* t  ˆ ƒ ‰ n  ˆ  r? t  ˆ  ƒ ‰  n  i  } yXt j |  ƒ } ˆ r„ d ˆ k r„ t ‡ f d †  | ƒ } n  x| D]} t j |  | ƒ } ˆ rÐ d ˆ k rÐ t ‡ f d †  | ƒ } n  xÅ | D]½ } t j |  | | ƒ }	 ˆ  rd ˆ  k rt ‡  f d †  |	 ƒ }	 n  xr |	 D]j }
 t j |  | | |
 ƒ } | | k r]i  | | <n  | | | k r~i  | | | <n  | | | | |
 <q&Wq× Wq‹ WWn> t j k
 rÝ} | j	 d t
 t t t f k rÔqÞ| ‚ n X| S(   sn  
    Get resources from hsrc.

    types = a list of resource types to search for (None = all)
    names = a list of resource names to search for (None = all)
    languages = a list of resource languages to search for (None = all)
    Return a dict of the form {type_: {name: {language: data}}} which
    might also be empty if no matching resources were found.
    t   *c            s
   |  ˆ  k S(   N(    (   R   (   R   (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   <lambda>{   s    c            s
   |  ˆ  k S(   N(    (   t   name(   R   (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   ‚   s    c            s
   |  ˆ  k S(   N(    (   t   language(   R   (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   ‹   s    i    (   t   sett   win32apit   EnumResourceTypest   filtert   EnumResourceNamest   EnumResourceLanguagest   LoadResourcet
   pywintypest   errort   argst   ERROR_RESOURCE_DATA_NOT_FOUNDt   ERROR_RESOURCE_TYPE_NOT_FOUNDt   ERROR_RESOURCE_NAME_NOT_FOUNDt   ERROR_RESOURCE_LANG_NOT_FOUND(   t   hsrcR   R   R   R   t
   enum_typesR   t
   enum_namesR   t   enum_languagesR   R
   t	   exception(    (   R   R   R   s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   _GetResourcesf   sN    
		"
c         C   s;   t  j |  d t ƒ } t | | | | ƒ } t  j | ƒ | S(   sv  
    Get resources from dll/exe file.

    types = a list of resource types to search for (None = all)
    names = a list of resource names to search for (None = all)
    languages = a list of resource languages to search for (None = all)
    Return a dict of the form {type_: {name: {language: data}}} which
    might also be empty if no matching resources were found.
    i    (   R   t   LoadLibraryExt   LOAD_LIBRARY_AS_DATAFILER0   t   FreeLibrary(   R   R   R   R   R+   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   ¡   s    
c   	   
   C   sj  t  |  | g | | ƒ } | | k r= | d k r= i  | | <n  | rÖ x | D]… } | | | k rJ | d k rJ g  | | | <| rÏ xI | D]> } | | | | k r‡ | d k r‡ | | | j | ƒ q‡ q‡ WqÏ qJ qJ Wn  t j |  d ƒ } xk | D]c } xZ | | D]N } xE | | | D]5 } t j d | | | ƒ t j | | | | | ƒ qWq Wqï Wt j | d ƒ d S(   sã   
    Update or add resource data in dll/exe file dstpath.

    type_ = resource type to update
    names = a list of resource names to update (None = all)
    languages = a list of resource languages to update (None = all)
    R   i    s-   Updating resource type %s name %s language %sN(   R   t   appendR   t   BeginUpdateResourcet   loggert   infot   UpdateResourcet   EndUpdateResource(	   t   dstpathR
   R   R   R   R   R   R   t   hdst(    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR	   ±   s&    	 )	%c         C   s?   t  | d ƒ } | j ƒ  } | j ƒ  t |  | | | | ƒ d S(   sõ   
    Update or add resource data from file srcpath in dll/exe file dstpath.

    type_ = resource type to update
    names = a list of resource names to update (None = all)
    languages = a list of resource languages to update (None = all)
    t   rbN(   t   opent   readt   closeR	   (   R:   R   R   R   R   t   srcR
   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   Ñ   s    	
c         C   sï   | r t  | ƒ } n  | r* t  | ƒ } n  | r? t  | ƒ } n  x© | D]¡ } | s_ | | k rF x… | | D]v } | sƒ | | k rj xZ | | | D]G } | s« | | k r’ t |  | | | | | g | g | g ƒ q’ q’ Wqj qj WqF qF Wd S(   s
  
    Update or add resources from resource dict in dll/exe file dstpath.

    types = a list of resource types to update (None = all)
    names = a list of resource names to update (None = all)
    languages = a list of resource languages to update (None = all)
    N(   R   R	   (   R:   R   R   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   à   s    	c         C   s&   t  | | | | ƒ } t |  | ƒ d S(   s  
    Update or add resources from dll/exe file srcpath in dll/exe file dstpath.

    types = a list of resource types to update (None = all)
    names = a list of resource names to update (None = all)
    languages = a list of resource languages to update (None = all)
    N(   R   R   (   R:   R   R   R   R   R   (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyR   ú   s    	(   R   R$   R   t   PyInstaller.logt   logt   loggingt	   getLoggerR   R6   R2   t   ERROR_BAD_EXE_FORMATR'   R(   R)   R*   t   objectR    R   R0   R   R	   R   R   R   (    (    (    s`   C:\Users\Salopaasi\My Documents\pyinstaller-pyinstaller-275d4c9\PyInstaller\utils\winresource.pyt   <module>   s(   B; 