Your IP : 3.145.79.214


Current Path : /usr/lib/python3.6/site-packages/pyudev/__pycache__/
Upload File :
Current File : //usr/lib/python3.6/site-packages/pyudev/__pycache__/_util.cpython-36.pyc

3

N�#W(�@s�dZddlmZmZmZmZyddlmZWn ek
rLddl	mZYnXddl
Z
ddlZddlZddl
Z
ddlZdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Zdd�Zdd�ZdS)z|
    pyudev._util
    ============

    Internal utilities

    .. moduleauthor::  Sebastian Wiesner  <lunaryorn@gmail.com>
�)�print_function�division�unicode_literals�absolute_import)�check_outputNcCst|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)�value�r
�/usr/lib/python3.6/_util.py�ensure_byte_string-s
rcCst|tj�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�six�	text_type�decoder
r)rr
r
r�ensure_unicode_string:srcCs2t|t�rt|�}t|t�r |Sttj|��SdS)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`.
    N)r�bool�intrrrr)rr
r
r�property_value_to_bytesGs


rcCs|dkrtdj|���|dkS)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})rr)�
ValueError�format)rr
r
r�string_to_bool\srccs6x0|r0|j|�}|j|�}||fV|j|�}qWdS)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)Zudev_list_entry_get_nameZudev_list_entry_get_valueZudev_list_entry_get_next)Zlibudev�entry�namerr
r
r�udev_list_iterateis



rcCs:tj|�j}tj|�rdStj|�r(dStdj|���dS)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}N)�os�stat�st_mode�S_ISCHR�S_ISBLKrr)�filename�moder
r
r�get_device_typexs

r(cOsvddl}xhy
|||�Stt|jfk
rl}z4t|ttf�rD|j}n
|jd}|tjkrZw
�WYdd}~Xq
Xq
WdS)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�argsZEINTR)�funcr.�kwargsr)�errZ
error_coder
r
r�eintr_retry_call�s


r2cCsttddg��}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
    Zudevadmz	--version)rrr�strip)�outputr
r
r�udev_version�sr5)�__doc__Z
__future__rrrr�
subprocessr�ImportErrorZpyudev._compatr!r
r"r-rrrrrrr(r2r5r
r
r
r�<module>s$


!

?>