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__/util.cpython-39.opt-1.pyc
a

j��Y0�@sdZdZddlZddlZddlmZddlmZdZdZ	dZ
dZd	Zd
Z
dZdZdZdZdZdZdZdZd
ZdZdZdZdZdZd
ZdZd
ZdZd
Z d�!d�Z"dZ#dZ$dZ%dZ&dZ'dd�Z(dd�Z)dd�Z*dd�Z+dd�Z,dd�Z-d*dd�Z.d d!�Z/d"d#�Z0d$d%�Z1d&d'�Z2d+d(d)�Z3dS),a�usb.util - Utility functions.

This module exports:

endpoint_address - return the endpoint absolute address.
endpoint_direction - return the endpoint transfer direction.
endpoint_type - return the endpoint type
ctrl_direction - return the direction of a control transfer
build_request_type - build a bmRequestType field of a control transfer.
find_descriptor - find an inner descriptor.
claim_interface - explicitly claim an interface.
release_interface - explicitly release an interface.
dispose_resources - release internal resources allocated by the object.
get_langids - retrieve the list of supported string languages from the device.
get_string - retrieve a string descriptor from the device.
zWander Lairson Costa�N)�
hexversion������� �@�`��zutf-8cCs|t@S)z�Return the endpoint absolute address.

    The address parameter is the bEndpointAddress field
    of the endpoint descriptor.
    )�_ENDPOINT_ADDR_MASK�Zaddress�r�,/usr/lib/python3.9/site-packages/usb/util.py�endpoint_addressesrcCs|t@S)z�Return the endpoint direction.

    The address parameter is the bEndpointAddress field
    of the endpoint descriptor.
    The possible return values are ENDPOINT_OUT or ENDPOINT_IN.
    )�_ENDPOINT_DIR_MASKrrrr�endpoint_directionmsrcCs|t@S)aReturn the transfer type of the endpoint.

    The bmAttributes parameter is the bmAttributes field
    of the endpoint descriptor.
    The possible return values are: ENDPOINT_TYPE_CTRL,
    ENDPOINT_TYPE_ISO, ENDPOINT_TYPE_BULK or ENDPOINT_TYPE_INTR.
    )�_ENDPOINT_TRANSFER_TYPE_MASK)ZbmAttributesrrr�
endpoint_typevsrcCs|t@S)z�Return the direction of a control request.

    The bmRequestType parameter is the value of the
    bmRequestType field of a control transfer.
    The possible return values are CTRL_OUT or CTRL_IN.
    )�_CTRL_DIR_MASK)Z
bmRequestTyperrr�ctrl_direction�srcCs||B|BS)a�Build a bmRequestType field for control requests.

    These is a conventional function to build a bmRequestType
    for a control request.

    The direction parameter can be CTRL_OUT or CTRL_IN.
    The type parameter can be CTRL_TYPE_STANDARD, CTRL_TYPE_CLASS,
    CTRL_TYPE_VENDOR or CTRL_TYPE_RESERVED values.
    The recipient can be CTRL_RECIPIENT_DEVICE, CTRL_RECIPIENT_INTERFACE,
    CTRL_RECIPIENT_ENDPOINT or CTRL_RECIPIENT_OTHER.

    Return the bmRequestType value.
    r)�	direction�typeZ	recipientrrr�build_request_type�srcCst�dt|�S)a<Create a buffer to be passed to a read function.

    A read function may receive an out buffer so the data
    is read inplace and the object can be reused, avoiding
    the overhead of creating a new object at each new read
    call. This function creates a compatible sequence buffer
    of the given length.
    �B)�array�_dummy_s)�lengthrrr�
create_buffer�s	r FcsP��fdd�}|r |fi|��Szt�|fi|���WStyJYdS0dS)a�Find an inner descriptor.

    find_descriptor works in the same way as the core.find() function does,
    but it acts on general descriptor objects. For example, suppose you
    have a Device object called dev and want a Configuration of this
    object with its bConfigurationValue equals to 1, the code would
    be like so:

    >>> cfg = util.find_descriptor(dev, bConfigurationValue=1)

    You can use any field of the Descriptor as a match criteria, and you
    can supply a customized match just like core.find() does. The
    find_descriptor function also accepts the find_all parameter to get
    an iterator instead of just one descriptor.
    c;sD�D]:��fdd�|��D�}t�|�r�dus8���r�VqdS)Nc3s |]\}}|t�|�kVqdS)N)�getattr)�.0�key�val��drr�	<genexpr>��z5find_descriptor.<locals>.desc_iter.<locals>.<genexpr>)�items�_interopZ_all)�kwargsZtests��custom_match�descr%r�	desc_iter�sz"find_descriptor.<locals>.desc_iterN)r*Z_next�
StopIteration)r.Zfind_allr-�argsr/rr,r�find_descriptor�sr2cCs|j�||�dS)a�Explicitly claim an interface.

    PyUSB users normally do not have to worry about interface claiming,
    as the library takes care of it automatically. But there are situations
    where you need deterministic interface claiming. For these uncommon
    cases, you can use claim_interface.

    If the interface is already claimed, either through a previously call
    to claim_interface or internally by the device object, nothing happens.
    N)�_ctxZmanaged_claim_interface��deviceZ	interfacerrr�claim_interface�sr6cCs|j�||�dS)a;Explicitly release an interface.

    This function is used to release an interface previously claimed,
    either through a call to claim_interface or internally by the
    device object.

    Normally, you do not need to worry about claiming policies, as
    the device object takes care of it automatically.
    N)r3Zmanaged_release_interfacer4rrr�release_interface�s
r7cCs|j�|�dS)a!Release internal resources allocated by the object.

    Sometimes you need to provide deterministic resources
    freeing, for example to allow another application to
    talk to the device. As Python does not provide deterministic
    destruction, this function releases all internal resources
    allocated by the device, like device handle and interface
    policy.

    After calling this function, you can continue using the device
    object normally. If the resources will be necessary again, it
    will be allocated automatically.
    N)r3Zdispose)r5rrr�dispose_resources�sr8cCsvddlm}||dtd�}t|�dksB|ddksB|dd@dkrFdSttdd�|d	|dd	�|d
|dd	���S)a�Retrieve the list of supported Language IDs from the device.

    Most client code should not call this function directly, but instead use
    the langids property on the Device object, which will call this function as
    needed and cache the result.

    USB LANGIDs are 16-bit integers familiar to Windows developers, where
    for example instead of en-US you say 0x0409. See the file USB_LANGIDS.pdf
    somewhere on the usb.org site for a list, which does not claim to be
    complete. It requires "system software must allow the enumeration and
    selection of LANGIDs that are not currently on this list." It also requires
    "system software should never request a LANGID not defined in the LANGID
    code array (string index = 0) presented by a device." Client code can
    check this tuple before issuing string requests for a specific language ID.

    dev is the Device object whose supported language IDs will be retrieved.

    The return value is a tuple of integer LANGIDs, possibly empty if the
    device does not support strings at all (which USB 3.1 r1.0 section
    9.6.9 allows). In that case client code should not request strings at all.

    A USBError may be raised from this function for some devices that have no
    string support, instead of returning an empty tuple. The accessor for the
    langids property on Device catches that case and supplies an empty tuple,
    so client code can ignore this detail by using the langids property instead
    of directly calling this function.
    r��get_descriptor�rrrcSs||d>S)N�r)�x�yrrr�<lambda>r(zget_langids.<locals>.<lambda>rr)�usb.controlr:�DESC_TYPE_STRING�len�tuple�map)�devr:�bufrrr�get_langids�s�(rGcCs�d|krdSddlm}|j}dt|�kr2td��|durD|d}n||vrTtd��||dt||�}tdkr�|d|d����d	�S|d|d��	��d	�SdS)
a�Retrieve a string descriptor from the device.

    dev is the Device object which the string will be read from.

    index is the string descriptor index and langid is the Language
    ID of the descriptor. If langid is omitted, the string descriptor
    of the first Language ID will be returned.

    Zero is never the index of a real string. The USB spec allows a device to
    use zero in a string index field to indicate that no string is provided.
    So the caller does not have to treat that case specially, this function
    returns None if passed an index of zero, and generates no traffic
    to the device.

    The return value is the unicode string present in the descriptor, or None
    if the requested index was zero.

    It is a ValueError to request a real string (index not zero), if: the
    device's langid tuple is empty, or with an explicit langid the device does
    not support.
    rNr9zThe device has no langidz0The device does not support the specified langid�irz	utf-16-le)
r@r:�langidsrB�
ValueErrorrAr�tobytes�decodeZtostring)rE�indexZlangidr:rIrFrrr�
get_strings(
�rN)FN)N)4�__doc__�
__author__�operatorr�sysrZusb._interopr*ZDESC_TYPE_DEVICEZDESC_TYPE_CONFIGrAZDESC_TYPE_INTERFACEZDESC_TYPE_ENDPOINTZENDPOINT_INZENDPOINT_OUTZENDPOINT_TYPE_CTRLZENDPOINT_TYPE_ISOZENDPOINT_TYPE_BULKZENDPOINT_TYPE_INTRZCTRL_TYPE_STANDARDZCTRL_TYPE_CLASSZCTRL_TYPE_VENDORZCTRL_TYPE_RESERVEDZCTRL_RECIPIENT_DEVICEZCTRL_RECIPIENT_INTERFACEZCTRL_RECIPIENT_ENDPOINTZCTRL_RECIPIENT_OTHERZCTRL_OUTZCTRL_INrrrr�encoderZ	SPEED_LOWZ
SPEED_FULLZ
SPEED_HIGHZSPEED_SUPERZ
SPEED_UNKNOWNrrrrrr r2r6r7r8rGrNrrrr�<module>s`
	
	

2