ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     ÿØÿà JFIF      ÿÛ „ 	 ( %!1!%)+//.383,7(-.+



-%%-////---/-.+/--+------/------/--0+--/-/-----.-----ÿÀ  ¥2" ÿÄ               ÿÄ J  	     ! 1AQ"aq2‘#BR‚¡ÁÑ3br’¢±Âð$CSƒ²á4c“%DsÓñÿÄ              ÿÄ *        !1AQa‘"2q3±ð#b¡ÿÚ   ? ¼QxJQaÍuò¸Zö Úü8,ÐÚú
"SSn<rçù–´âE—^ªBÖ9À\†¸ÔÁT­ÃÛ5
ëd´³Í#Ý;Þ38œî ¶H£M:wÎ3…³…âpÔF&‚FK¸9„â4àGEõªfÿ ‘ñ(ßw­pŽF|È¥ù®häðÍÑ¶¹‘[ÒinÙW¶ùñY˜Q{›K"išÒ[Ú8žë\F¹@-?v"ÔU”,ìöžkÿ {I‡£šÍ?e
ríV
..............................................................................................................................................................................
.............................................................................                                                  
                                                                                                                                                                                     3
u1W,                 @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	Z	ddl
Z
ddlmZ ddlmZ d	d
 Ze
jejG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZdS )z
    pyudev.discover
    ===============

    Tools to discover a device given limited information.

    .. moduleauthor::  mulhern <amulhern@redhat.com>
    )absolute_import)division)print_function)unicode_literalsN)Devices)DeviceNotFoundErrorc                s   t j  fdd}|S )z\
    Allow Device discovery methods to return None instead of raising an
    exception.
    c                 s$   y
 | |S  t k
r   dS X dS )z
        Returns result of calling ``func`` on ``args``, ``kwargs``.
        Returns None if ``func`` raises :exc:`DeviceNotFoundError`.
        N)r   )argskwargs)func /usr/lib/python3.6/discover.pythe_func1   s    
z wrap_exception.<locals>.the_func)	functoolswraps)r
   r   r   )r
   r   wrap_exception+   s    r   c               @   sL   e Zd ZdZeejdd Zeejdd Zedd Z	edd	 Z
d
S )
HypothesiszM
    Represents a hypothesis about the meaning of the device identifier.
    c             C   s
   t  dS )a  
        Match the given string according to the hypothesis.

        The purpose of this method is to obtain a value corresponding to
        ``value`` if that is possible. It may use a regular expression, but
        in general it should just return ``value`` and let the lookup method
        sort out the rest.

        :param str value: the string to inspect
        :returns: the matched thing or None if unmatched
        :rtype: the type of lookup's key parameter or NoneType
        N)NotImplementedError)clsvaluer   r   r   matchD   s    zHypothesis.matchc             C   s
   t  dS )aN  
        Lookup the given string according to the hypothesis.

        :param Context context: the pyudev context
        :param key: a key with which to lookup the device
        :type key: the type of match's return value if not None
        :returns: a list of Devices obtained
        :rtype: frozenset of :class:`Device`
        N)r   )r   contextkeyr   r   r   lookupU   s    zHypothesis.lookupc             C   s   dS )z
        A potentially expensive method that may allow an :class:`Hypothesis`
        to find devices more rapidly or to find a device that it would
        otherwise miss.

        :param Context context: the pyudev context
        Nr   )r   r   r   r   r   setupc   s    	zHypothesis.setupc             C   s$   | j |}|dk	r| j||S t S )a  
        Get any devices that may correspond to the given string.

        :param Context context: the pyudev context
        :param str value: the value to look for
        :returns: a list of devices obtained
        :rtype: set of :class:`Device`
        N)r   r   	frozenset)r   r   r   r   r   r   r   get_devicesn   s    

zHypothesis.get_devicesN)__name__
__module____qualname____doc__classmethodabcabstractmethodr   r   r   r   r   r   r   r   r   >   s   r   c               @   sL   e Zd ZdZedd Zedd Zedd Zedd	 Zed
d Z	dS )DeviceNumberHypothesisz
    Represents the hypothesis that the device is a device number.

    The device may be separated into major/minor number or a composite number.
    c             C   s8   t jd}|j|}|o6tjt|jdt|jdS )z
        Match the number under the assumption that it is a major,minor pair.

        :param str value: value to match
        :returns: the device number or None
        :rtype: int or NoneType
        z#^(?P<major>\d+)(\D+)(?P<minor>\d+)$majorminor)recompiler   osmakedevintgroup)r   r   Zmajor_minor_rer   r   r   r   _match_major_minor   s    	
z)DeviceNumberHypothesis._match_major_minorc             C   s&   t jd}|j|}|o$t|jdS )z
        Match the number under the assumption that it is a single number.

        :param str value: value to match
        :returns: the device number or None
        :rtype: int or NoneType
        z^(?P<number>\d+)$Znumber)r&   r'   r   r*   r+   )r   r   Z	number_rer   r   r   r   _match_number   s    	

z$DeviceNumberHypothesis._match_numberc             C   s   | j |p| j|S )z
        Match the number under the assumption that it is a device number.

        :returns: the device number or None
        :rtype: int or NoneType
        )r,   r-   )r   r   r   r   r   r      s    zDeviceNumberHypothesis.matchc             C   s   |j }tjtjj|dS )z
        Find subsystems in /sys/dev.

        :param Context context: the context
        :returns: a lis of available subsystems
        :rtype: list of str
        Zdev)sys_pathr(   listdirpathjoin)r   r   r.   r   r   r   find_subsystems   s    	z&DeviceNumberHypothesis.find_subsystemsc                s8   t tj fdd| j D }tdd |D S )z
        Lookup by the device number.

        :param Context context: the context
        :param int key: the device number
        :returns: a list of matching devices
        :rtype: frozenset of :class:`Device`
        c             3   s   | ]} |V  qd S )Nr   ).0s)r   r
   r   r   r   	<genexpr>   s    z0DeviceNumberHypothesis.lookup.<locals>.<genexpr>c             s   s   | ]}|d k	r|V  qd S )Nr   )r3   rr   r   r   r5      s    )r   r   Zfrom_device_numberr2   r   )r   r   r   resr   )r   r
   r   r   r      s    

zDeviceNumberHypothesis.lookupN)
r   r   r   r   r    r,   r-   r   r2   r   r   r   r   r   r#   |   s   
r#   c               @   s(   e Zd ZdZedd Zedd ZdS )DevicePathHypothesiszG
    Discover the device assuming the identifier is a device path.
    c             C   s   |S )z
        Match ``value`` under the assumption that it is a device path.

        :returns: the device path or None
        :rtype: str or NoneType
        r   )r   r   r   r   r   r      s    zDevicePathHypothesis.matchc             C   s(   t tj||}|dk	r"t|fS t S )z
        Lookup by the path.

        :param Context context: the context
        :param str key: the device path
        :returns: a list of matching devices
        :rtype: frozenset of :class:`Device`
        N)r   r   Z	from_pathr   )r   r   r   r7   r   r   r   r      s    
zDevicePathHypothesis.lookupN)r   r   r   r   r    r   r   r   r   r   r   r8      s   
r8   c               @   s4   e Zd ZdZedd Zedd Zedd ZdS )	DeviceNameHypothesiszf
    Discover the device assuming the input is a device name.

    Try every available subsystem.
    c                s<   |j  d} fdd|D }dd |D }tdd |D S )	z
        Find all subsystems in sysfs.

        :param Context context: the context
        :rtype: frozenset
        :returns: subsystems in sysfs
        busclass	subsystemc             3   s   | ]}t jj |V  qd S )N)r(   r0   r1   )r3   name)r.   r   r   r5      s    z7DeviceNameHypothesis.find_subsystems.<locals>.<genexpr>c             s   s   | ]}t jj|r|V  qd S )N)r(   r0   isdir)r3   dr   r   r   r5      s    c             s   s"   | ]}t j|D ]
}|V  qqd S )N)r(   r/   )r3   r?   nr   r   r   r5      s    )r:   r;   r<   )r.   r   )r   r   ZdirnamesZabsnamesZ	realnamesr   )r.   r   r2      s
    	z$DeviceNameHypothesis.find_subsystemsc             C   s   |S )z
        Match ``value`` under the assumption that it is a device name.

        :returns: the device path or None
        :rtype: str or NoneType
        r   )r   r   r   r   r   r      s    zDeviceNameHypothesis.matchc                s8   t tj fdd| j D }tdd |D S )z
        Lookup by the path.

        :param Context context: the context
        :param str key: the device path
        :returns: a list of matching devices
        :rtype: frozenset of :class:`Device`
        c             3   s   | ]} |V  qd S )Nr   )r3   r4   )r   r
   r   r   r   r5     s    z.DeviceNameHypothesis.lookup.<locals>.<genexpr>c             s   s   | ]}|d k	r|V  qd S )Nr   )r3   r6   r   r   r   r5     s    )r   r   	from_namer2   r   )r   r   r   r7   r   )r   r
   r   r   r     s    

zDeviceNameHypothesis.lookupN)r   r   r   r   r    r2   r   r   r   r   r   r   r9      s   
r9   c               @   sZ   e Zd ZdZdddddddd	d
ddgZedd Zedd Zedd Zedd Z	dS )DeviceFileHypothesisz
    Discover the device assuming the value is some portion of a device file.

    The device file may be a link to a device node.
    z/devz/dev/disk/by-idz/dev/disk/by-labelz/dev/disk/by-partlabelz/dev/disk/by-partuuidz/dev/disk/by-pathz/dev/disk/by-uuidz/dev/input/by-pathz/dev/mapperz/dev/mdz/dev/vgc             C   s:   |j  }dd |D }dd |D }ttdd |D S )a7  
        Get all directories that may contain links to device nodes.

        This method checks the device links of every device, so it is very
        expensive.

        :param Context context: the context
        :returns: a sorted list of directories that contain device links
        :rtype: list
        c             s   s   | ]}t |jr|V  qd S )N)listdevice_links)r3   r?   r   r   r   r5   5  s    z5DeviceFileHypothesis.get_link_dirs.<locals>.<genexpr>c             s   s   | ]}|j D ]
}|V  qqd S )N)rD   )r3   r?   lr   r   r   r5   6  s    c             s   s   | ]}t jj|V  qd S )N)r(   r0   dirname)r3   rE   r   r   r   r5   7  s    )Zlist_devicessortedset)r   r   devicesZdevices_with_linksZlinksr   r   r   get_link_dirs(  s    z"DeviceFileHypothesis.get_link_dirsc             C   s   | j || _dS )z
        Set the link directories to be used when discovering by file.

        Uses `get_link_dirs`, so is as expensive as it is.

        :param Context context: the context
        N)rJ   
_LINK_DIRS)r   r   r   r   r   r   9  s    	zDeviceFileHypothesis.setupc             C   s   |S )Nr   )r   r   r   r   r   r   D  s    zDeviceFileHypothesis.matchc                sr   t tjdkr4 }|dk	r.t|fS t S fdd| jD } fdd|D }tdd |D S dS )a  
        Lookup the device under the assumption that the key is part of
        the name of a device file.

        :param Context context: the context
        :param str key: a portion of the device file name

        It is assumed that either it is the whole name of the device file
        or it is the basename.

        A device file may be a device node or a device link.
        /Nc             3   s   | ]}t jj| V  qd S )N)r(   r0   r1   )r3   Zld)r   r   r   r5   [  s    z.DeviceFileHypothesis.lookup.<locals>.<genexpr>c             3   s   | ]} |V  qd S )Nr   )r3   f)r   r
   r   r   r5   \  s    c             s   s   | ]}|d k	r|V  qd S )Nr   )r3   r?   r   r   r   r5   ]  s    )r   r   Zfrom_device_filer   rK   )r   r   r   ZdevicefilesrI   r   )r   r
   r   r   r   H  s    

zDeviceFileHypothesis.lookupN)
r   r   r   r   rK   r    rJ   r   r   r   r   r   r   r   rB     s    rB   c               @   s4   e Zd ZdZeeeegZdd Z	dd Z
dd ZdS )		Discoveryz1
    Provides discovery methods for devices.
    c             C   s   | j | _d S )N)_HYPOTHESES_hypotheses)selfr   r   r   __init__m  s    zDiscovery.__init__c             C   s   x| j D ]}|j| qW dS )z
        Set up individual hypotheses.

        May be an expensive call.

        :param Context context: the context
        N)rQ   r   )rR   r   Zhypr   r   r   r   p  s    zDiscovery.setupc                s   t  fdd| jD S )z
        Get the devices corresponding to value.

        :param Context context: the context
        :param str value: some identifier of the device
        :returns: a list of corresponding devices
        :rtype: frozenset of :class:`Device`
        c             3   s$   | ]}|j  D ]
}|V  qqd S )N)r   )r3   hr?   )r   r   r   r   r5     s    z(Discovery.get_devices.<locals>.<genexpr>)r   rQ   )rR   r   r   r   )r   r   r   r   {  s    	zDiscovery.get_devicesN)r   r   r   r   rB   r9   r#   r8   rP   rS   r   r   r   r   r   r   rO   `  s   rO   )r   Z
__future__r   r   r   r   r!   r   r(   r&   ZsixZpyudev.devicer   r   r   Zadd_metaclassABCMetaobjectr   r#   r8   r9   rB   rO   r   r   r   r   <module>   s&   =K/M