§
    cÌc›<  ã                   óö   — d Z ddlZddlZddlZddlmZ  e 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&d„Z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(d#„Z d$„ Z!e!Z"d%„ Z#dS ))zWin32-specific helper functionsé    Né   )Úlazy_importzK
import ctypes

from breezy import cmdline
from breezy.i18n import gettext
iöÿÿÿiõÿÿÿiôÿÿÿé   é   é   i  é   é   é   Ú Tc                 óV  — ddl m}  G d„ dt          j        ¦  «        }t          j        j                             ¦   «         } |¦   «         }t          j        j                             |t           	                    |¦  «        t           
                    |¦  «        ¦  «        }|s$|                     t          d¦  «        ¦  «         dS |j        |j        |j        |j        |j        |j        |j        |j        |j        |j        dœ
}|rK|                     t          d¦  «                             |d	         d
z  |d         d
z  | ¦  «        ¦  «         dS | r|                     d| ¦  «         |                     t          d¦  «        |d	         d
z  ¦  «         |                     t          d¦  «        |d         d
z  ¦  «         |                     t          d¦  «        |                     dd¦  «        d
z  ¦  «         |                     t          d¦  «        |                     dd¦  «        d
z  ¦  «         |                     t          d¦  «        |                     dd¦  «        d
z  ¦  «         |                     t          d¦  «        |                     dd¦  «        ¦  «         dS )z1Use trace.note() to dump the running memory info.r   ©Útracec                   óÆ   — e Zd ZdZdej        fdej        fdej        fdej        fdej        fdej        fdej        fd	ej        fd
ej        fdej        fdej        fgZdS )ú9debug_memory_win32api.<locals>.PROCESS_MEMORY_COUNTERS_EXzUsed by GetProcessMemoryInfoÚcbÚPageFaultCountÚPeakWorkingSetSizeÚWorkingSetSizeÚQuotaPeakPagedPoolUsageÚQuotaPagedPoolUsageÚQuotaPeakNonPagedPoolUsageÚQuotaNonPagedPoolUsageÚPagefileUsageÚPeakPagefileUsageÚPrivateUsageN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚctypesÚc_ulongÚc_size_tÚ_fields_© ó    ú3/usr/lib/python3/dist-packages/breezy/win32utils.pyÚPROCESS_MEMORY_COUNTERS_EXr   9   s‰   € € € € € Ø*Ð*Ø˜6œ>Ð*Ø% v¤~Ð6Ø)¨6¬?Ð;Ø% v¤Ð7Ø.°´Ð@Ø*¨F¬OÐ<Ø1°6´?ÐCØ-¨v¬Ð?Ø$ f¤oÐ6Ø(¨&¬/Ð:Ø# V¤_Ð5ðˆˆˆr%   r'   z Failed to GetProcessMemoryInfo()N)
r   r   r   r   r   r   r   r   r   r   z/WorkingSize {0:>7}KiB	PeakWorking {1:>7}KiB	{2}r   i   r   z%szWorkingSize       %8d KiBzPeakWorking       %8d KiBzPagefileUsage     %8d KiBr   zPeakPagefileUsage %8d KiBr   zPrivateUsage      %8d KiBr   zPageFaultCount    %8dr   )Úbreezyr   r    Ú	StructureÚwindllÚkernel32ÚGetCurrentProcessÚpsapiÚGetProcessMemoryInfoÚbyrefÚsizeofÚnoteÚgettextr   r   r   r   r   r   r   r   r   r   ÚformatÚget)ÚmessageÚshortr   r'   Úcur_processÚ
mem_structÚretÚinfos           r&   Údebug_memory_win32apir;   6   sÊ  € àÐÐÐÐÐðð ð ð ð ¥VÔ%5ñ ô ð õ ”-Ô(×:Ò:Ñ<Ô<€KØ+Ð+Ñ-Ô-€JÝ
Œ-Ô
×
2Ò
2Ø•V—\’\ *Ñ-Ô-­v¯}ª}¸ZÑ/HÔ/HñJô J€Càð Ø�
Š
•7Ð=Ñ>Ô>Ñ?Ô?Ð?ØˆØ(Ô7Ø",Ô"?Ø(Ô7Ø'1Ô'IØ#-Ô#AàÔ5Ø&0Ô&GØ'Ô5Ø!+Ô!=Ø&Ô3ðð €Dð ð à�
Š
•7ð :ñ ;ô ;ß;Aº6ØÐ(Ô)¨DÑ0ØÐ,Ô-°Ñ4Øñ<ô <ñ	ô 	ð 	ð
 	ˆØð "Ø�
Š
�4˜Ñ!Ô!Ð!Ø	‡J‚J�wÐ2Ñ3Ô3ØÐ$Ô%¨Ñ,ñ.ô .ð .à	‡J‚J�wÐ2Ñ3Ô3ØÐ(Ô)¨DÑ0ñ2ô 2ð 2à	‡J‚J�wÐ2Ñ3Ô3Ø�xŠx˜¨Ñ+Ô+¨dÑ2ñ4ô 4ð 4à	‡J‚J�wÐ2Ñ3Ô3Ø�xŠxÐ+¨QÑ/Ô/°$Ñ6ñ8ô 8ð 8à	‡J‚J�wÐ2Ñ3Ô3Ø�xŠx˜¨Ñ*Ô*¨TÑ1ñ3ô 3ð 3à	‡J‚J�wÐ.Ñ/Ô/°·²Ð:JÈAÑ1NÔ1NÑOÔOÐOÐOÐOr%   éP   é   c                 óR  — t           j        j                             t          ¦  «        }t                                d¦  «        }t           j        j                             ||¦  «        }|r:t          j        d|j	        ¦  «        \  }}}}}	}
}}}}}||
z
  dz   }||z
  dz   }||fS | |fS )zÚReturn size of current console.

    This function try to determine actual size of current working
    console window and return tuple (sizex, sizey) if success,
    or default size (defaultx, defaulty) otherwise.
    é   ÚhhhhHhhhhhhr   )
r    r*   r+   ÚGetStdHandleÚWIN32_STDERR_HANDLEÚcreate_string_bufferÚGetConsoleScreenBufferInfoÚstructÚunpackÚraw)ÚdefaultxÚdefaultyÚhÚcsbiÚresÚbufxÚbufyÚcurxÚcuryÚwattrÚleftÚtopÚrightÚbottomÚmaxxÚmaxyÚsizexÚsizeys                     r&   Úget_console_sizerZ   q   sµ   € õ 	ŒÔ×+Ò+Õ,?Ñ@Ô@€AÝ×&Ò& rÑ*Ô*€DÝ
Œ-Ô
 ×
;Ò
;¸A¸tÑ
DÔ
D€Cà
ð $å17´Ø˜4œ8ñ2%ô 2%ñ	/ˆˆt�T˜4 Ø	ˆs�E˜6 4¨à˜‘˜qÑ ˆØ˜‘˜qÑ ˆØ�uˆ~Ðà˜(Ð#Ð#r%   c                 ó¾   — 	 t           j        j        j        }t                                t
          ¦  «        } |d|| d¦  «        r|j        S dS # t          $ r Y dS w xY w)zhCall SHGetSpecialFolderPathW if available, or return None.

    Result is always unicode (or None).
    Nr   )r    r*   Úshell32ÚSHGetSpecialFolderPathWÚcreate_unicode_bufferÚMAX_PATHÚvalueÚAttributeError)ÚcsidlÚSHGetSpecialFolderPathÚbufs      r&   Ú_get_sh_special_folder_pathre   ‰   s{   € ð
åŒMÔ!Ô9ð 	õ
 ×*Ò*­8Ñ4Ô4ˆØ!Ð! $¨¨U°AÑ6Ô6ð 	Ø”9Ðð	ð 	øõ	 ð ð ð Øˆˆðøøøs   ‚A Á
AÁAc                  óp   — t          t          ¦  «        } | r| S t          j                             d¦  «        S )a  Return Application Data location.
    Return None if we cannot obtain location.

    Windows defines two 'Application Data' folders per user - a 'roaming'
    one that moves with the user as they logon to different machines, and
    a 'local' one that stays local to the machine.  This returns the 'roaming'
    directory, and thus is suitable for storing user-preferences, etc.
    ÚAPPDATA)re   ÚCSIDL_APPDATAÚosÚenvironr4   )Úappdatas    r&   Úget_appdata_locationrl   ™   s2   € õ *­-Ñ8Ô8€GØð ØˆåŒ:�>Š>˜)Ñ$Ô$Ð$r%   c                  ó”   — t          t          ¦  «        } | r| S t          j                             d¦  «        } | r| S t          ¦   «         S )aÒ  Return Local Application Data location.
    Return the same as get_appdata_location() if we cannot obtain location.

    Windows defines two 'Application Data' folders per user - a 'roaming'
    one that moves with the user as they logon to different machines, and
    a 'local' one that stays local to the machine.  This returns the 'local'
    directory, and thus is suitable for caches, temp files and other things
    which don't need to move with the user.
    ÚLOCALAPPDATA)re   ÚCSIDL_LOCAL_APPDATAri   rj   r4   rl   )Úlocals    r&   Úget_local_appdata_locationrq   ©   sK   € õ (Õ(;Ñ<Ô<€EØð ØˆåŒJ�NŠN˜>Ñ*Ô*€EØð ØˆÝÑ!Ô!Ð!r%   c                  óÌ  — t          t          ¦  «        } | r| S t          j                             d¦  «        } | �| S t          j                             d¦  «        }|�>t          j                             t          j                             dd¦  «        | ¦  «        S t          j                             d¦  «        }|r(t          j                             |¦  «        d         dz   S d	S )
z�Return user's home location.
    Assume on win32 it's the <My Documents> folder.
    If location cannot be obtained return system drive root,
    i.e. C:    ÚHOMENÚHOMEPATHÚHOMEDIRr   ÚWINDIRr   ú/zC:/)re   ÚCSIDL_PERSONALri   rj   r4   ÚpathÚjoinÚ
splitdrive)ÚhomeÚhomepathÚwindirs      r&   Úget_home_locationr   ½   s»   € õ '¥~Ñ6Ô6€DØð ØˆÝŒ:�>Š>˜&Ñ!Ô!€DØÐØˆÝŒz�~Š~˜jÑ)Ô)€HØÐÝŒw�|Š|�BœJŸNšN¨9°bÑ9Ô9¸4Ñ@Ô@Ð@åŒZ�^Š^˜HÑ%Ô%€FØð 3ÝŒw×!Ò! &Ñ)Ô)¨!Ô,¨sÑ2Ð2àˆ5r%   c                  ó„  — 	 t           j        j        } t          | d¦  «        }t                                t
          dz   ¦  «        }t                                t
          dz   ¦  «        } ||t                                |¦  «        ¦  «        r|j        S n# t          $ r Y nw xY wt          j                             d¦  «        S )zPReturn user name as login name.
    If name cannot be obtained return None.
    ÚGetUserNameWr   ÚUSERNAME)r    r*   Úadvapi32Úgetattrr^   ÚUNLENÚc_intr/   r`   ra   ri   rj   r4   )rƒ   ÚGetUserNamerd   Úns       r&   Úget_user_namer‰   Ô   s±   € ð	Ý”=Ô)ˆÝ˜h¨Ñ7Ô7ˆõ ×*Ò*­5°1©9Ñ5Ô5ˆÝ�LŠL� ™Ñ#Ô#ˆØˆ;�s�FŸLšL¨™OœOÑ,Ô,ð 	Ø”9Ðð	øõ ð ð ð Øˆðøøøõ Œ:�>Š>˜*Ñ%Ô%Ð%s   ‚!B Â
B ÂB c                  ón  — t                                t          dz   ¦  «        } t                                t          dz   ¦  «        }t	          t           j        j        dd¦  «        }|�1 |t          | t                                |¦  «        ¦  «        r| j	        S t          j                             d¦  «        S )z…Return host machine name.
    If name cannot be obtained return None.

    :return: A unicode string representing the host name.
    r   ÚGetComputerNameExWNÚCOMPUTERNAME)r    r^   ÚMAX_COMPUTERNAME_LENGTHr†   r„   r*   r+   Ú_WIN32_ComputerNameDnsHostnamer/   r`   ri   rj   r4   )rd   rˆ   ÚGetComputerNameExs      r&   Úget_host_namer�   ë   sž   € õ ×
&Ò
&Õ'>ÀÑ'BÑ
CÔ
C€CÝ�ŠÕ,¨qÑ0Ñ1Ô1€Aõ  ÝŒÔÐ 4°dñ<ô <ÐàÐ%ØÐÕ<Ø!¥6§<¢<°¡?¤?ñ4ô 4ð 	&ð ŒyÐÝŒ:�>Š>˜.Ñ)Ô)Ð)r%   c                 ó¶   — t           j                             | ¦  «        d         r*|                      d¦  «        s|                      d¦  «        rd| z   dfS | dfS )Nr   Ú*ú?z./TF)ri   ry   ÚsplitÚ
startswith)ry   s    r&   Ú_ensure_with_dirr–   þ   s]   € ÝŒG�MŠM˜$ÑÔ Ô"ð  d§o¢o°cÑ&:Ô&:ð Ø�Š˜sÑ#Ô#ðà�d‰{˜DÐ Ð à�Uˆ{Ðr%   c                 ó   — |r
| dd …         S | S )Nr
   r$   )ry   Ú	correcteds     r&   Ú_undo_ensure_with_dirr™     s   € Øð Ø�A�B�BŒxˆàˆr%   c                 ó”   ‡— t          | ¦  «        \  }Št          j        |¦  «        }|s| g}n‰rˆfd„|D ¦   «         }d„ |D ¦   «         S )z»Same as glob.glob().

    work around bugs in glob.glob()
    - Python bug #1001604 ("glob doesn't return unicode with ...")
    - failing expansion for */* with non-iso-8859-* chars
    c                 ó0   •— g | ]}t          |‰¦  «        ‘ŒS r$   )r™   )Ú.0Úelemr˜   s     €r&   ú
<listcomp>zglob_one.<locals>.<listcomp>  s3   ø€ ð .ð .ð .Øõ ,¨D°)Ñ<Ô<ð .ð .ð .r%   c                 ó:   — g | ]}|                      d d¦  «        ‘ŒS )ú\rw   )Úreplace)rœ   r�   s     r&   rž   zglob_one.<locals>.<listcomp>  s&   € Ð;Ð;Ð;¨ˆD�LŠL˜˜sÑ#Ô#Ð;Ð;Ð;r%   )r–   Úglob)Úpossible_globÚcorrected_globÚ
glob_filesr˜   s      @r&   Úglob_oner¦     s}   ø€ õ !1°Ñ ?Ô ?Ñ€N�IÝ”˜>Ñ*Ô*€Jàð .ð $�_ˆ
ˆ
Ø	ð .ð.ð .ð .ð .Ø",ð.ñ .ô .ˆ
à;Ð;°
Ð;Ñ;Ô;Ð;r%   c                 ó`   — | sg S g }| D ]$}|                      t          |¦  «        ¦  «         Œ%|S )a!  Replacement for glob expansion by the shell.

    Win32's cmd.exe does not do glob expansion (eg ``*.py``), so we do our own
    here.

    :param file_list: A list of filenames which may include shell globs.
    :return: An expanded list of filenames.

    Introduced in breezy 0.18.
    )Úextendr¦   )Ú	file_listÚexpanded_file_listr£   s      r&   Úglob_expandr«   !  sK   € ð ð Øˆ	ØÐØ"ð ;ð ;ˆØ×!Ò!¥(¨=Ñ"9Ô"9Ñ:Ô:Ð:Ð:ØÐr%   c                 óÌ  — ddl }| }t          j                             |¦  «        d         s| dz   }	 |                     |j        d|z   ¦  «        }n# t          $ r | cY S w xY w	 	 |                     |d¦  «        \  }}n'# t          $ r | cY |                     |¦  «         S w xY w	 |                     |¦  «         n# |                     |¦  «         w xY w|t          k    r|S | S )a¶  Look up in Windows registry for full path to application executable.
    Typically, applications create subkey with their basename
    in HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\

    :param  appname:    name of application (if no filename extension
                        is specified, .exe used)
    :return:    full path to aplication executable from registry,
                or appname itself if nothing found.
    r   Nr   z.exez4SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\r   )
Úwinregri   ry   ÚsplitextÚOpenKeyÚHKEY_LOCAL_MACHINEÚOSErrorÚQueryValueExÚCloseKeyÚREG_SZ)Úappnamer­   ÚbasenameÚhkeyry   Útype_ids         r&   Úget_app_pathr¹   4  s/  € ð €M€M€Mà€HÝŒ7×Ò˜HÑ%Ô% aÔ(ð $Ø˜VÑ#ˆðØ�~Š~ØÔ%ØGØññô ˆˆøõ ð ð ð Øˆˆˆðøøøðð	Ø"×/Ò/°°bÑ9Ô9‰MˆD�'�'øÝð 	ð 	ð 	ØˆNˆNà�Š˜ÑÔÐÐð	øøøð ð 	�Š˜ÑÔÐÐøˆ�Š˜ÑÔÐÐøøøà•&ÒÐØˆØ€Ns;   ²A ÁA ÁA Á%A? Á>B= Á?B#ÂB= Â"B#Â#B= Â=Cc                 óò   — ddl m}m}m} t          j        j        j        }||f|_        ||_	        d} || |¦  «        s8t           
                    ¦   «         }ddlm} |                     d| |¦  «         dS dS )z)Set file attributes to hidden if possibler   )ÚBOOLÚDWORDÚLPWSTRr
   r   r   z(Unable to set hidden attribute on %r: %sN)Úctypes.wintypesr»   r¼   r½   r    r*   r+   ÚSetFileAttributesWÚargtypesÚrestypeÚWinErrorr   r   Úmutter)ry   r»   r¼   r½   ÚSetFileAttributesÚFILE_ATTRIBUTE_HIDDENÚer   s           r&   Úset_file_attr_hiddenrÇ   Y  s«   € à3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3Ð3åœÔ.ÔAÐØ!'¨ ÐÔØ $ÐÔØÐØÐ˜TÐ#8Ñ9Ô9ð JÝ�OŠOÑÔˆØÐÐÐÐÐØ�ŠÐ?ÀÀqÑIÔIÐIÐIÐIðJð Jr%   Fc                 ó¸  — t                                | |¬¦  «        }t          |¦  «        }t          |¦  «        t          |¦  «        k     rt	          d¦  «        ‚|t          |¦  «        t          |¦  «        z
  d…         }g }|D ]S\  }}|st          j        |¦  «        s|                     |¦  «         Œ1|                     t          |¦  «        ¦  «         ŒT|S )a3  Convert a Unicode command line into a list of argv arguments.

    It performs wildcard expansion to make wildcards act closer to how they
    work in posix shells, versus how they work by default on Windows. Quoted
    arguments are left untouched.

    :param command_line: The unicode string to split into an arg list.
    :param single_quotes_allowed: Whether single quotes are accepted as quoting
                                  characters like double quotes. False by
                                  default.
    :return: A list of unicode strings.
    )Úsingle_quotes_allowedz-Split command line can't be shorter than argvN)
ÚcmdlineÚSplitterÚlistÚlenÚAssertionErrorr¢   Ú	has_magicÚappendr¨   r¦   )Úcommand_lineÚargvrÉ   ÚsÚ	argumentsÚargsÚ	is_quotedÚargs           r&   Ú_command_line_to_argvrØ   g  sä   € õ 	×ÒØÐ,Að 	ñ 	Cô 	C€Aõ �Q‘”€Iõ ˆ9�~„~�˜D™	œ	Ò!Ð!ÝÐLÑMÔMÐMØ�#˜i™.œ.­3¨t©9¬9Ñ4Ð5Ð5Ô6€Ið €DØ#ð 'ð '‰ˆ	�3Øð 	'�DœN¨3Ñ/Ô/ð 	'Ø�KŠK˜ÑÔÐÐà�KŠK� ™œÑ&Ô&Ð&Ð&Ø€Kr%   c                 ó
  — t           j        j        }|                     dd| ¦  «        }|sCt                                ¦   «         }|dk    rdS |dk    rdS t                                |¦  «        ‚|                     |¦  «         dS )z>True if pid doesn't correspond to live process on this machiner   Fr   éW   T)r    r*   r+   ÚOpenProcessÚGetLastErrorrÂ   ÚCloseHandle)Úpidr+   ÚhandleÚ	errorcodes       r&   Ú_ctypes_is_local_pid_deadrá   ‘  sƒ   € åŒ}Ô%€HØ×!Ò! ! U¨CÑ0Ô0€FØð )Ý×'Ò'Ñ)Ô)ˆ	Ø˜Š>ˆ>à�5Ø˜"Š_ˆ_Ø�4Ý�oŠo˜iÑ(Ô(Ð(Ø×Ò˜Ñ Ô Ð Øˆ5r%   c           
      ó¦   — d}t           j        j        }|j        }t                                |dz   ¦  «        } || ddddd||¦  «        r|j        S dS )a  Return file system type for a drive on the system.

    Args:
      drive: Unicode string with drive including trailing backslash (e.g.
         "C:\")
    Returns:
      Windows filesystem type name (e.g. "FAT32", "NTFS") or None
      if the drive can not be found
    é   r   Nr   )r    r*   r+   ÚGetVolumeInformationWr^   r`   )ÚdriveÚMAX_FS_TYPE_LENGTHr+   ÚGetVolumeInformationÚfs_types        r&   Úget_fs_typeré   £  sq   € ð ÐÝŒ}Ô%€HØ#Ô9ÐÝ×*Ò*Ð+=ÀÑ+AÑBÔB€GØÐØØˆaØØØØÐ#ñô ð ð Œ}ÐØˆ4r%   )r   T)r<   r=   )F)$r   r¢   ri   rE   r   ÚglobalsÚWIN32_STDIN_HANDLEÚWIN32_STDOUT_HANDLErB   rh   ro   rx   r_   r…   r�   r´   ÚREG_EXPAND_SZr;   rZ   re   rl   rq   r   r‰   rŽ   r�   r–   r™   r¦   r«   r¹   rÇ   rØ   rá   Úis_local_pid_deadré   r$   r%   r&   ú<module>rï      sÑ  ðð" &Ð %à €€€Ø 	€	€	€	Ø €€€à $Ð $Ð $Ð $Ð $Ð $Ø €ˆGˆG‰IŒIð ñ ô ð ð Ð ØÐ ØÐ ð €àÐ Ø€ð €Ø€ØÐ ð 
€Ø€ð8Pð 8Pð 8Pð 8Pðv$ð $ð $ð $ð0ð ð ð %ð %ð %ð "ð "ð "ð(ð ð ð.&ð &ð &ð( "#Ð ð*ð *ð *ð&ð ð ðð ð ð<ð <ð <ð(ð ð ð&"ð "ð "ðJJð Jð Jð'ð 'ð 'ð 'ðTð ð ð .Ð ðð ð ð ð r%   