Advanced Web Server Manager
Complete File Manager & Terminal - Standalone Version
By Sid Gifari | Gifari Industries
Current path:
/
/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
psutil
/
tests
/
__pycache__
✏️
Editing: test_unicode.cpython-36.pyc
3 �̪e1 � @ s8 d Z ddlZddlZddlZddlZddlZddlmZ ddlZddlm Z ddlm Z ddlmZ ddlm Z ddlmZ dd lmZ dd lmZ ddlmZ ddlmZ dd lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z ddlm!Z! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddlm&Z& e�r�d d!� Z"d"d#� Z'G d$d%� d%e�Z(e#ej)ed&�ej)e�o�e d'�G d(d)� d)e(����Z*ej)ed*�G d+d,� d,e*��Z+G d-d.� d.e(�Z,e-d/k�r4dd0l.m/Z/ e/e0� 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.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)�POSIX)�WINDOWS)�PY3)�super)�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_py_exe)� get_testfn)� safe_mkdir)�safe_rmpath)� serialrun)�skip_on_access_denied)�spawn_testproc)� terminatec C s6 ddl m} y|| �S tk r0 tj� Y nX d S )Nr )r )�psutil.testsr ZWindowsError� traceback� print_exc)�pathZrm� r# �E/usr/local/lib64/python3.6/site-packages/psutil/tests/test_unicode.pyr s s r c C s� d}t | d�}z^y<t|� t|� t|gd�}tj||d � t|d � W n ttfk rd dS X dS W d|dk r~t|� t|� X dS )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�IOErrorr )r% �sprocZtestfnr# r# r$ �try_unicode� s r, c s0 e Zd ZdZe� fdd��Z� fdd�Z� ZS )�BaseUnicodeTestNc sN t � j� d| _d | _| jd k rJt| j�s2d| _nt| jd�| _t| j� d S )NFT)r% )r � setUpClass� skip_tests� funky_name�funky_suffixr, r r )�cls)� __class__r# r$ r. � s zBaseUnicodeTest.setUpClassc s t � j� | jr| jd��d S )Nzcan't handle unicode str)r �setUpr/ �skipTest)�self)r3 r# r$ r4 � s zBaseUnicodeTest.setUp)�__name__� __module__�__qualname__r1 �classmethodr. r4 � __classcell__r# r# )r3 r$ r- � s r- zASCII fsztoo much trouble on PYPY2c @ s� e Zd ZdZeZdd� Zdd� Zdd� Zdd � Z d d� Z eje oBed�d d� �Zeje d�dd� �Zeje d�eje d�e� dd� ���Zdd� Zeje d�eje d�eje d�dd� ���ZdS )� TestFSAPIsz1Test FS APIs with a funky, valid, UTF8 path name.c C sF t | jt�rdntd�}tj� � tjd� | jtj|�kS Q R X d S )N�.�ignore) � isinstancer0 �strr �warnings�catch_warnings�simplefilter�os�listdir)r6 �herer# r# r$ �expect_exact_path_match� s z"TestFSAPIs.expect_exact_path_matchc C s` | j ddg}| j|�}tj|j�}|j� }| j|t� | j� r\| j t jj|�t jj| j �� d S )Nz-czimport time; time.sleep(10)) r0 r �psutil�Process�pid�exe�assertIsInstancer@ rG �assertEqualrD r"