File: //usr/lib/python3.9/site-packages/usb/__pycache__/util.cpython-39.opt-1.pyc
a
j��Y0 � @ s d Z dZddlZddlZddlmZ ddlmZ dZdZ dZ
dZd Zd
Z
dZdZdZdZdZdZdZdZd
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-8c C s | 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_addresse s r c C s | 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_MASKr r r r �endpoint_directionm s r c C s | t @ S )a Return 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)ZbmAttributesr r r �
endpoint_typev s r c C s | 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
bmRequestTyper r r �ctrl_direction� s r c C s ||B | B S )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 recipientr r r �build_request_type� s r c C s t � 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)�lengthr r r �
create_buffer� s r Fc sP � �fdd�}|r |f i |��S zt �|f i |���W S tyJ Y dS 0 dS )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�d u s8�� �r� V qd S )Nc 3 s | ]\}}|t � |�kV qd S )N)�getattr)�.0�key�val��dr r � <genexpr>� � z5find_descriptor.<locals>.desc_iter.<locals>.<genexpr>)�items�_interopZ_all)�kwargsZtests��custom_match�descr% r � desc_iter� s z"find_descriptor.<locals>.desc_iterN)r* Z_next�
StopIteration)r. Zfind_allr- �argsr/ r r, r �find_descriptor� s r2 c C s | 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 interfacer r r �claim_interface� s r6 c C s | 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)r3 Zmanaged_release_interfacer4 r r r �release_interface� s
r7 c C s | 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)r3 Zdispose)r5 r r r �dispose_resources� s r8 c C sv ddl m} || dtd�}t|�dk sB|d dk sB|d d@ dkrFdS ttdd� |d |d d � |d
|d d � ��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� r r r c S s | |d>