%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/pyudev/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/pyudev/__pycache__/_util.cpython-312.pyc

�

9*�bd��d�dZddlZddlZddlZddlZddlmZd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zy)z|
    pyudev._util
    ============

    Internal utilities

    .. moduleauthor::  Sebastian Wiesner  <lunaryorn@gmail.com>
�N)�check_outputc�l�t|t�s#|jtj��}|S)z�
    Return the given ``value`` as bytestring.

    If the given ``value`` is not a byte string, but a real unicode string, it
    is encoded with the filesystem encoding (as in
    :func:`sys.getfilesystemencoding()`).
    )�
isinstance�bytes�encode�sys�getfilesystemencoding��values �./usr/lib/python3/dist-packages/pyudev/_util.py�ensure_byte_stringr
"s*���e�U�#����S�6�6�8�9���L�c�l�t|t�s#|jtj��}|S)z�
    Return the given ``value`` as unicode string.

    If the given ``value`` is not a unicode string, but a byte string, it is
    decoded with the filesystem encoding (as in
    :func:`sys.getfilesystemencoding()`).
    )r�str�decoderr	r
s r�ensure_unicode_stringr/s*���e�S�!����S�6�6�8�9���Lrc��t|t�rt|�}t|t�r|St	t|��S)a�
    Return a byte string, which represents the given ``value`` in a way
    suitable as raw value of an udev property.

    If ``value`` is a boolean object, it is converted to ``'1'`` or ``'0'``,
    depending on whether ``value`` is ``True`` or ``False``.  If ``value`` is a
    byte string already, it is returned unchanged.  Anything else is simply
    converted to a unicode string, and then passed to
    :func:`ensure_byte_string`.
    )r�bool�intrr
rr
s r�property_value_to_bytesr<s5���%����E�
���%������c�%�j�)�)rc�H�|dvrtdj|���|dk(S)z�
    Convert the given unicode string ``value`` to a boolean object.

    If ``value`` is ``'1'``, ``True`` is returned.  If ``value`` is ``'0'``,
    ``False`` is returned.  Any other value raises a
    :exc:`~exceptions.ValueError`.
    )�1�0zNot a boolean value: {0!r}r)�
ValueError�formatr
s r�string_to_boolrPs-��
�J���5�<�<�U�C�D�D��C�<�rc#�K�|r=|j|�}|j|�}||f��|j|�}|r�<yy�w)z�
    Iteration helper for udev list entry objects.

    Yield a tuple ``(name, value)``.  ``name`` and ``value`` are bytestrings
    containing the name and the value of the list entry.  The exact contents
    depend on the list iterated over.
    N)�udev_list_entry_get_name�udev_list_entry_get_value�udev_list_entry_get_next)�libudev�entry�namers    r�udev_list_iterater$]sJ������/�/��6���1�1�%�8���U�m���0�0��7��	�s�>A�Ac���tj|�j}tj|�rytj|�rytdj
|���)a�
    Get the device type of a device file.

    ``filename`` is a string containing the path of a device file.

    Return ``'char'`` if ``filename`` is a character device, or ``'block'`` if
    ``filename`` is a block device.  Raise :exc:`~exceptions.ValueError` if
    ``filename`` is no device file at all.  Raise
    :exc:`~exceptions.EnvironmentError` if ``filename`` does not exist or if
    its metadata was inaccessible.

    .. versionadded:: 0.15
    �char�blockznot a device file: {0!r})�os�stat�st_mode�S_ISCHR�S_ISBLKrr)�filename�modes  r�get_device_typer/lsM���7�7�8��$�$�D��|�|�D���	
���d�	���3�:�:�8�D�E�Erc��ddl}		||i|��S#tt|jf$rP}t	|ttf�r
|j
}n|jd}|t
jk(rYd}~�n�d}~wwxYw)a=
    Handle interruptions to an interruptible system call.

    Run an interruptible system call in a loop and retry if it raises EINTR.
    The signal calls that may raise EINTR prior to Python 3.5 are listed in
    PEP 0475.  Any calls to these functions must be wrapped in eintr_retry_call
    in order to handle EINTR returns in older versions of Python.

    This function is safe to use under Python 3.5 and newer since the wrapped
    function will simply return without raising EINTR.

    This function is based on _eintr_retry_call in python's subprocess.py.
    rN)�select�OSError�IOError�errorr�errno�args�EINTR)�funcr6�kwargsr1�err�
error_codes      r�eintr_retry_callr<�ss��"�
�	���(��(�(����&�,�,�/�
	��#���1�2� �Y�Y�
� �X�X�a�[�
��U�[�[�(����
	�s��A9�AA4�3A4�4A9c�`�ttddg��}t|j��S)ak
    Get the version of the underlying udev library.

    udev doesn't use a standard major-minor versioning scheme, but instead
    labels releases with a single consecutive number.  Consequently, the
    version number returned by this function is a single integer, and not a
    tuple (like for instance the interpreter version in
    :data:`sys.version_info`).

    As libudev itself does not provide a function to query the version number,
    this function calls the ``udevadm`` utility, so be prepared to catch
    :exc:`~exceptions.EnvironmentError` and
    :exc:`~subprocess.CalledProcessError` if you call this function.

    Return the version number as single integer.  Raise
    :exc:`~exceptions.ValueError`, if the version number retrieved from udev
    could not be converted to an integer.  Raise
    :exc:`~exceptions.EnvironmentError`, if ``udevadm`` was not found, or could
    not be executed.  Raise :exc:`subprocess.CalledProcessError`, if
    ``udevadm`` returned a non-zero exit code.  On Python 2.7 or newer, the
    ``output`` attribute of this exception is correctly set.

    .. versionadded:: 0.8
    �udevadmz	--version)rrr�strip)�outputs r�udev_versionrA�s)��2#�<��K�0H�#I�
J�F��v�|�|�~��r)�__doc__r5r(r)r�
subprocessrr
rrrr$r/r<rA�rr�<module>rEsE��"�
�	��
�#�
�
�*�(
�8�F�. �Fr

Zerion Mini Shell 1.0