HEX
Server: LiteSpeed
System: Linux atali.colombiahosting.com.co 5.14.0-570.12.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Tue May 13 06:11:55 EDT 2025 x86_64
User: coopserp (1713)
PHP: 8.2.29
Disabled: dl,exec,passthru,proc_open,proc_close,shell_exec,memory_limit,system,popen,curl_multi_exec,show_source,symlink,link,leak,listen,diskfreespace,tmpfile,ignore_user_abord,highlight_file,source,show_source,fpaththru,virtual,posix_ctermid,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setid,posix_times,posix_ttyname,posix_uname,proc_get_status,proc_nice,proc_terminate
Upload Files
File: //usr/local/lib64/python3.9/site-packages/psutil/tests/__pycache__/test_unicode.cpython-39.pyc
a

��?h;1�@sdZddlZddlZddlZddlZddlmZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$e�r�dd �Z!d!d"�Z%Gd#d$�d$e�Z&ej'j(d%d&�ej'j)ed'd(�ej'j)e�o�ed)d(�Gd*d+�d+e&����Z*ej'j)ed,d(�Gd-d.�d.e*��Z+Gd/d0�d0e&�Z,dS)1a>	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.cwd()
* Process.environ()
* Process.exe()
* Process.memory_maps()
* Process.name()
* Process.net_connections('unix')
* 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)�POSIX)�WINDOWS)�PY3)�super)�APPVEYOR)�ASCII_FS)�
CI_TESTING)�HAS_ENVIRON)�HAS_MEMORY_MAPS)�HAS_NET_CONNECTIONS_UNIX)�INVALID_UNICODE_SUFFIX)�PYPY��
TESTFN_PREFIX)�UNICODE_SUFFIX)�PsutilTestCase)�bind_unix_socket)�chdir)�copyload_shared_lib)�
create_py_exe)�
get_testfn)�pytest)�
safe_mkdir��safe_rmpath)�skip_on_access_denied)�spawn_testproc)�	terminatecCs6ddlm}z
||�WSty0t��Yn0dS)Nrr)�psutil.testsrZWindowsError�	traceback�	print_exc)�pathZrm�r$�E/usr/local/lib64/python3.9/site-packages/psutil/tests/test_unicode.pyrqs

rc	Cs�d}t|d�}z�z<t|�t|�t|gd�}t�||d�t|d�Wn2ttfy~YW|durrt|�t|�dS0W|dur�t|�t|�dSW|dur�t|�t|�n|dur�t|�t|�0dS)z`Return True if both the fs and the subprocess module can
    deal with a unicode file name.
    N��suffix)�cmdz-2FT)	rrrr�shutil�copyfile�UnicodeEncodeError�IOErrorr)r'�sprocZtestfnr$r$r%�try_unicode�s2
��
�r.cs0eZdZdZe�fdd��Z�fdd�Z�ZS)�BaseUnicodeTestNcsNt���d|_d|_|jdurJt|j�s2d|_nt|jd�|_t|j�dS)NFTr&)r�
setUpClass�
skip_tests�
funky_name�funky_suffixr.rr)�cls��	__class__r$r%r0�s


zBaseUnicodeTest.setUpClasscst���|jrt�d��dS)Nzcan't handle unicode str)r�setUpr1r�skip��selfr5r$r%r7�s
zBaseUnicodeTest.setUp)�__name__�
__module__�__qualname__r3�classmethodr0r7�
__classcell__r$r$r5r%r/�sr/�serial)�namezASCII fs��reasonztoo much trouble on PYPY2c@s�eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
ejj
eoDedd
�dd��Zejj
edd
�dd��Zejj
edd
�ejj
edd
�e�dd����Zdd�Zejj
edd
�ejj
edd
�ejj
edd
�dd����ZdS)�
TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.cCsZt|jt�rdnd}t���*t�d�|jt�|�vWd�S1sL0YdS)N�.�ignore)�
isinstancer2�str�warnings�catch_warnings�simplefilter�os�listdir)r:�herer$r$r%�expect_exact_path_match�s

z"TestFSAPIs.expect_exact_path_matchcCsb|jddg}|�|�}t�|j�}|��}t|t�s8J�|��r^t	j
�|�t	j
�|j�ks^J�dS�Nz-cz2import time; [time.sleep(0.1) for x in range(100)])r2r�psutil�Process�pid�exerGrHrOrLr#�normcase)r:r(�subp�prTr$r$r%�
test_proc_exe�s�
zTestFSAPIs.test_proc_execCsV|jddg}|�|�}t�|j���}t|t�s4J�|��rR|t	j
�|j�ksRJ�dSrP)r2rrQrRrSrArGrHrOrLr#�basename)r:r(rVrAr$r$r%�test_proc_name�s�
zTestFSAPIs.test_proc_namecCsZ|jddg}|�|�}t�|j�}|��}|D]}t|t�s.J�q.|��rV||ksVJ�dSrP)	r2rrQrRrS�cmdlinerGrHrO)r:r(rVrWr[�partr$r$r%�test_proc_cmdline�s�
zTestFSAPIs.test_proc_cmdlinecCs�|jd}|�t|�t|�t|�� t��}|��}Wd�n1sL0Yt|��t	�shJ�|�
�r|||ks|J�dS�N�2)r2�
addCleanuprrrrQrR�cwdrGrHrO)r:�dnamerWrar$r$r%�
test_proc_cwd�s

&zTestFSAPIs.test_proc_cwdzfails on PYPY + WINDOWSrBcCs�t��}t|���}t|jd��t|���}Wd�n1sB0Y||��j}t|t	�shJ�t
rz|szt�d��|�
�r�tj�|�tj�|j�ks�J�dS)N�rbzopen_files on BSD is broken)rQrR�setZ
open_files�openr2�popr#rGrHrrr8rOrLrU)r:rW�start�newr#r$r$r%�test_proc_open_files�s*
zTestFSAPIs.test_proc_open_filesz
POSIX onlycCs�|j|jd�}zt|�}Wn$ty>tr0�n
t�d��Yn0t|��@t�	��
d�d}t|jt
�slJ�|j|kszJ�Wd�n1s�0YdS)Nr&�
not supported�unixr)rr3rr+rrr8rrQrR�net_connectionsrG�laddrrH)r:rA�sock�connr$r$r%�test_proc_net_connectionss
z$TestFSAPIs.test_proc_net_connectionszcan't list UNIX socketscCs�dd�}|j|jd�}zt|�}Wn$tyFtr8�n
t�d��Yn0t|��Btj	dd�}||�}t
|jt�svJ�|j|ks�J�Wd�n1s�0YdS)NcSs2|D] }tj�|j��t�r|Sqtd��dS)Nzconnection not found)rLr#rYrn�
startswithr�
ValueError)�consrpr$r$r%�	find_socks
z2TestFSAPIs.test_net_connections.<locals>.find_sockr&rkrl)�kind)
rr3rr+rrr8rrQrmrGrnrH)r:rurArortrpr$r$r%�test_net_connectionss
zTestFSAPIs.test_net_connectionscCs,|jd}|�t|�t|�t�|�dSr^)r2r`rrrQ�
disk_usage)r:rbr$r$r%�test_disk_usage/s
zTestFSAPIs.test_disk_usagerkz&ctypes does not support unicode on PY2zunstable on PYPYcs�t|jd��h}dd���fdd�t����D�}dd�|D�}�|�|vsNJ�|D]}t|t�sRJ�qRWd�n1sz0YdS)Nr&cSstj�tj�|��S)N)rLr#�realpathrU)rWr$r$r%�normpath?sz-TestFSAPIs.test_memory_maps.<locals>.normpathcsg|]}�|j��qSr$)r#��.0�x�r{r$r%�
<listcomp>Bsz/TestFSAPIs.test_memory_maps.<locals>.<listcomp>cSsg|]}t|vr|�qSr$rr|r$r$r%r�F�)rr3rQrRZmemory_mapsrGrH)r:Z
funky_pathZlibpathsr#r$rr%�test_memory_maps5s

�zTestFSAPIs.test_memory_mapsN)r;r<r=�__doc__rr3rOrXrZr]rcr�mark�skipifrrrjrrqr
rrwryrrr�r$r$r$r%rD�s0




��rDzunreliable on CIc@seZdZdZeZdd�ZdS)�TestFSAPIsWithInvalidPathz-Test FS APIs with a funky, invalid path name.cCsdS)NTr$r9r$r$r%rORsz1TestFSAPIsWithInvalidPath.expect_exact_path_matchN)r;r<r=r�rr3rOr$r$r$r%r�Lsr�c@sJeZdZdZerendZejj	e
dd�ejj	eo4edd�dd���Z
dS)	�
TestNonFSAPISz&Unicode tests for non fs-related APIs.�èrkrBzsegfaults on PYPY + WINDOWScCsxtj��}|j|d<|j|d�}t�|j�}|��}|��D]$\}}t	|t
�sRJ�t	|t
�s<J�q<|d|jkstJ�dS)NZ	FUNNY_ARG)�env)rL�environ�copyr3rrQrRrS�itemsrGrH)r:r�r-rW�k�vr$r$r%�test_proc_environas

zTestNonFSAPIS.test_proc_environN)r;r<r=r�rrr3rr�r�rrrr�r$r$r$r%r�\s
r�)-r�rLr)r!rI�
contextlibrrQrrrZpsutil._compatrrr rr	r
rrr
rrrrrrrrrrrrrrrrr.r/r�Zxdist_groupr�rDr�r�r$r$r$r%�<module>sZC