HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.30
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/__pycache__/win_chcp.cpython-310.pyc
o

�N�g��@s�dZddlZddlmZddlmZe�e�Zzddl	Z	ddl
Z
dZWney.dZYnwdd�Z
edd	d
��Zddd�Zdd
d�ZdS)z<
Functions for working with the codepage on Windows systems
�N)�contextmanager)�
CodePageErrorTFcCstsdSdS)z4
    Only load if Win32 Libraries are installed
    )FzThis utility requires pywin32Zwin_chcp)�	HAS_WIN32�rr�G/opt/saltstack/salt/lib/python3.10/site-packages/salt/utils/win_chcp.py�__virtual__src
cs��t|t�s)zt|�}Wnty(dt|���}|r t|��t�|�YdSwt|d�}|r9|r9||kr9d}nd}z|rDt||d�dVW|rRt||d�dSdS|r]t||d�ww)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_idrrZprevious_page_idZ
set_code_pagerrr�chcp s0�

�
��rc
Cs`zt��WStjy/}z|j\}}}d|��}|rt|��t�|�WYd}~dSd}~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	)�win32consoleZGetConsoleCP�
pywintypesr�argsrr)r�exc�_�msgrrrrrQs


��rc
Cs�t|t�s(zt|�}Wnty'dt|���}|rt|��t�|�YdSwzt�|�t	|d�WSt
jy]}z|j\}}}d|��}|rMt|��t�|�WYd}~dSd}~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
    rr	r
z%Failed to set the windows code page: N)rr
rrrrrrZSetConsoleCPrrr)rrrrrrrrrrms,

�


��r)F)�__doc__�logging�
contextlibrZsalt.exceptionsr�	getLogger�__name__rrrr�ImportErrorrrrrrrrr�<module>s"
�

0