403Webshell
Server IP : 217.160.0.135  /  Your IP : 216.73.217.85
Web Server : Apache
System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64
User : sws1074145052 ( 1074145052)
PHP Version : 8.3.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /lib/python3/dist-packages/psutil/tests/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /lib/python3/dist-packages/psutil/tests/__pycache__/test_unicode.cpython-311.pyc
�

�bic�0����dZddlZddlZddlZddlZddlZddlmZddlZddlm	Z	ddlm
Z
ddlmZddlmZddl
mZdd	l
mZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddlm%Z%ddlm&Z&erd �Z"d!�Z'Gd"�d#e��Z(e#ej)ed$��ej)eoed%��Gd&�d'e(��������Z*ej)ed(��Gd)�d*e*����Z+Gd+�d,e(��Z,e-d-krdd.l.m/Z/e/e0��dSdS)/a:	
Notes about unicode handling in psutil
======================================

Starting from version 5.3.0 psutil adds unicode support, see:
https://github.com/giampaolo/psutil/issues/1040
The notes below apply to *any* API returning a string such as
process exe(), cwd() or username():

* all strings are encoded by using the OS filesystem encoding
  (sys.getfilesystemencoding()) which varies depending on the platform
  (e.g. "UTF-8" on macOS, "mbcs" on Win)
* no API call is supposed to crash with UnicodeDecodeError
* instead, in case of badly encoded data returned by the OS, the
  following error handlers are used to replace the corrupted characters in
  the string:
    * Python 3: sys.getfilesystemencodeerrors() (PY 3.6+) or
      "surrogatescape" on POSIX and "replace" on Windows
    * Python 2: "replace"
* on Python 2 all APIs return bytes (str type), never unicode
* on Python 2, you can go back to unicode by doing:

    >>> unicode(p.exe(), sys.getdefaultencoding(), errors="replace")

For a detailed explanation of how psutil handles unicode see #1040.

Tests
=====

List of APIs returning or dealing with a string:
('not tested' means they are not tested to deal with non-ASCII strings):

* Process.cmdline()
* Process.connections('unix')
* Process.cwd()
* Process.environ()
* Process.exe()
* Process.memory_maps()
* Process.name()
* Process.open_files()
* Process.username()             (not tested)

* disk_io_counters()             (not tested)
* disk_partitions()              (not tested)
* disk_usage(str)
* net_connections('unix')
* net_if_addrs()                 (not tested)
* net_if_stats()                 (not tested)
* net_io_counters()              (not tested)
* sensors_fans()                 (not tested)
* sensors_temperatures()         (not tested)
* users()                        (not tested)

* WindowsService.binpath()       (not tested)
* WindowsService.description()   (not tested)
* WindowsService.display_name()  (not tested)
* WindowsService.name()          (not tested)
* WindowsService.status()        (not tested)
* WindowsService.username()      (not tested)

In here we create a unicode path with a funky non-ASCII name and (where
possible) make psutil return it back (e.g. on name(), exe(), open_files(),
etc.) and make sure that:

* psutil never crashes with UnicodeDecodeError
* the returned path matches
�N)�closing)�BSD)�OPENBSD)�POSIX)�WINDOWS)�PY3)�u)�APPVEYOR)�ASCII_FS)�
CI_TESTING)�HAS_CONNECTIONS_UNIX)�HAS_ENVIRON)�HAS_MEMORY_MAPS)�INVALID_UNICODE_SUFFIX)�PYPY��
TESTFN_PREFIX)�UNICODE_SUFFIX)�PsutilTestCase)�bind_unix_socket)�chdir)�copyload_shared_lib)�
create_exe)�
get_testfn)�
safe_mkdir��safe_rmpath)�	serialrun)�skip_on_access_denied)�spawn_testproc)�	terminatec�n�ddlm}	||��S#t$rtj��YdSwxYw)Nrr)�psutil.testsr�WindowsError�	traceback�	print_exc)�path�rms  �;/usr/lib/python3/dist-packages/psutil/tests/test_unicode.pyrrss[��	3�2�2�2�2�2�	"��2�d�8�8�O���	"�	"�	"���!�!�!�!�!�!�	"���s�
�4�4c���d}t|���}	t|��t|��t|g���}t	j||dz��t|dz��	|�t
|��t|��dS#ttf$r$Y|�t
|��t|��dSwxYw#|�t
|��t|��wxYw)z`Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    N��suffix��cmdz-2TF)	rrrr �shutil�copyfiler!�UnicodeEncodeError�IOError)r,�sproc�testfns   r)�try_unicoder5�s��
�E�
�v�
&�
&�
&�F�
��F�����6�����F�8�,�,�,�������
�.�.�.��F�T�M�"�"�"�����e�����F�������
��(��������e�����F�����������
���e�����F�������s$�AB�C�!C�C�C�"C*c��eZdZdZd�ZdS)�BaseUnicodeTestNc�j�|j�)t|j��s|�d���dSdS)Nzcan't handle unicode str)�funky_suffixr5�skipTest)�selfs r)�setUpzBaseUnicodeTest.setUp�sF����(��t�0�1�1�
@��m�m�$>�?�?�?�)�(�
@�
@�)�__name__�
__module__�__qualname__r9r<�r=r)r7r7�s-�������L�@�@�@�@�@r=r7zASCII fsztoo much trouble on PYPY2c���eZdZdZeZed���Zed���Zd�Z	d�Z
d�Zd�Zd�Z
ejeoed	��d
���Zejed��d���Zejed��ejed
��e��d�������Zd�Zejed��ejed��ejed��d�������ZdS)�
TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.c�b�t|j���|_t|j��dS)Nr+)rr9�
funky_namer��clss r)�
setUpClasszTestFSAPIs.setUpClass�s-��#�3�+;�<�<�<����3�>�"�"�"�"�"r=c�.�t|j��dS�N)rrErFs r)�
tearDownClasszTestFSAPIs.tearDownClass�s���C�N�#�#�#�#�#r=c��t|jt��rdntd��}t	j��5t	jd��|jtj|��vcddd��S#1swxYwYdS)N�.�ignore)	�
isinstancerE�strr	�warnings�catch_warnings�simplefilter�os�listdir)r;�heres  r)�expect_exact_path_matchz"TestFSAPIs.expect_exact_path_match�s���!���#�6�6�B�s�s�A�c�F�F��
�
$�
&�
&�	7�	7��!�(�+�+�+��?�b�j��&6�&6�6�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7�	7����	7�	7�	7�	7�	7�	7s�/A;�;A?�A?c��|�|jg���}tj|j��}|���}|�|t��|���rW|�	tj�|��tj�|j����dSdS�Nr-)
r rE�psutil�Process�pid�exe�assertIsInstancerPrW�assertEqualrTr'�normcase)r;�subp�pr]s    r)�
test_proc_exezTestFSAPIs.test_proc_exe�s����"�"���'8�"�9�9���N�4�8�$�$���e�e�g�g�����c�3�'�'�'��'�'�)�)�	@����R�W�-�-�c�2�2��W�-�-�d�o�>�>�
@�
@�
@�
@�
@�	@�	@r=c�f�|�|jg���}tj|j�����}|�|t��|���r:|�	|tj�|j����dSdSrY)
r rErZr[r\�namer^rPrWr_rTr'�basename)r;rares   r)�test_proc_namezTestFSAPIs.test_proc_name�s����"�"���'8�"�9�9���~�d�h�'�'�,�,�.�.�����d�C�(�(�(��'�'�)�)�	F����T�2�7�#3�#3�D�O�#D�#D�E�E�E�E�E�	F�	Fr=c�<�|�|jg���}tj|j��}|���}|D]}|�|t���|���r|�	||jg��dSdSrY)
r rErZr[r\�cmdliner^rPrWr_)r;rarbri�parts     r)�test_proc_cmdlinezTestFSAPIs.test_proc_cmdline�s����"�"���'8�"�9�9���N�4�8�$�$���)�)�+�+���	-�	-�D��!�!�$��,�,�,�,��'�'�)�)�	9����W�t��&7�8�8�8�8�8�	9�	9r=c��|jdz}|�t|��t|��t	|��5tj��}|���}ddd��n#1swxYwY|�|���t��|�
��r|�||��dSdS�N�2)rE�
addCleanuprrrrZr[�cwdr^rPrWr_)r;�dnamerbrps    r)�
test_proc_cwdzTestFSAPIs.test_proc_cwd�s����#�%������U�+�+�+��5����
�5�\�\�	�	��� � �A��%�%�'�'�C�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	�	
���a�e�e�g�g�s�+�+�+��'�'�)�)�	)����S�%�(�(�(�(�(�	)�	)s�(A8�8A<�?A<zfails on PYPY + WINDOWSc��tj��}t|�����}t	|jd��5t|�����}ddd��n#1swxYwY||z
���j}|�|t��tr|s|�d��S|���rW|�
tj�|��tj�|j����dSdS)N�rbzopen_files on BSD is broken)rZr[�set�
open_files�openrE�popr'r^rPrr:rWr_rTr`)r;rb�start�newr's     r)�test_proc_open_fileszTestFSAPIs.test_proc_open_files�sa���N�����A�L�L�N�N�#�#��
�$�/�4�
(�
(�	&�	&��a�l�l�n�n�%�%�C�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&�	&����	&�	&�	&�	&��e�� � �"�"�'�����d�C�(�(�(��	@�t�	@��=�=�!>�?�?�?��'�'�)�)�	@����R�W�-�-�d�3�3��W�-�-�d�o�>�>�
@�
@�
@�
@�
@�	@�	@s�
"A8�8A<�?A<z
POSIX onlyc���|�|j���}	t|��}n*#t$rtr�tjd���wxYwt|��5tj	���
d��d}|�|jt��ts|�|j|��ddd��dS#1swxYwYdS)Nr+�
not supported�unixr)rr9rr1r�unittest�SkipTestrrZr[�connectionsr^�laddrrPrr_)r;re�sock�conns    r)�test_proc_connectionsz TestFSAPIs.test_proc_connections�s-�����d�&7��8�8��	9�#�D�)�)�D�D��!�	9�	9�	9��
9���'��8�8�8�		9����
�T�]�]�	3�	3��>�#�#�/�/��7�7��:�D��!�!�$�*�c�2�2�2��
3�� � ���T�2�2�2�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3s�-�'A�&A/C"�"C&�)C&zcan't list UNIX socketsc���d�}|�|j���}	t|��}n*#t$rtr�tjd���wxYwt|��5tj	d���}tsF||��}|�|jt��|�|j|��ddd��dS#1swxYwYdS)Nc��|D]B}tj�|j���t
��r|cS�Ct
d���)Nzconnection not found)rTr'rfr��
startswithr�
ValueError)�consr�s  r)�	find_sockz2TestFSAPIs.test_net_connections.<locals>.find_socksV���
 �
 ���7�#�#�D�J�/�/�:�:�=�I�I� ��K�K�K� ��3�4�4�4r=r+r}r~)�kind)rr9rr1rrr�rrZ�net_connectionsrr^r�rPr_)r;r�rer�r�r�s      r)�test_net_connectionszTestFSAPIs.test_net_connectionss>��	5�	5�	5����d�&7��8�8��	9�#�D�)�)�D�D��!�	9�	9�	9��
9���'��8�8�8�		9����
�T�]�]�	3�	3��)�v�6�6�6�D��
3� �y������%�%�d�j�#�6�6�6�� � ���T�2�2�2�
	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3�	3����	3�	3�	3�	3�	3�	3s�0�'A�)A#C�C� Cc��|jdz}|�t|��t|��t	j|��dSrm)rErorrrZ�
disk_usage)r;rqs  r)�test_disk_usagezTestFSAPIs.test_disk_usage"sG����#�%������U�+�+�+��5������%� � � � � r=r}z&ctypes does not support unicode on PY2zunstable on PYPYc�d��t|j���5}d���fd�tj�����D��}d�|D��}|��|��|��|D]}|�|t���	ddd��dS#1swxYwYdS)Nr+c�z�tj�tj�|����SrJ)rTr'�realpathr`)rbs r)�normpathz-TestFSAPIs.test_memory_maps.<locals>.normpath/s(���w�'�'���(8�(8��(;�(;�<�<�<r=c�0��g|]}�|j����SrA)r')�.0�xr�s  �r)�
<listcomp>z/TestFSAPIs.test_memory_maps.<locals>.<listcomp>1s;���A�A�A��!����(�(�A�A�Ar=c�$�g|]
}t|v�|��SrAr)r�r�s  r)r�z/TestFSAPIs.test_memory_maps.<locals>.<listcomp>4s"��B�B�B�a�}��/A�/A��/A�/A�/Ar=)rr9rZr[�memory_maps�assertInr^rP)r;�
funky_path�libpathsr'r�s    @r)�test_memory_mapszTestFSAPIs.test_memory_maps(s-���!��(9�
:�
:�
:�		1�j�
=�
=�
=�A�A�A�A�!'��!1�!1�!=�!=�!?�!?�A�A�A�H�C�B�8�B�B�B�H��M�M�(�(�:�.�.��9�9�9� �
1�
1���%�%�d�C�0�0�0�0�
1�		1�		1�		1�		1�		1�		1�		1�		1�		1�		1�		1�		1����		1�		1�		1�		1�		1�		1s�BB%�%B)�,B)N)r>r?r@�__doc__rr9�classmethodrHrKrWrcrgrkrrr�skipIfrrr{rr�r
rr�r�rrr�rAr=r)rCrC�s�������<�;�!�L��#�#��[�#��$�$��[�$�7�7�7�@�@�@�F�F�F�9�9�9�	)�	)�	)��X�_�T�%�g�'@�A�A�@�@�B�A�@��X�_��Y��-�-�3�3�.�-�3� �X�_��Y��-�-��X�_�-�-�/H�I�I�����3�3���J�I�.�-�3�.!�!�!��X�_��(�/�:�:��X�_��W�F�G�G��X�_�T�-�.�.�1�1�/�.�H�G�;�:�1�1�1r=rCzunreliable on CIc�,�eZdZdZeZed���ZdS)�TestFSAPIsWithInvalidPathz-Test FS APIs with a funky, invalid path name.c��dS)NTrArFs r)rWz1TestFSAPIsWithInvalidPath.expect_exact_path_match?s	���tr=N)r>r?r@r�rr9r�rWrAr=r)r�r�:s8������7�7�)�L�����[���r=r�c��eZdZdZerendZeje	d��eje
oed��d�����ZdS)�
TestNonFSAPISz&Unicode tests for non fs-related APIs.�èr}zsegfaults on PYPY + WINDOWSc��tj���}|j|d<|�|���}tj|j��}|���}|���D];\}}|�	|t��|�	|t���<|�|d|j��dS)N�	FUNNY_ARG)�env)rT�environ�copyr9r rZr[r\�itemsr^rPr_)r;r�r3rb�k�vs      r)�test_proc_environzTestNonFSAPIS.test_proc_environNs����j�o�o�����,��K���#�#��#�,�,���N�5�9�%�%���i�i�k�k���I�I�K�K�	*�	*�D�A�q��!�!�!�S�)�)�)��!�!�!�S�)�)�)�)�����[�)�4�+<�=�=�=�=�=r=N)
r>r?r@r�rrr9rr�rrrr�rAr=r)r�r�Jsr������0�0�%(�2�>�>�d�L��X�_��_�o�6�6��X�_�T�%�g�'D�E�E�>�>�F�E�7�6�>�>�>r=r��__main__)�
run_from_name)1r�rTr/r%rrQ�
contextlibrrZrrrr�psutil._compatrr	r#r
rrr
rrrrrrrrrrrrrrrrr r!r5r7r�rCr�r�r>�psutil.tests.runnerr��__file__rAr=r)�<module>r�s���B�B�H
�	�	�	�
�
�
�
�������������������
�
�
�
�������������������������������������!�!�!�!�!�!�!�!�!�!�!�!�#�#�#�#�#�#�-�-�-�-�-�-�$�$�$�$�$�$�(�(�(�(�(�(�/�/�/�/�/�/�������&�&�&�&�&�&�'�'�'�'�'�'�'�'�'�'�'�'�)�)�)�)�)�)�������,�,�,�,�,�,�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�#�$�$�$�$�$�$�"�"�"�"�"�"�.�.�.�.�.�.�'�'�'�'�'�'�"�"�"�"�"�"��"�"�"�"�$���6@�@�@�@�@�n�@�@�@������:�&�&�����!�c�'�#>�?�?�K1�K1�K1�K1�K1��K1�K1�@�?�'�&���K1�\����/�0�0������
���1�0��>�>�>�>�>�O�>�>�>�.�z���1�1�1�1�1�1��M�(�������r=

Youez - 2016 - github.com/yon3zu
LinuXploit