HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //opt/osm/venv/lib/python3.10/site-packages/psutil/tests/__pycache__/test_unicode.cpython-310.pyc
o

=i�)�@s�dZddlZddlZddlZddlmZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZdd	lmZdd
l
mZddl
mZddl
mZdd
l
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
mZddl
m Z ddl
m!Z!ddl
m"Z"dd �Z#Gd!d"�d"e�Z$ej%j&d#d$�ej%j'ed%d&�Gd'd(�d(e$���Z(ej%j'ed)d&�Gd*d+�d+e(��Z)Gd,d-�d-e$�Z*dS).aYNotes 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:
    * sys.getfilesystemencodeerrors() or "surrogatescape" on POSIX and
      "replace" on Windows.

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��MACOS)�NETBSD)�OPENBSD)�POSIX)�WINDOWS)�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_subproc)�	terminatec	Cs�d}t|d�}zGzt|�t|�t|gd�}t�||d�t|d�Wnttfy?YW|dur9t|�t|�dSwW|durIt|�t|�dS|durWt|�t|�w)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�OSErrorr)r!�sprocZtestfn�r(�G/opt/osm/venv/lib/python3.10/site-packages/psutil/tests/test_unicode.py�try_unicodehs*
��
r*cs0eZdZdZe�fdd��Z�fdd�Z�ZS)�BaseUnicodeTestNcsTt���d|_d|_|jdur(t|j�sd|_dSt|jd�|_t|j�dSdS)NFTr )�super�
setUpClass�
skip_tests�
funky_name�funky_suffixr*rr)�cls��	__class__r(r)r-�s



�zBaseUnicodeTest.setUpClasscst���|jr
t�d�SdS)Nzcan't handle unicode str)r,�setUpr.r�skip��selfr2r(r)r4�s

�zBaseUnicodeTest.setUp)�__name__�
__module__�__qualname__r0�classmethodr-r4�
__classcell__r(r(r2r)r+�s
r+�serial)�namezASCII fs��reasonc@s�eZdZdZeZdd�Zdd�Zdd�Zdd	�Z	d
d�Z
ejj
eo"edd
�ejj
ep+edd
�dd���Zejj
edd
�ejj
edd
�dd���Zejj
edd
�ejj
edd
�e�dd����Zdd�Zejj
edd
�dd��ZdS)�
TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.cCsFt���t�d�|jt�d�vWd�S1swYdS)N�ignore�.)�warnings�catch_warnings�simplefilterr/�os�listdirr6r(r(r)�expect_exact_path_match�s

$�z"TestFSAPIs.expect_exact_path_matchcCsf|jddg}|�|�}t�|j�}|��}t|t�sJ�|��r/t	j
�|�t	j
�|j�ks1J�dSdS�Nz-cz2import time; [time.sleep(0.1) for x in range(100)])r/r�psutil�Process�pid�exe�
isinstance�strrIrG�path�normcase)r7r"�subp�prNr(r(r)�
test_proc_exe�s�
�zTestFSAPIs.test_proc_execCsZ|jddg}|�|�}t�|j���}t|t�sJ�|��r)|t	j
�|j�ks+J�dSdSrJ)r/rrKrLrMr>rOrPrIrGrQ�basename)r7r"rSr>r(r(r)�test_proc_name�s�
�zTestFSAPIs.test_proc_namecCs^|jddg}|�|�}t�|j�}|��}|D]	}t|t�s J�q|��r+||ks-J�dSdSrJ)	r/rrKrLrM�cmdlinerOrPrI)r7r"rSrTrX�partr(r(r)�test_proc_cmdline�s�
�zTestFSAPIs.test_proc_cmdlinecCs�|jd}|�t|�t|�t|��t��}|��}Wd�n1s&wYt|��t	�s4J�|�
�r>||ks@J�dSdS�N�2)r/�
addCleanuprrrrKrL�cwdrOrPrI)r7�dnamerTr^r(r(r)�
test_proc_cwd�s


��zTestFSAPIs.test_proc_cwdzfails on PYPY + WINDOWSr?zbroken on NETBSD or OPENBSDcCs�t��}t|���}t|jd��t|���}Wd�n1s!wY||��j}t|t	�s4J�t
r=|s=t�d�S|�
�rPtj�|�tj�|j�ksRJ�dSdS)N�rbzopen_files on BSD is broken)rKrL�setZ
open_files�openr/�poprQrOrPrrr5rIrGrR)r7rT�start�newrQr(r(r)�test_proc_open_files�s�
�zTestFSAPIs.test_proc_open_filesz
POSIX onlyzcan't list UNIX socketscCs�|j|jd�}t|�}t|��4t���d�d}t|jt	�s!J�|js4t
r4tr4t�
d�Wd�S|j|ks;J�Wd�dS1sFwYdS)Nr �unixrzunreliable on OSX)rr0rrrKrL�net_connectionsrO�laddrrPrrrr5)r7r>�sock�connr(r(r)�test_proc_net_connections�s
�"�z$TestFSAPIs.test_proc_net_connectionscCs~dd�}|j|jd�}t|�}t|��"tjdd�}||�}t|jt�s&J�|j|ks-J�Wd�dS1s8wYdS)NcSs.|D]}tj�|j��t�r|Sqtd��)Nzconnection not found)rGrQrVrj�
startswithr�
ValueError)�consrlr(r(r)�	find_sock�s
�z2TestFSAPIs.test_net_connections.<locals>.find_sockr rh)�kind)	rr0rrrKrirOrjrP)r7rqr>rkrprlr(r(r)�test_net_connections�s
"�zTestFSAPIs.test_net_connectionscCs,|jd}|�t|�t|�t�|�dSr[)r/r]rrrK�
disk_usage)r7r_r(r(r)�test_disk_usages
zTestFSAPIs.test_disk_usage�
not supportedcs�t|jd��5}dd���fdd�t����D�}dd�|D�}�|�|vs'J�|D]	}t|t�s2J�q)Wd�dS1s>wYdS)Nr cSstj�tj�|��S�N)rGrQ�realpathrR)rTr(r(r)�normpathsz-TestFSAPIs.test_memory_maps.<locals>.normpathcsg|]}�|j��qSr()rQ��.0�x�ryr(r)�
<listcomp>s
�z/TestFSAPIs.test_memory_maps.<locals>.<listcomp>cSsg|]}t|vr|�qSr(rrzr(r(r)r~s)rr0rKrLZmemory_mapsrOrP)r7Z
funky_pathZlibpathsrQr(r}r)�test_memory_mapss

��"�zTestFSAPIs.test_memory_mapsN)r8r9r:�__doc__rr0rIrUrWrZr`r�mark�skipifrr	rrrgrrrmrrsrur
rr(r(r(r)rA�s6
�
�
�rAzunreliable on CIc@seZdZdZeZdd�ZdS)�TestFSAPIsWithInvalidPathz-Test FS APIs with a funky, invalid path name.cCstSrwrr6r(r(r)rI(sz1TestFSAPIsWithInvalidPath.expect_exact_path_matchN)r8r9r:r�rr0rIr(r(r(r)r�"sr�c@sBeZdZdZeZejje	dd�ejje
oedd�dd���ZdS)�
TestNonFSAPISz&Unicode tests for non fs-related APIs.rvr?zsegfaults on PYPY + WINDOWScCsxtj��}|j|d<|j|d�}t�|j�}|��}|��D]\}}t	|t
�s)J�t	|t
�s0J�q|d|jks:J�dS)NZ	FUNNY_ARG)�env)rG�environ�copyr0rrKrLrM�itemsrOrP)r7r�r'rT�k�vr(r(r)�test_proc_environ6s

zTestNonFSAPIS.test_proc_environN)
r8r9r:r�rr0rr�r�rrr	r�r(r(r(r)r�1sr�)+r�rGr#rD�
contextlibrrKrrrrrr	Zpsutil.testsr
rrr
rrrrrrrrrrrrrrrrrr*r+r�Zxdist_groupr�rAr�r�r(r(r(r)�<module>sT>