MINI MINI MANI MO
σ
έΉYc           @` sΧ   d  Z  d d l m Z m Z m Z m Z d d l Z d d l Z d d l Z d d l	 Z	 e j
 d d k rx d d l Tn
 d d l Td   Z
 d   Z d   Z d	   Z d
   Z e j Z e j Z d   Z d   Z d S(
   u   
    pyudev._util
    ============
    Internal utilities
    .. moduleauthor::  Sebastian Wiesner  <lunaryorn@googlemail.com>
i    (   t   print_functiont   divisiont   unicode_literalst   absolute_importNi   (   t   *c         C` s+   t  |  t  s' |  j t j    }  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
   isinstancet   bytest   encodet   syst   getfilesystemencoding(   t   value(    (    s0   /usr/lib/python2.7/site-packages/pyudev/_util.pyt   ensure_byte_string,   s    c         C` s+   t  |  t  s' |  j t j    }  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()`).
    (   R   t   unicodet   decodeR   R	   (   R
   (    (    s0   /usr/lib/python2.7/site-packages/pyudev/_util.pyt   ensure_unicode_string9   s    c         C` sE   t  |  t  r t |   }  n  t  |  t  r1 |  St t |    Sd S(   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(   R   t   boolt   intR   R   R   (   R
   (    (    s0   /usr/lib/python2.7/site-packages/pyudev/_util.pyt   property_value_to_bytesF   s
    
c         C` s.   |  d k r$ t  d j |     n  |  d k S(   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`.
    u   1u   0u   Not a boolean value: {0!r}(   u   1u   0(   t
   ValueErrort   format(   R
   (    (    s0   /usr/lib/python2.7/site-packages/pyudev/_util.pyt   string_to_bool[   s    c         c` sI   xB | rD |  j  |  } |  j |  } | | f V|  j |  } q Wd S(   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(   t   udev_list_entry_get_namet   udev_list_entry_get_valuet   udev_list_entry_get_next(   t   libudevt   entryt   nameR
   (    (    s0   /usr/lib/python2.7/site-packages/pyudev/_util.pyt   udev_list_iterateh   s
    	c         C` sK   t  j |   j } t |  r"