File manager - Edit - /opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/win_chcp.cpython-310.pyc
Back
o ;j� � @ s� d Z ddlZddlmZ ddlmZ e�e�Zzddl Z ddl Z dZW n ey. dZY nw dd� Z edd d ��Zddd�Zdd d�ZdS )z< Functions for working with the codepage on Windows systems � N)�contextmanager)� CodePageErrorTFc C s t sdS dS )z4 Only load if Win32 Libraries are installed )FzThis utility requires pywin32Zwin_chcp)� HAS_WIN32� r r �G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_chcp.py�__virtual__ s r c c s� � t | t�s)zt| �} W n ty( dt| �� �}|r t|��t�|� Y dS w t|d�}| r9|r9| |kr9d}nd}z|rDt| |d� dV W |rRt||d� dS dS |r]t||d� w w )a� Gets or sets the codepage of the shell. Args: page_id (str, int): A number representing the codepage. raise_error (bool): ``True`` will raise an error if the codepage fails to change. ``False`` will suppress the error Returns: int: A number representing the codepage Raises: CodePageError: On unsuccessful codepage change �*The `page_id` needs to be an integer, not �����raise_errorTFN) � isinstance�int� ValueError�typer �log�error�get_codepage_id�set_codepage_id)�page_idr r Zprevious_page_idZ set_code_pager r r �chcp s0 � � ��r c C s` zt �� W S tjy/ } z|j\}}}d|� �}| rt|��t�|� W Y d}~dS d}~ww )aV Get the currently set code page on windows Args: raise_error (bool): ``True`` will raise an error if the codepage fails to change. ``False`` will suppress the error Returns: int: A number representing the codepage Raises: CodePageError: On unsuccessful codepage change z%Failed to get the windows code page: Nr )�win32consoleZGetConsoleCP� pywintypesr �argsr r )r �exc�_�msgr r r r r Q s ��r c C s� t | t�s(zt| �} W n ty' dt| �� �}|rt|��t�|� Y dS w zt�| � t |d�W S t jy] } z|j\}}}d|� �}|rMt|��t�|� W Y d}~dS d}~ww )a� Set the code page on windows Args: page_id (str, int): A number representing the codepage. raise_error (bool): ``True`` will raise an error if the codepage fails to change. ``False`` will suppress the error Returns: int: A number representing the codepage Raises: CodePageError: On unsuccessful codepage change r r r z%Failed to set the windows code page: N)r r r r r r r r ZSetConsoleCPr r r )r r r r r r r r r r m s, � ��r )F)�__doc__�logging� contextlibr Zsalt.exceptionsr � getLogger�__name__r r r r �ImportErrorr r r r r r r r �<module> s"