관리-도구
편집 파일: _util.cpython-36.opt-1.pyc
3 N�#W( � @ s� d Z ddlmZmZmZmZ yddlmZ W n ek rL ddl mZ Y nX ddl Z ddlZddlZddl 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_outputNc C s 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)�value� r �/usr/lib/python3.6/_util.py�ensure_byte_string- s r c C s t | 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 r c C s2 t | t�rt| �} t | t�r | S ttj| ��S dS )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�intr r r r )r r r r �property_value_to_bytesG s r c C s | dkrt dj| ���| 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})r r )� ValueError�format)r r r r �string_to_bool\ s r c c s6 x0|r0| j |�}| j|�}||fV | j|�}qW dS )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_iteratei s r c C s: t j| �j}tj|�rdS tj|�r(dS tdj| ���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_ISBLKr r )�filename�moder r r �get_device_typex s r( c O sv ddl }xhy | ||�S tt|jfk rl } z4t|ttf�rD|j}n |jd }|tjkrZw � W Y dd}~X q X q W dS )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. r N)�select�OSError�IOError�errorr �errno�argsZEINTR)�funcr. �kwargsr) �errZ error_coder r r �eintr_retry_call� s r2 c C s t tddg��} 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)r r r �strip)�outputr r r �udev_version� s r5 )�__doc__Z __future__r r r r � subprocessr �ImportErrorZpyudev._compatr! r r"