ݹYc@`sdZddlmZmZmZmZddlZddlZddlZddl Z ej ddkrxddl Tn ddl TdZ dZdZd Zd ZejZejZd Zd ZdS( u pyudev._util ============ Internal utilities .. moduleauthor:: Sebastian Wiesner i(tprint_functiontdivisiontunicode_literalstabsolute_importNi(t*cC`s+t|ts'|jtj}n|S(u 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()`). (t isinstancetbytestencodetsystgetfilesystemencoding(tvalue((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytensure_byte_string,scC`s+t|ts'|jtj}n|S(u 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()`). (RtunicodetdecodeRR (R ((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytensure_unicode_string9scC`sEt|trt|}nt|tr1|Stt|SdS(u 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(RtbooltintRR R (R ((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytproperty_value_to_bytesFs cC`s.|dkr$tdj|n|dkS(u 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`. u1u0uNot a boolean value: {0!r}(u1u0(t ValueErrortformat(R ((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytstring_to_bool[s cc`sIxB|rD|j|}|j|}||fV|j|}qWdS(u 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(tudev_list_entry_get_nametudev_list_entry_get_valuetudev_list_entry_get_next(tlibudevtentrytnameR ((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytudev_list_iteratehs   cC`sKtj|j}t|r"dSt|r2dStdj|dS(u 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 ucharublockunot a device file: {0!r}N(toststattst_modet_is_char_devicet_is_block_deviceRR(tfilenametmode((s0/usr/lib/python2.7/site-packages/pyudev/_util.pytget_device_type|s   cO`sddl}xtry|||SWqtt|jfk r}t|ttfre|j}n |jd}|tjkrqnqXqWdS(u= 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. iN( tselecttTruetOSErrortIOErrorterrorRterrnotargstEINTR(tfuncR*tkwargsR$tet error_code((s0/usr/lib/python2.7/site-packages/pyudev/_util.pyteintr_retry_calls    (t__doc__t __future__RRRRRRRR)t version_infotpyudev._py2utiltpyudev._py3utilR RRRRtS_ISCHRRtS_ISBLKR R#R0(((s0/usr/lib/python2.7/site-packages/pyudev/_util.pyts""