File: //opt/osm/venv/lib/python3.10/site-packages/psutil/tests/__pycache__/test_unicode.cpython-310.pyc
o
=i�) � @ s� d Z ddlZddlZddlZddlmZ ddlZddlmZ ddlmZ ddlm Z ddlm
Z
ddlmZ dd lmZ dd
l
mZ ddl
mZ ddl
mZ dd
l
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
mZ ddl
m Z ddl
m!Z! ddl
m"Z" dd � Z#G d!d"� d"e�Z$ej%j&d#d$�ej%j'ed%d&�G d'd(� d(e$���Z(ej%j'ed)d&�G d*d+� d+e(��Z)G d,d-� d-e$�Z*dS ).aY 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:
* 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 C s� d}t | d�}zGzt|� t|� t|gd�}t�||d � t|d � W n ttfy? Y W |dur9t|� t|� dS w W |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) r r r r �shutil�copyfile�UnicodeEncodeError�OSErrorr )r! �sprocZtestfn� r( �G/opt/osm/venv/lib/python3.10/site-packages/psutil/tests/test_unicode.py�try_unicodeh s*
��
r* c s0 e Zd ZdZe� fdd��Z� fdd�Z� ZS )�BaseUnicodeTestNc sT t � �� d| _d | _| jd ur(t| j�sd| _d S t| jd�| _t| j� d S d S )NFTr )�super�
setUpClass�
skip_tests�
funky_name�funky_suffixr* r r )�cls�� __class__r( r) r- � s
�zBaseUnicodeTest.setUpClassc s t � �� | jr
t�d�S d S )Nzcan't handle unicode str)r, �setUpr. r �skip��selfr2 r( r) r4 � s
�zBaseUnicodeTest.setUp)�__name__�
__module__�__qualname__r0 �classmethodr- r4 �
__classcell__r( r( r2 r) r+ � s
r+ �serial)�namezASCII fs��reasonc @ s� e Zd ZdZeZdd� Zdd� Zdd� Zdd � Z d
d� Z
ejj
eo"edd
�ejj
ep+edd
�dd� ��Zejj
e dd
�ejj
e dd
�dd� ��Zejj
e dd
�ejj
e dd
�e� dd� ���Zdd� Zejj
e dd
�dd� �ZdS )�
TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.c C sF t �� � t �d� | jt�d�v W d � S 1 sw Y d S )N�ignore�.)�warnings�catch_warnings�simplefilterr/ �os�listdirr6 r( r( r) �expect_exact_path_match� s
$�z"TestFSAPIs.expect_exact_path_matchc C sf | j ddg}| �|�}t�|j�}|�� }t|t�sJ �| �� r/t j
�|�t j
�| j �ks1J �d S d S �Nz-cz2import time; [time.sleep(0.1) for x in range(100)])r/ r �psutil�Process�pid�exe�
isinstance�strrI rG �path�normcase)r7 r"