Файловый менеджер - Редактировать - /opt/imh-python/lib/python3.9/site-packages/oslo_utils/__pycache__/encodeutils.cpython-39.pyc
Ðазад
a s�hY � @ s6 d dl Z e jZddd�Zd dd�Zdd � Zd d� ZdS )� N�strictc C sx t | ttf�stdt| � ��t | t�r,| S |sFttjdd�pDt�� }z| � ||�W S t yr | � d|� Y S 0 dS )a� Decodes incoming text/bytes string using `incoming` if they're not already unicode. :param incoming: Text's current encoding :param errors: Errors handling policy. See here for valid values http://docs.python.org/2/library/codecs.html :returns: text or a unicode `incoming` encoded representation of it. :raises TypeError: If text is not an instance of str z%s can't be decoded�encodingN�utf-8)� isinstance�str�bytes� TypeError�type�getattr�sys�stdin�getdefaultencoding�decode�UnicodeDecodeError)�text�incoming�errors� r ��/root/rpmbuild/BUILDROOT/imh-python39-modules-3.9.7-92.el8.x86_64/opt/imh-python/lib/python3.9/site-packages/oslo_utils/encodeutils.py�safe_decode s � r r c C s� t | ttf�stdt| � ��|s8ttjdd�p6t�� }t |d�rJ|� � }t |d�r\|� � }t | t�rr| �||�S | r�||kr�t| ||�} | �||�S | S dS )a� Encodes incoming text/bytes string using `encoding`. If incoming is not specified, text is expected to be encoded with current python's default encoding. (`sys.getdefaultencoding`) :param incoming: Text's current encoding :param encoding: Expected encoding for text (Default UTF-8) :param errors: Errors handling policy. See here for valid values http://docs.python.org/2/library/codecs.html :returns: text or a bytestring `encoding` encoded representation of it. :raises TypeError: If text is not an instance of str See also to_utf8() function which is simpler and don't depend on the locale encoding. z%s can't be encodedr N�lower) r r r r r r r r r �hasattrr �encoder )r r r r r r r �safe_encode@ s � r c C s8 t | t�r| S t | t�r"| �d�S tdt| �j ��dS )z�Encode Unicode to UTF-8, return bytes unchanged. Raise TypeError if text is not a bytes string or a Unicode string. .. versionadded:: 3.5 r z!bytes or Unicode expected, got %sN)r r r r r r �__name__)r r r r �to_utf8i s �r c C sr d}|du r| � � }t|t�r"|S z|�d�W S ty@ Y n0 t� }z|�|�W S tyf Y n0 |�d�S )a� Get the message of an exception as a Unicode string. On Python 3, the exception message is always a Unicode string. On Python 2, the exception message is a bytes string *most* of the time. If the exception message is a bytes strings, try to decode it from UTF-8 (superset of ASCII), from the locale encoding, or fallback to decoding it from ISO-8859-1 (which never fails). .. versionadded:: 1.6 Nr �latin1)�__str__r r r r �_getfilesystemencoding)�exc�msgr r r r �exception_to_unicodey s r! )Nr )Nr r )r �getfilesystemencodingr r r r r! r r r r �<module> s '