HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/usb/__pycache__/core.cpython-39.pyc
a

j��Yp��@s<dZdZgd�ZddlmZddlZddlZddlmZddl	m
Z
ddlmZ
ddlZddlZddlZddlZe�d�ZdZdd�Zd&dd�Zd'd
d�ZGdd�de�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�Z Gdd�de�Z!Gdd�de�Z"Gdd�de�Z#Gdd �d e
j$�Z%d(d"d#�Z&d)d$d%�Z'dS)*avusb.core - Core USB features.

This module exports:

Device - a class representing a USB device.
Configuration - a class representing a configuration descriptor.
Interface - a class representing an interface descriptor.
Endpoint - a class representing an endpoint descriptor.
find() - a function to find USB devices.
show_devices() - a function to show the devices present.
zWander Lairson Costa)�Device�
Configuration�	Interface�Endpoint�find�show_devices�Nzusb.corei�cCs |D]}t||t||��qdS�N)�setattr�getattr)�input�output�fields�f�r�,/usr/lib/python3.9/site-packages/usb/core.py�	_set_attr=sr��Error Accessing StringcCsL|dkr|}n:z(|dur&t�||�}nt�|||�}Wn|}Yn0|S)z= try to get a string, but return a string no matter what
    rN)�util�
get_string)�dev�indexZlangidZdefault_str_i0Zdefault_access_error�stringrrr�_try_get_stringAs
rcCs(z||}Wnty"|}Yn0|S)zS try to get a string from the lookup table, return "" instead of key
    error
    )�KeyError)�table�value�defaultrrrr�_try_lookupQs

rc@seZdZdZdd�ZdS)�_DescriptorInfozc this class is used so that when a descriptor is shown on the
    terminal it is propely formatted cCs|Srr��selfrrr�__repr__^sz_DescriptorInfo.__repr__N)�__name__�
__module__�__qualname__�__doc__r"rrrrr[srcst����fdd��}|S)Ncs>z,|j���|g|�Ri|��W|j��S|j��0dSr)�lock�acquire�release)r!�args�kwargs�rrr�wrapperbs

�zsynchronized.<locals>.wrapper)�	functools�wraps)rr-rr,r�synchronizedasr0c@s�eZdZdd�Zedd��Zedd��Zedd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zedd��Zedd��Z
edd��Zeddd��ZdS)�_ResourceManagercCs6||_d|_||_d|_t��|_i|_t�	�|_
dSr)�backend�_active_cfg_indexr�handle�_interopZ_set�
_claimed_intf�_ep_info�	threading�RLockr')r!rr2rrr�__init__ls
z_ResourceManager.__init__cCs |jdur|j�|j�|_|jSr)r4r2Zopen_devicerr rrr�managed_openus
z_ResourceManager.managed_opencCs"|jdur|j�|j�d|_dSr)r4r2Zclose_devicer rrr�
managed_close{s
z_ResourceManager.managed_closecCs�|dur|d}n>t|t�r"|}n.|dkrBGdd�dt�}|�}ntj||d�}|durhtdt|���|��|j�	|j
|j�|j|_
|j��dS)Nrc@seZdZdd�ZdS)zE_ResourceManager.managed_set_configuration.<locals>.MockConfigurationcSsd|_d|_dS)Nr)r�bConfigurationValuer rrrr:�szN_ResourceManager.managed_set_configuration.<locals>.MockConfiguration.__init__N)r#r$r%r:rrrr�MockConfiguration�sr>�r=zInvalid configuration )�
isinstancer�objectr�find_descriptor�
ValueError�strr;r2�set_configurationr4r=rr3r7�clear)r!�deviceZconfig�cfgr>rrr�managed_set_configuration�s

z*_ResourceManager.managed_set_configurationcCsH|��t|t�r|j}n|}||jvrD|j�|j|�|j�|�dSr)	r;r@r�bInterfaceNumberr6r2Zclaim_interfacer4�add)r!rG�intf�irrr�managed_claim_interface�s

z(_ResourceManager.managed_claim_interfacec	Csr|dur|�|�}|dj}nt|t�r0|j}n|}||jvrnz |j�|j|�W|j�|�n|j�|�0dS)N�rr)	�get_active_configurationrJr@rr6r2Zrelease_interfacer4�remove)r!rGrLrHrMrrr�managed_release_interface�s


z*_ResourceManager.managed_release_interfacecCs�t|t�r|}nD|�|�}|dur,|dj}|durFtj|||d�}ntj||d�}|�||�|durn|j}|j�	|j
|j|�dS)NrO)rJ�bAlternateSetting)rJ)r@rrPrJrrBrNrSr2�set_interface_altsettingr4)r!rGrL�altrMrHrrr�managed_set_interface�s


z&_ResourceManager.managed_set_interfacecCs:t|t�r|j}n|}|�||�\}}|�||�||fSr)r@r�bEndpointAddress�get_interface_and_endpointrN)r!rG�endpoint�endpoint_addressrL�eprrr�
setup_request�s
z_ResourceManager.setup_requestcCsxz|j|WStyr|�|�D]8}tj||d�}|dur$||f|j|<||fYSq$tdt|���Yn0dS)N)rWzInvalid endpoint address )r7rrPrrBrC�hex)r!rGrZrLr[rrrrX�sz+_ResourceManager.get_interface_and_endpointcCsP|jdurF|��tj||j�|j�d�}|dur:td��|j|_|S||jS)Nr?zConfiguration not set)	r3r;rrBr2Zget_configurationr4�USBErrorr)r!rGrHrrrrP�s
�z)_ResourceManager.get_active_configurationc	Cs>t�|j�}|D](}z|�||�Wqty6Yq0qdSr)�copyr6rRr^)r!rGZclaimedrMrrr�release_all_interfaces�sz'_ResourceManager.release_all_interfacesTcCs*|�|�|r|��|j��d|_dSr)r`r<r7rFr3)r!rGZclose_handlerrr�disposes


z_ResourceManager.disposeN)T)r#r$r%r:r0r;r<rIrNrRrVr\rXrPr`rarrrrr1ks.	












r1c@seZdZdZddd�ZdS)r^z�Exception class for USB errors.

    Backends must raise this exception when USB related errors occur.  The
    backend specific error code is available through the 'backend_error_code'
    member variable.
    NcCst�|||�||_dS)z�Initialize the object.

        This initializes the USBError object. The strerror and errno are passed
        to the parent object. The error_code parameter is attributed to the
        backend_error_code member variable.
        N)�IOErrorr:Zbackend_error_code)r!�strerrorZ
error_code�errnorrrr:szUSBError.__init__)NN)r#r$r%r&r:rrrrr^sr^c@seZdZdZdS)�NoBackendErrorz2Exception class when a valid backend is not found.N)r#r$r%r&rrrrresrec@sNeZdZdZddd�Zdd�Zdd�Zdd
d�Zddd
�Zdd�Z	dd�Z
d	S)ra�Represent an endpoint object.

    This class contains all fields of the Endpoint Descriptor according to the
    USB Specification. You can access them as class properties. For example, to
    access the field bEndpointAddress of the endpoint descriptor, you can do so:

    >>> import usb.core
    >>> dev = usb.core.find()
    >>> for cfg in dev:
    >>>     for i in cfg:
    >>>         for e in i:
    >>>             print e.bEndpointAddress
    rcCs:||_||_|jj}|�|jj||||�}t||d�dS)a(Initialize the Endpoint object.

        The device parameter is the device object returned by the find()
        function. endpoint is the endpoint logical index (not the endpoint
        address). The configuration parameter is the logical index of the
        configuration (not the bConfigurationValue field). The interface
        parameter is the interface logical index (not the bInterfaceNumber
        field) and alternate_setting is the alternate setting logical index
        (not the bAlternateSetting value). An interface may have only one
        alternate setting. In this case, the alternate_setting parameter
        should be zero. By "logical index" we mean the relative order of the
        configurations returned by the peripheral as a result of GET_DESCRIPTOR
        request.
        )	�bLength�bDescriptorTyperW�bmAttributes�wMaxPacketSize�	bIntervalZbRefreshZ
bSynchAddress�extra_descriptorsN)rGr�_ctxr2Zget_endpoint_descriptorrr)r!rGrY�	interface�alternate_setting�
configurationr2�descrrrr:1s��zEndpoint.__init__cCsd|��dS�N�<�>��_strr rrrr"^szEndpoint.__repr__cCs�d|��d}t�|j�tjkr(d}nd}d|ddt|�fdd	|jfd
d|jtt	j
|j�fd
d|j|fd
d
|jt	j|jd@fdd|j
|j
fdd|jfS)Nz      � �IN�OUT�%s%s
�=�<z       %-17s:%#7x (7 bytes)
rfz       %-17s:%#7x %s
rgrWrh�z       %-17s:%#7x (%d bytes)
riz       %-17s:%#7xrj)rur�endpoint_directionrW�ENDPOINT_IN�lenrfrgr�_lu�descriptorsrh�
ep_attributesrirj)r!�headstr�	directionrrr�__str__as:��������
��
�zEndpoint.__str__NcCs|j�|||�S)a^Write data to the endpoint.

        The parameter data contains the data to be sent to the endpoint and
        timeout is the time limit of the operation. The transfer type and
        endpoint address are automatically inferred.

        The method returns the number of bytes written.

        For details, see the Device.write() method.
        )rG�write)r!�data�timeoutrrrr�xszEndpoint.writecCs|j�|||�S)a�Read data from the endpoint.

        The parameter size_or_buffer is either the number of bytes to
        read or an array object where the data will be put in and timeout is the
        time limit of the operation. The transfer type and endpoint address
        are automatically inferred.

        The method returns either an array object or the number of bytes
        actually read.

        For details, see the Device.read() method.
        )rG�read)r!�size_or_bufferr�rrrr��s
z
Endpoint.readcCs|j�|j�dS)z0Clear the halt/status condition of the endpoint.N)rG�
clear_haltrWr rrrr��szEndpoint.clear_haltcCs8t�|j�tjkrd}nd}d|jtj|jd@|fS)NrwrxzENDPOINT 0x%X: %s %sr|)rr}rWr~r�r�rh)r!r�rrrru�s��z
Endpoint._str)rrr)N)N)r#r$r%r&r:r"r�r�r�r�rurrrrr"s�
-

rc@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)ra�Represent an interface object.

    This class contains all fields of the Interface Descriptor
    according to the USB Specification. You may access them as class
    properties. For example, to access the field bInterfaceNumber
    of the interface descriptor, you can do so:

    >>> import usb.core
    >>> dev = usb.core.find()
    >>> for cfg in dev:
    >>>     for i in cfg:
    >>>         print i.bInterfaceNumber
    rcCsF||_||_||_||_|jj}|�|jjj|||�}t||d�dS)a�Initialize the interface object.

        The device parameter is the device object returned by the find()
        function. The configuration parameter is the logical index of the
        configuration (not the bConfigurationValue field). The interface
        parameter is the interface logical index (not the bInterfaceNumber
        field) and alternate_setting is the alternate setting logical index
        (not the bAlternateSetting value). An interface may have only one
        alternate setting. In this case, the alternate_setting parameter
        should be zero.  By "logical index" we mean the relative order of
        the configurations returned by the peripheral as a result of
        GET_DESCRIPTOR request.
        )
rfrgrJrS�
bNumEndpoints�bInterfaceClass�bInterfaceSubClass�bInterfaceProtocol�
iInterfacerkN)	rG�alternate_indexrrorlr2Zget_interface_descriptorrr)r!rGrmrnror2rprrrr:�s ��zInterface.__init__cCsd|��dSrqrtr rrrr"�szInterface.__repr__cCs&|��}|D]}|dt|�7}q|S)z'Show all information for the interface.�
��_get_full_descriptor_strrD)r!rrYrrrr��szInterface.__str__cCst|�S)z*Return a tuple of the interface endpoints.��tupler rrr�	endpoints�szInterface.endpointscCs|j�|j|j�dS)z$Set the interface alternate setting.N)rGrTrJrSr rrr�set_altsetting�s�zInterface.set_altsettingccs.t|j�D]}t|j||j|j|j�Vq
dS)z,Iterate over all endpoints of the interface.N)�ranger�rrGrr�ro�r!rMrrr�__iter__�s�zInterface.__iter__cCst|j||j|j|j�S)z1Return the Endpoint object in the given position.)rrGrr�ro�r!rrrr�__getitem__�s�zInterface.__getitem__cCs4|jrd|j}nd}d|j|ttj|jdd�fS)Nz, %drzINTERFACE %d%s: %sz
Unknown Class)r)rSrJrr��interface_classesr�)r!Zalt_settingrrrrus
��zInterface._strcCs�d|��d}d|ddt|�fdd|jfdd	|jttj|j�fd
d|jfd
d|jfd
d
|j	fdd|j
ttj|j
�fd
d|jfd
d|j
fdd|jt|j|j�fS)Nz    rvryrzr{z     %-19s:%#7x (9 bytes)
rfz     %-19s:%#7x %s
rgz     %-19s:%#7x
rJrSr�r�r�r�z     %-19s:%#7x %sr�)rurrfrgrr�r�rJrSr�r�r�r�r�r�rrG)r!r�rrrr�sR��������
����������z"Interface._get_full_descriptor_strN)rrr)
r#r$r%r&r:r"r�r�r�r�r�rur�rrrrr�s�
.
	
rc@sZeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�ZdS)ra�Represent a configuration object.

    This class contains all fields of the Configuration Descriptor according to
    the USB Specification. You may access them as class properties.  For
    example, to access the field bConfigurationValue of the configuration
    descriptor, you can do so:

    >>> import usb.core
    >>> dev = usb.core.find()
    >>> for cfg in dev:
    >>>     print cfg.bConfigurationValue
    rcCs6||_||_|jj}|�|jjj|�}t||d�dS)a�Initialize the configuration object.

        The device parameter is the device object returned by the find()
        function. The configuration parameter is the logical index of the
        configuration (not the bConfigurationValue field). By "logical index"
        we mean the relative order of the configurations returned by the
        peripheral as a result of GET_DESCRIPTOR request.
        )	rfrg�wTotalLength�bNumInterfacesr=�iConfigurationrh�	bMaxPowerrkN)rGrrlr2Zget_configuration_descriptorrr)r!rGror2rprrrr::s	��zConfiguration.__init__cCsd|��dSrqrtr rrrr"]szConfiguration.__repr__cCs&|��}|D]}|dt|�7}q|S)N�
%sr�)r!rrmrrrr�`szConfiguration.__str__cCst|�S)z/Return a tuple of the configuration interfaces.r�r rrr�
interfacesfszConfiguration.interfacescCs|j�|j�dS)z)Set this configuration as the active one.N)rGrEr=r rrr�setjszConfiguration.setc
csRt|j�D]B}d}z"t|j|||j�V|d7}qWq
ttfyJYq
0q
dS)z1Iterate over all interfaces of the configuration.r�N)r�r�rrGrr^�
IndexError)r!rMrUrrrr�nszConfiguration.__iter__cCst|j|d|d|j�S)z�Return the Interface object in the given position.

        index is a tuple of two values with interface index and
        alternate setting index, respectivally. Example:

        >>> interface = config[(0, 0)]
        rr�)rrGrr�rrrr�yszConfiguration.__getitem__cCsd|jtj|jfS)NzCONFIGURATION %d: %d mA)r=r��MAX_POWER_UNITS_USB2p0r�r rrrru�s
�zConfiguration._strcCs�d|��d}|jd@r d}nd}|jd@r4d}nd}d	|d
dt|�fdd
|jfdd|jttj|j�fdd|j|jfdd|j	fdd|j
fdd|jt|j
|j�fdd|j||fdd|jtj|jfS)Nz  rv�@ZSelfZBus� z, Remote Wakeuprryrzr{z   %-21s:%#7x (9 bytes)
rfz   %-21s:%#7x %s
rgz   %-21s:%#7x (%d bytes)
r�z   %-21s:%#7x
r�r=r�z   %-21s:%#7x %s Powered%s
rhz   %-21s:%#7x (%d mA)r�)rurhrrfrgrr�r�r�r�r=r�rrGr�r�)r!r�ZpoweredZ
remote_wakeuprrrr��sV

����
����
����
��
��z&Configuration._get_full_descriptor_strN)r)
r#r$r%r&r:r"r�r�r�r�r�rur�rrrrr,s
#rc@seZdZdZdd�Zdd�Zdd�Zdd	�Zed
d��Z	edd
��Z
edd��Zedd��Zedd��Z
d>dd�Zdd�Zd?dd�Zdd�Zdd�Zd@dd �ZdAd!d"�ZdBd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�Zd:d;�Z eeed<d=�Z!dS)Cra
Device object.

    This class contains all fields of the Device Descriptor according to the
    USB Specification. You may access them as class properties.  For example,
    to access the field bDescriptorType of the device descriptor, you can
    do so:

    >>> import usb.core
    >>> dev = usb.core.find()
    >>> dev.bDescriptorType

    Additionally, the class provides methods to communicate with the hardware.
    Typically, an application will first call the set_configuration() method to
    put the device in a known configured state, optionally call the
    set_interface_altsetting() to select the alternate setting (if there is
    more than one) of the interface used, and call the write() and read()
    methods to send and receive data, respectively.

    When working in a new hardware, the first try could be like this:

    >>> import usb.core
    >>> dev = usb.core.find(idVendor=myVendorId, idProduct=myProductId)
    >>> dev.set_configuration()
    >>> dev.write(1, 'test')

    This sample finds the device of interest (myVendorId and myProductId should
    be replaced by the corresponding values of your device), then configures
    the device (by default, the configuration value is 1, which is a typical
    value for most devices) and then writes some data to the endpoint 0x01.

    Timeout values for the write, read and ctrl_transfer methods are specified
    in miliseconds. If the parameter is omitted, Device.default_timeout value
    will be used instead. This property can be set by the user at anytime.
    cCsd|��dSrqrtr rrrr"�szDevice.__repr__cCst|��}z|D]}|dt|�7}qWnHtynz|��}|d|j7}Wntyh|d7}Yn0Yn0|S)Nr�z" USBError Accessing Configurations)r�rDr^rP�info)r!rrorrrr��szDevice.__str__cCst|�S)z,Return a tuple of the device configurations.r�r rrr�configurations�szDevice.configurationscCs�t||�|_t|_d\|_|_|_d|_|�|�}t	||d�|j
durVt|j
�|_
nd|_
|jdurtt|j�|_nd|_|j
dur�t|j
�|_
nd|_
|jdur�t|j�|_nd|_dS)aCInitialize the Device object.

        Library users should normally get a Device instance through
        the find function. The dev parameter is the identification
        of a device to the backend and its meaning is opaque outside
        of it. The backend parameter is a instance of a backend
        object.
        )NNNN)rfrg�bcdUSB�bDeviceClass�bDeviceSubClass�bDeviceProtocol�bMaxPacketSize0�idVendor�	idProduct�	bcdDevice�
iManufacturer�iProduct�
iSerialNumber�bNumConfigurations�address�bus�port_numberZport_numbers�speed)r1rl�_DEFAULT_TIMEOUT�_Device__default_timeout�_serial_number�_product�
_manufacturer�_langidsZget_device_descriptorrr��intr�r�r�)r!rr2rprrrr:�s,	
�



zDevice.__init__cCs:|jdur4zt�|�|_Wnty2d|_Yn0|jS)a� Return the USB device's supported language ID codes.

        These are 16-bit codes familiar to Windows developers, where for
        example instead of en-US you say 0x0409. USB_LANGIDS.pdf on the usb.org
        developer site for more info. String requests using a LANGID not
        in this array should not be sent to the device.

        This property will cause some USB traffic the first time it is accessed
        and cache the resulting value for future use.
        Nr)r�rZget_langidsr^r rrr�langids#s
zDevice.langidscCs |jdurt�||j�|_|jS)z� Return the USB device's serial number string descriptor.

        This property will cause some USB traffic the first time it is accessed
        and cache the resulting value for future use.
        N)r�rrr�r rrr�
serial_number6s
zDevice.serial_numbercCs |jdurt�||j�|_|jS)z� Return the USB device's product string descriptor.

        This property will cause some USB traffic the first time it is accessed
        and cache the resulting value for future use.
        N)r�rrr�r rrr�productAs
zDevice.productcCs |jdurt�||j�|_|jS)z� Return the USB device's manufacturer string descriptor.

        This property will cause some USB traffic the first time it is accessed
        and cache the resulting value for future use.
        N)r�rrr�r rrr�manufacturerLs
zDevice.manufacturercCs|jjS)z,Return the backend being used by the device.)rlr2r rrrr2WszDevice.backendNcCs|j�||�dS)a�Set the active configuration.

        The configuration parameter is the bConfigurationValue field of the
        configuration you want to set as active. If you call this method
        without parameter, it will use the first configuration found.  As a
        device hardly ever has more than one configuration, calling the method
        without arguments is enough to get the device ready.
        N)rlrI)r!rorrrrE\s	zDevice.set_configurationcCs|j�|�S)zZReturn a Configuration object representing the current
        configuration set.
        )rlrPr rrrrPgszDevice.get_active_configurationcCs|j�|||�dS)a}Set the alternate setting for an interface.

        When you want to use an interface and it has more than one alternate
        setting, you should call this method to select the appropriate
        alternate setting. If you call the method without one or the two
        parameters, it will be selected the first one found in the Device in
        the same way of the set_configuration method.

        Commonly, an interface has only one alternate setting and this call is
        not necessary. For most devices, either it has more than one
        alternate setting or not, it is not harmful to make a call to this
        method with no arguments, as devices will silently ignore the request
        when there is only one alternate setting, though the USB Spec allows
        devices with no additional alternate setting return an error to the
        Host in response to a SET_INTERFACE request.

        If you are in doubt, you may want to call it with no arguments wrapped
        by a try/except clause:

        >>> try:
        >>>     dev.set_interface_altsetting()
        >>> except usb.core.USBError:
        >>>     pass
        N)rlrV)r!rmrnrrrrTmszDevice.set_interface_altsettingcCs2t|t�r|j}|j��|jj�|jj|�dS)z4 Clear the halt/stall condition for the endpoint ep.N)r@rrWrlr;r2r�r4)r!r[rrrr��s

zDevice.clear_haltcCs<|j��|j�|d�|jj�|jj�|j�|d�dS)zReset the device.FTN)rlr;rar2Zreset_devicer4r rrr�reset�s
zDevice.resetc	Csj|jj}tj|jtj|jtj|ji}|j�	||�\}}|t�
|j�}||jj|j
|jt�|�|�|��S)a�Write data to the endpoint.

        This method is used to send data to the device. The endpoint parameter
        corresponds to the bEndpointAddress member whose endpoint you want to
        communicate with.

        The data parameter should be a sequence like type convertible to
        the array type (see array module).

        The timeout is specified in miliseconds.

        The method returns the number of bytes written.
        )rlr2r�ENDPOINT_TYPE_BULKZ
bulk_write�ENDPOINT_TYPE_INTRZ
intr_write�ENDPOINT_TYPE_ISOZ	iso_writer\�
endpoint_typerhr4rWrJr5�as_array�_Device__get_timeout)	r!rYr�r�r2�fn_maprLr[�fnrrrr��s��zDevice.writecCs�|jj}tj|jtj|jtj|ji}|j�	||�\}}|t�
|j�}t|t
j
�rX|}	n
t�|�}	||jj|j|j|	|�|��}
t|t
j
�r�|
S|
t|	�|	jkr�|	d|
�S|	SdS)a�Read data from the endpoint.

        This method is used to receive data from the device. The endpoint
        parameter corresponds to the bEndpointAddress member whose endpoint
        you want to communicate with. The size_or_buffer parameter either
        tells how many bytes you want to read or supplies the buffer to
        receive the data (it *must* be an object of the type array).

        The timeout is specified in miliseconds.

        If the size_or_buffer parameter is the number of bytes to read, the
        method returns an array object with the data read. If the
        size_or_buffer parameter is an array object, it returns the number
        of bytes actually read.
        N)rlr2rr�Z	bulk_readr�Z	intr_readr�Ziso_readr\r�rhr@�array�
create_bufferr4rWrJr�r�itemsize)r!rYr�r�r2r�rLr[r��buff�retrrrr��s,�
�zDevice.readrcCs�zt�|�}Wnty*t�|�}Yn0|j��|d@}|d@}	|tjkrp|	tjkrp|d@}
|j�	||
�|jj
�|jj||||||�
|��}t|tj�s�t�|�tjkr�|S|t|�|jkr�|d|�S|SdS)a�Do a control transfer on the endpoint 0.

        This method is used to issue a control transfer over the endpoint 0
        (endpoint 0 is required to always be a control endpoint).

        The parameters bmRequestType, bRequest, wValue and wIndex are the same
        of the USB Standard Control Request format.

        Control requests may or may not have a data payload to write/read.
        In cases which it has, the direction bit of the bmRequestType
        field is used to infer the desired request direction. For
        host to device requests (OUT), data_or_wLength parameter is
        the data payload to send, and it must be a sequence type convertible
        to an array object. In this case, the return value is the number
        of bytes written in the data payload. For device to host requests
        (IN), data_or_wLength is either the wLength parameter of the control
        request specifying the number of bytes to read in data payload, and
        the return value is an array object with data read, or an array
        object which the data will be read to, and the return value is the
        number of bytes read.
        r|�`�N)rr��	TypeErrorr5r�rlr;ZCTRL_RECIPIENT_INTERFACEZCTRL_TYPE_VENDORrNr2�
ctrl_transferr4r�r@r�Zctrl_directionZCTRL_OUTrr�)r!Z
bmRequestTypeZbRequestZwValueZwIndexZdata_or_wLengthr�r�Z	recipientZrqtypeZinterface_numberr�rrrr��s8

��	�zDevice.ctrl_transfercCs|j��|jj�|jj|�S)z�Determine if there is kernel driver associated with the interface.

        If a kernel driver is active, the object will be unable to perform
        I/O.

        The interface parameter is the device interface number to check.
        )rlr;r2�is_kernel_driver_activer4�r!rmrrrr�s

�zDevice.is_kernel_driver_activecCs"|j��|jj�|jj|�dS)z�Detach a kernel driver.

        If successful, you will then be able to perform I/O.

        The interface parameter is the device interface number to detach the
        driver from.
        N)rlr;r2�detach_kernel_driverr4r�rrrr�*s

�zDevice.detach_kernel_drivercCs"|j��|jj�|jj|�dS)z�Re-attach an interface's kernel driver, which was previously
        detached using detach_kernel_driver().

        The interface parameter is the device interface number to attach the
        driver to.
        N)rlr;r2�attach_kernel_driverr4r�rrrr�7s

�zDevice.attach_kernel_driverccs t|j�D]}t||�Vq
dS)z.Iterate over all configurations of the device.N)r�r�rr�rrrr�CszDevice.__iter__cCs
t||�S)z6Return the Configuration object in the given position.)rr�rrrr�HszDevice.__getitem__cCs|j�|�dSr)rlrar rrr�_finalize_objectLszDevice._finalize_objectcCs|dur|S|jSr�r�)r!r�rrrZ
__get_timeoutOszDevice.__get_timeoutcCs|dkrtd��||_dS)Nrz"Timeout cannot be a negative value)rCr�)r!ZtmorrrZ
__set_def_tmoTszDevice.__set_def_tmocCs|jSrr�r rrrZ
__get_def_tmoYszDevice.__get_def_tmocCsd|j|j|j|jfS)Nz,DEVICE ID %04x:%04x on Bus %03d Address %03d)r�r�r�r�r rrrru\s�zDevice._strcCs�|��d}|jd@r&t|jd@�}nd}|jd@rDt|jd@�}nd}d|ddt|�fdd|jfd	d
|jttj	|j�fdd|j|jd
@d?|jd@d?|fd	d|j
ttj|j
�fdd|jfdd|j
fdd|j|jfdd|jfdd|jfdd|j|jd
@d?|jd@d?|fd	d|jt||j�fd	d|jt||j�fd	d|jt||j�fdd |jfS)!Nrv�rryrzr{z %-23s:%#7x (18 bytes)
rfz %-23s:%#7x %s
rgz %-23s:%#7x USB %d.%d%s
r�i�����r�z %-23s:%#7x
r�r�z %-23s:%#7x (%d bytes)
r�z %-23s: %#06x
r�r�z %-23s:%#7x Device %d.%d%s
r�r�r�r�z %-23s:%#7xr�)rur�rDr�rrfrgrr�r�r��device_classesr�r�r�r�r�r�rr�r�r�)r!r�Zlow_bcd_usbZlow_bcd_devicerrrr�`s�

������	������
��������
��
��
��"��zDevice._get_full_descriptor_strz*Default timeout for transfer I/O functions)�doc)N)NN)N)N)rrNN)"r#r$r%r&r"r�r�r:�propertyr�r�r�r�r2rErPrTr�r�r�r�r�r�r�r�r�r�r�r�Z_Device__set_def_tmoZ_Device__get_def_tmorur�Zdefault_timeoutrrrrr�sR#
>










!
.�
8

2�rFc	s���fdd�}�dur�ddlmm}ddlmm}ddlmm}|||fD]&}|����durVt�	d|j
�q�qVtd��|r�|fi|��Szt�
|fi|���WSty�YdS0dS)a
Find an USB device and return it.

    find() is the function used to discover USB devices.  You can pass as
    arguments any combination of the USB Device Descriptor fields to match a
    device. For example:

    find(idVendor=0x3f4, idProduct=0x2009)

    will return the Device object for the device with idVendor field equals
    to 0x3f4 and idProduct equals to 0x2009.

    If there is more than one device which matchs the criteria, the first one
    found will be returned. If a matching device cannot be found the function
    returns None. If you want to get all devices, you can set the parameter
    find_all to True, then find will return an iterator with all matched devices.
    If no matching device is found, it will return an empty iterator. Example:

    for printer in find(find_all=True, bDeviceClass=7):
        print (printer)

    This call will get all the USB printers connected to the system.  (actually
    may be not, because some devices put their class information in the
    Interface Descriptor).

    You can also use a customized match criteria:

    dev = find(custom_match = lambda d: d.idProduct=0x3f4 and d.idvendor=0x2009)

    A more accurate printer finder using a customized match would be like
    so:

    def is_printer(dev):
        import usb.util
        if dev.bDeviceClass == 7:
            return True
        for cfg in dev:
            if usb.util.find_descriptor(cfg, bInterfaceClass=7) is not None:
                return True

    for printer in find(find_all=True, custom_match = is_printer):
        print (printer)

    Now even if the device class code is in the interface descriptor the
    printer will be found.

    You can combine a customized match with device descriptor fields. In this
    case, the fields must match and the custom_match must return True. In the
    our previous example, if we would like to get all printers belonging to the
    manufacturer 0x3f4, the code would be like so:

    printers = list(find(find_all=True, idVendor=0x3f4, custom_match=is_printer))

    If you want to use find as a 'list all devices' function, just call
    it with find_all = True:

    devices = list(find(find_all=True))

    Finally, you can pass a custom backend to the find function:

    find(backend = MyBackend())

    PyUSB has builtin backends for libusb 0.1, libusb 1.0 and OpenUSB.  If you
    do not supply a backend explicitly, find() function will select one of the
    predefineds backends according to system availability.

    Backends are explained in the usb.backend module.
    c;sR���D]D}t|����fdd�|��D�}t�|�r�dusF���r�VqdS)Nc3s |]\}}|t�|�kVqdSr)r
)�.0�key�val��drr�	<genexpr>��z,find.<locals>.device_iter.<locals>.<genexpr>)Zenumerate_devicesr�itemsr5Z_all)r+rZtests�r2�custom_matchr�r�device_iter�s

zfind.<locals>.device_iterNrzfind(): using backend "%s"zNo backend available)Zusb.backend.libusb1r2�libusb1Zusb.backend.libusb0�libusb0Zusb.backend.openusb�openusbZget_backend�_loggerr�r#rer5Z_next�
StopIteration)	�find_allr2r�r*r�r�r�r��mrr�rr�s"DrcKs`d|d<tfi|��}d}|D]8}|sF|d|��ttj|j�f7}q|dt|�7}qt|�S)z�Show information about connected devices.

    The verbose flag sets to verbose or not.
    **kwargs are passed directly to the find() function.
    Tr�rz%s, %s
z%s

)rrurr�r�r�rDr)�verboser+Zdevices�stringsrGrrrr�s�r)Nrr)r)FNN)F)(r&�
__author__�__all__Zusb.utilrr_�operatorZusb._interopr5Zusb._objfinalizerZ
_objfinalizerZusb._lookupZ_lookupr�Zloggingr�r8r.Z	getLoggerr�r�rrrrDrr0rAr1rbr^rCrerrrZAutoFinalizedObjectrrrrrrr�<module>sJ
�



!
o
`