Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_winreg.cpython-39.opt-1.pyc

a

��gU�@s�ddlZddlZddlZddlZddlmZddlZddlmZm	Z	ej
ddgd�ddlTzejej�
d�d	ZWneefy�dZYn0e��dd
�Ze�dkr�dnd
Zedkr�dnd
Zde��fZdeZdeZddefddefddefddefdgd�efdgd�efddefd d!d"efd#d$d%efd&d'efg
ZGd(d)�d)ej �Z!Gd*d+�d+e!�Z"e�#ed,�Gd-d.�d.e!��Z$e�#ed/�Gd0d1�d1e!��Z%e&d2k�r�e�s�e'd3d4�e�(�dS)5�N)�support)�machine�
win32_edition�winreg�win)Zrequired_on)�*z--remote��ZAMD64TF)�rz Python Test Key [%d] - Delete Mez	SOFTWARE\zSOFTWARE\Classes\z	Int Value�-zQword Valuel�w�*M	z
String ValzA string valueZStringExpandzThe path is %path%zMulti-string)ZLotsZof�string�valuesz	Multi-nul)�rrrzRaw Datasbinarydataz
Big String�xi�?z
Big Binary�xi@uJapanese 日本u	日本語c@sTeZdZdd�Zdd�Zdefdd�Zdefdd	�Zdd
d�Z	ddd
�Z
dd�ZdS)�BaseWinregTestscCs|�tt�dS�N)�delete_tree�HKEY_CURRENT_USER�
test_key_name��self�r�,/usr/local/lib/python3.9/test/test_winreg.py�setUp6szBaseWinregTests.setUpcCsrzt||dt�}Wnty&YdS0zt|d�}WntyLYq\Yn0|�||�q(t|�t||�dS�Nr)�OpenKey�KEY_ALL_ACCESS�OSError�EnumKeyr�CloseKey�	DeleteKey)r�rootZsubkey�hkeyZ	subsubkeyrrrr;s
zBaseWinregTests.delete_tree�sub_keycCs$t|ttd�||t�}|�|jdk�|||�}tD]\}}}t||d||�q6t|�\}	}
}|�|	dd�|�|
dd�t|�\}	}
}|�|	dd�|�|
t	t�d�t
|�}t|�zt|�|�d�Wnt
y�Yn0t
|�}
|��zt|
�|�d�Wnt
�yYn0dS)N�
Default valuerrz"Not the correct number of sub keysz Not the correct number of valueszAIt appears the CloseKey() function does not close the actual key!zBIt appears the key.Close() function does not close the actual key!)�SetValuer�REG_SZ�
assertTrue�handle�	test_data�
SetValueEx�QueryInfoKey�assertEqual�len�intr �failr�Close)r�root_key�	subkeystr�	CreateKey�keyr$�
value_name�
value_data�
value_type�nkeys�nvalues�	since_modZint_sub_keyZint_keyrrr�_write_test_dataKs8

�z BaseWinregTests._write_test_datac	Cs8t|t�}|�|dd�||t�}|||���}d}zt||�}WntyVYqtYn0|�|tvdd�|d}q2|�|tt�d�tD]4\}	}
}t||	�\}}
|�||
d�|�|
|d�q�Wd�n1s�0Y|��t	|d�}|�||d	�zt	|d�|�
d
�Wnt�y*Yn0|��dS)Nr%z+Registry didn't give back the correct valuerTz&Didn't read back the correct test datarz'Didn't read the correct number of itemsz!Could not directly read the valuezRead subkey value wrongz2Was able to get a second key when I only have one!)�
QueryValuerr-�	EnumValuerr*r.�QueryValueExr1rr0)rr2r3r�valr5r$�index�datar6r7r8Zread_valZread_typrrr�_read_test_datausF
�

�
���$

zBaseWinregTests._read_test_datacCs�t|tdt�}t||dt�}tD]\}}}t||�q t|�\}}	}
|�|dd�|�|	dd�|��t||�zt||�|�	d�Wnt
y�Yn0|��t|t�zt|t�}|�	d�Wnt
y�Yn0dS)Nrzsubkey not empty before deletez Deleting the key twice succeededzCould open the non-existent key)rrrr*ZDeleteValuer,r-r1r!r0r)rr2r3r5r$r6r7r8r9r:r;rrr�_delete_test_data�s*



z!BaseWinregTests._delete_test_datacCs(|�||�|�||�|�||�dSr)r<rCrD)rr2r3rrr�	_test_all�szBaseWinregTests._test_allcCs�t||dtd�� }|�|jdk�Wd�n1s60Yt||dtd�� }|�|jdk�Wd�n1sv0YdS)Nr)r5r$�reserved�access)�CreateKeyExrr(r)�	OpenKeyEx)rr5r$ZckeyZokeyrrr�_test_named_args�s�.�z BaseWinregTests._test_named_argsN)r$)r$)�__name__�
__module__�__qualname__rrr4r<rrCrDrErJrrrrr4s�
*(

rc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Ze
�edkd�dd��Zdd�Zdd�Zdd�Zdd �Zd!S)"�LocalWinregTestscCs|�t�|�td�dS)Nu
日本-subkey)rErrrrr�test_registry_works�s
z$LocalWinregTests.test_registry_workscCs:dd�}|jt|d�dd�}|jt|d�|�t�dS)NcSst||dt�Sr)rHr�r5r$rrr�<lambda>��zILocalWinregTests.test_registry_works_extended_functions.<locals>.<lambda>)r4cSst||dt�Sr)rI�KEY_READrPrrrrQ�rR)r)r<rrCrD)rZckeZokerrr�&test_registry_works_extended_functions�s
z7LocalWinregTests.test_registry_works_extended_functionscCs|�tt�ttt�dSr)rJrrr!rrrr�test_named_arguments�sz%LocalWinregTests.test_named_argumentscCs2tdt�}|�|jd�|��|�|jd�dSr)�ConnectRegistry�HKEY_LOCAL_MACHINE�assertNotEqualr)r1r-�r�hrrr�,test_connect_registry_to_local_machine_works�s
z=LocalWinregTests.test_connect_registry_to_local_machine_workscCsdd�}|�t|�dS)NcSs
tdt�S)NZabcdefghijkl)rVrrrrrrQ�rRzCLocalWinregTests.test_nonexistent_remote_registry.<locals>.<lambda>)�assertRaisesr)r�connectrrr� test_nonexistent_remote_registry�sz1LocalWinregTests.test_nonexistent_remote_registrycCs2td�}|�t|�t�|�|tjdd�dS)Nz
%windir%\testZwindirz\test)ZExpandEnvironmentStringsr-�type�str�os�environ)r�rrrr�testExpandEnvironmentStrings�sz-LocalWinregTests.testExpandEnvironmentStringscCsfz@tdt��"}|�|jd�t�Wd�n1s40YWn ty`|�|jd�Yn0dSr)rVrWrXr)rr-rYrrr�test_context_manager�s&z%LocalWinregTests.test_context_managerc

s�d�G�fdd�dtj�}|�}|��z�tttd��R}td�D]8}t|�\}}}t|�D]}t||�}	t	||	d�q\qBWd�n1s�0YWd�|�
�tttd�ttt�n&d�|�
�tttd�ttt�0dS)NFcseZdZ�fdd�ZdS)z>LocalWinregTests.test_changing_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xxxxxxxxxxxxxxxrZchanging_value)r4rrr&r')rr5Z	use_shortZlong_string�s��donerr�runszBLocalWinregTests.test_changing_value.<locals>.VeryActiveThread.runN)rKrLrMrirrgrr�VeryActiveThreadsrjz\changing_valuei�rT)�	threading�Thread�startr4rr�ranger,r>r=�joinr!)
rrj�threadr5�_�num_subkeys�
num_values�t�i�namerrgr�test_changing_value�s,
�
2�z$LocalWinregTests.test_changing_valuecCs�d}zrttt��6}t||td�t|�\}}}t|d�Wd�n1sL0YWttd�t|f��ttt�n ttd�t|f��ttt�0dS)NAxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxrr�\)	r4rrr&r'r,rr!ro)rrvr5rrrsrtrrr�
test_long_keys*�zLocalWinregTests.test_long_keyc
Cs`zttd�WnBtyP}z*|jtjtjfvr:|�d��WYd}~n
d}~00ttd�dS)NrzMaccess denied to registry key (are you running in a non-interactive session?)r)r>ZHKEY_PERFORMANCE_DATAr�errnoZEPERMZEACCESZskipTestr?)r�errr�test_dynamic_key)s
z!LocalWinregTests.test_dynamic_key)�r	zRequires Windows XPc	Cs>�z*ttt��}|�|jd�Wd�n1s20Yttt�}|�|jd�|�t��t|�Wd�n1s|0Y|�t��t	|�Wd�n1s�0Y|�t��t
|�Wd�n1s�0Y|�t��ttt�Wd�n1�s0YWttt�nttt�0dSr)
r4rrrXr)rr\�NotImplementedError�DisableReflectionKey�EnableReflectionKey�QueryReflectionKey�DeleteKeyExr!)r�ckr5rrr�test_reflection_unsupported7s,
&&&,z,LocalWinregTests.test_reflection_unsupportedc	CshzVttt��.}|�|jd�t|ddtd�Wd�n1s@0YWttt�nttt�0dS)Nr�	test_name�)r4rrrXr)r+�	REG_DWORDr!)rr�rrr�test_setvalueex_value_rangeKs
0z,LocalWinregTests.test_setvalueex_value_rangec	Cs�z�ttt��X}|�|jd�d}t|ddt|�t|d�\}}|�|t�|�||�Wd�n1sj0YWt	tt�nt	tt�0dS)Nrr�r�)
r4rrrXr)r+r�r?r-r!�rr�Ztest_valZret_valZret_typerrr�test_queryvalueex_return_valueWs,z/LocalWinregTests.test_queryvalueex_return_valuec	Cs�z�ttt��X}|�|jd�d}t|ddt|�t|d�\}}|�|t�|�||�Wd�n1sj0YWt	tt�nt	tt�0dS)Nrr�)
r4rrrXr)r+�
REG_BINARYr?r-r!r�rrr�#test_setvalueex_crash_with_none_arggs,z4LocalWinregTests.test_setvalueex_crash_with_none_argc	Cs�z�ttt��X}|�|jd�d}t|ddt|�t|d�\}}|�|t�|�|d�Wd�n1sj0YWt	tt�nt	tt�0dS)NrzA string with a nullr�zA string)
r4rrrXr)r+r'r?r-r!r�rrr� test_read_string_containing_nullts,z1LocalWinregTests.test_read_string_containing_nullN)rKrLrMrOrTrUr[r^rdrerwryr|�unittest�
skipUnless�WIN_VERr�r�r�r�r�rrrrrN�s 	 

rNzSkipping remote registry testsc@seZdZdd�ZdS)�RemoteWinregTestscCsttt�}|�|�dSr)rV�REMOTE_NAMErrE)rZ
remote_keyrrr�test_remote_registry_works�s
z,RemoteWinregTests.test_remote_registry_worksN)rKrLrMr�rrrrr��sr�zx64 specific registry testsc@s^eZdZdd�Ze�e�dvd�dd��Ze�e	d�dd	��Z
e�e	d�d
d��Zdd
�ZdS)�Win64WinregTestscCs |�tt�ttttdd�dS)Nr)r5r$rGrF)rJrrr�rrrrrrU�s�z%Win64WinregTests.test_named_arguments)ZWindowsCoreHeadlessZ	IoTEdgeOSz)APIs not available on WindowsCoreHeadlesscCsfttd��H}|�t|��|�t|��|�t|��|�t|��Wd�n1sX0YdS)NZSoftware)rrWr(r�ZassertIsNoner�r)rr5rrr�test_reflection_functions�s
z*Win64WinregTests.test_reflection_functionszOS doesn't support reflectioncCsx�z`tttdttB���}|�|jd�tttdttB��}|�|jd�Wd�n1s\0Yt|ddt	d�dd�}|�
t|�Wd�n1s�0YtttdttB��@}|�|jd�|�
dt|d��t|ddt	d�Wd�n1�s0YtttdttB��"}|�
dt|d��Wd�n1�sH0YWttttd�nttttd�0dS)NrrZ32KEYcSstttdttB�Sr)rr�test_reflect_key_namerS�KEY_WOW64_64KEYrrrrrQ�s�z2Win64WinregTests.test_reflection.<locals>.<lambda>Z64KEY)rHrr�r�KEY_WOW64_32KEYrXr)rr+r'r\rr�r-r=rSr�)r�created_keyr5�	open_failrrr�test_reflection�s>��,*�0�4��z Win64WinregTests.test_reflectioncCs�z�tttdttB��H}t|�}|�t|�t�|�	|�t
|�|�t|��Wd�n1sb0Ydd�}|�t
|�tttdttB��}|�|jd�Wd�n1s�0YWttttd�nttttd�0dS)NrcSstttdttB�Sr)rIrr�rSr�rrrrrQ�s�z:Win64WinregTests.test_disable_reflection.<locals>.<lambda>)rHrr�rr�r�r-r_�boolZassertFalserr(r\rrIrSrXr)r�)rr��disabledr�r5rrr�test_disable_reflection�s,�
,�.��z(Win64WinregTests.test_disable_reflectioncCs8|�t��}ttd�Wd�n1s*0YdS)NZsome_value_that_does_not_exist)r\�FileNotFoundErrorr=ZHKEY_CLASSES_ROOT)r�ctxrrr�test_exception_numbers�sz'Win64WinregTests.test_exception_numbersN)
rKrLrMrUr�ZskipIfrr�r��HAS_REFLECTIONr�r�r�rrrrr��s



+

r��__main__z)Remote registry calls can be tested usingz('test_winreg.py --remote \\machine_name'))ra�sysrzr��testrrk�platformrr�
import_moduler�argvrAr��
IndexError�
ValueError�getwindowsversionr�Z
WIN64_MACHINEr��getpidZ
test_key_baserr�r�Z	REG_QWORDr'Z
REG_EXPAND_SZZREG_MULTI_SZr�r*ZTestCaserrNr�r�r�rK�print�mainrrrr�<module>sR
�9

b
�

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists