Ë
    ¿[;já1  ã                   óœ   — d Z ddlZddlZddlmZmZmZ dd„Z G d„ d«      Zd„ Z	d	„ Z
d
„ Zd„ Z G d„ d«      Z G d„ d«      Z G d„ d«      Zy)a/  
Async wrappers for py-lmdb via :func:`asyncio.loop.run_in_executor`.

Usage::

    import lmdb
    import lmdb.aio

    env = lmdb.open('/tmp/mydb')
    aenv = lmdb.aio.wrap(env)

    async with aenv.begin(write=True) as txn:
        await txn.put(b'key', b'value')
        val = await txn.get(b'key')
é    Né   )ÚCursorÚEnvironmentÚTransactionc                 ó   — t        | |«      S )z®Wrap an :class:`lmdb.Environment` for async use.

    *executor* is passed to :meth:`loop.run_in_executor`.  ``None`` (the
    default) uses the loop's default executor.
    )ÚAsyncEnvironment)ÚenvÚexecutors     úQG:\00. PROJECTS\API\Inventory\templateJSON\kerjaOCR\Lib\site-packages\lmdb/aio.pyÚwrapr   +   s   € ô ˜C Ó*Ð*ó    c                   ó,   — e Zd ZdZdZd„ Zd„ Zd„ Zd„ Zy)Ú_AsyncContextWrapperzáWraps a coroutine so it can be used as both ``await`` and ``async with``.

    Supports::

        txn = await aenv.begin(write=True)      # just await
        async with aenv.begin(write=True) as txn:  # context manager
    ©Ú_coroÚ_resultc                 ó    — || _         d | _        y ©Nr   )ÚselfÚcoros     r   Ú__init__z_AsyncContextWrapper.__init__?   s   € ØˆŒ
Øˆ�r   c                 ó6   — | j                   j                  «       S r   )r   Ú	__await__©r   s    r   r   z_AsyncContextWrapper.__await__C   s   € Ø�z‰z×#Ñ#Ó%Ð%r   c              ƒ   óX   K  — | j                   ƒ d {  –—† | _        | j                  S 7 Œ­wr   r   r   s    r   Ú
__aenter__z_AsyncContextWrapper.__aenter__F   s#   è ø€ Ø!ŸZ™Z×'ˆŒØ�|‰|Ðð (ús   ‚*’(“*c              ƒ   óX   K  — | j                   j                  |||«      ƒ d {  –—† S 7 Œ­wr   )r   Ú	__aexit__)r   Úexc_typeÚexc_valÚexc_tbs       r   r   z_AsyncContextWrapper.__aexit__J   s%   è ø€ Ø—\‘\×+Ñ+¨H°g¸vÓF×FÐFÐFús   ‚!*£(¤*N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__r   r   r   r   © r   r   r   r   4   s#   „ ñð %€Iòò&òóGr   r   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )z@Return a method that calls *sync* directly, without an executor.c                 óD   •—  ‰t        | | j                  «      g|¢­i |¤ŽS r   )ÚgetattrÚ_WRAPS)r   ÚargsÚkwargsÚsyncs      €r   Úmethodz_sync_method.<locals>.methodT   s#   ø€ á”G˜D $§+¡+Ó.Ð@°Ò@¸Ñ@Ð@r   ©Ú	functoolsÚwraps©r.   r/   s   ` r   Ú_sync_methodr4   R   s%   ø€ ä‡_�_�TÓóAó ðAà€Mr   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )z<Return a coroutine method that calls *sync* in the executor.c           
   Ÿ   óØ   •K  — t        j                  «       }|j                  | j                  t	        j
                  ‰t        | | j                  «      g|¢­i |¤Ž«      ƒ d {  –—† S 7 Œ­wr   )ÚasyncioÚget_running_loopÚrun_in_executorÚ	_executorr1   Úpartialr*   r+   ©r   r,   r-   Úloopr.   s       €r   r/   z_async_method.<locals>.method\   s^   øè ø€ ä×'Ñ'Ó)ˆØ×)Ñ)Ø�N‰NÜ×Ñ˜d¤G¨D°$·+±+Ó$>ÐPÀÒPÈÑPó
÷ 
ð 	
ð 
ús   ƒA A*Á#A(Á$A*r0   r3   s   ` r   Ú_async_methodr>   Z   s%   ø€ ä‡_�_�TÓó
ó ð
ð €Mr   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )z>Like :func:`_async_method`, but acquires ``self._lock`` first.c              Ÿ   óV  •K  — | j                   4 ƒd {  –—†  t        j                  «       }|j                  | j                  t        j                  ‰t        | | j                  «      g|¢­i |¤Ž«      ƒ d {  –—† cd d d «      ƒd {  –—†  S 7 Œy7 Œ7 Œ	# 1 ƒd {  –—†7  sw Y   y xY w­wr   )	Ú_lockr7   r8   r9   r:   r1   r;   r*   r+   r<   s       €r   r/   z$_async_method_locked.<locals>.methodh   sy   øè ø€ à—:—:“:Ü×+Ñ+Ó-ˆDØ×-Ñ-Ø—‘Ü×!Ñ! $¬°°d·k±kÓ(BÐTÀTÒTÈVÑTó÷ ÷ —:’:øðøð ø—:—:‘:üsW   ƒB)”B•B)˜A BÁ8BÁ9BÁ<B)ÂBÂ	B)ÂBÂB)ÂB&ÂBÂB&Â"B)r0   r3   s   ` r   Ú_async_method_lockedrB   f   s%   ø€ ä‡_�_�TÓóó ðð €Mr   c                 óB   ‡ — t        j                  ‰ «      ˆ fd„«       }|S )zvLike :func:`_async_method_locked`, but *sync* returns an iterator
    consumed in the executor and returned as a list.c              Ÿ   ó  •‡ ‡‡K  — ‰ j                   4 ƒd {  –—†  t        j                  «       }|j                  ‰ j                  ˆˆˆ ˆfd„«      ƒ d {  –—† cd d d «      ƒd {  –—†  S 7 ŒS7 Œ7 Œ	# 1 ƒd {  –—†7  sw Y   y xY w­w)Nc                  óV   •— t         ‰t        ‰‰j                  «      g‰ ¢­i ‰¤Ž«      S r   )Úlistr*   r+   )r,   r-   r   r.   s   €€€€r   Ú<lambda>z1_collect_locked.<locals>.method.<locals>.<lambda>|   s$   ø€ œ™T¤'¨$°·±Ó"<ÐN¸tÒNÀvÑNÔOr   )rA   r7   r8   r9   r:   r<   s   ``` €r   r/   z_collect_locked.<locals>.methodv   sW   ûè ø€ à—:—:“:Ü×+Ñ+Ó-ˆDØ×-Ñ-Ø—‘ÞOó÷ ÷ —:’:øðøð ø—:—:‘:üsV   †B—A+˜B›:A1ÁA-ÁA1ÁBÁ%A/Á&BÁ-A1Á/BÁ1BÁ7A:Á8BÁ?Br0   r3   s   ` r   Ú_collect_lockedrH   s   s'   ø€ ô ‡_�_�TÓóó ðð €Mr   c                   óT  — e Zd ZdZdZdZd
d„Zd„ Zd„ Zd„ Z	 e
ej                  «      Z e
ej                  «      Z e
ej                  «      Z e
ej                  «      Z eej"                  «      Z eej$                  «      Z eej&                  «      Z eej(                  «      Z eej*                  «      Z eej,                  «      Z eej.                  «      Z eej0                  «      Z eej2                  «      Z eej4                  «      Z eej6                  «      Zd	„ Zy)r   u¸  Async wrapper for :py:class:`lmdb.Environment`.

    Created by :py:func:`wrap`.  All methods of the underlying
    :py:class:`~lmdb.Environment` are available and are dispatched to an
    executor, except for the low-overhead accessors ``path()``,
    ``max_key_size()``, ``max_readers()``, and ``flags()``, which are called
    directly.

    Supports ``async with`` for lifetime management â€” the environment is
    closed on exit.
    ©Ú_envr:   rK   Nc                 ó    — || _         || _        y r   rJ   )r   r	   r
   s      r   r   zAsyncEnvironment.__init__–   s   € ØˆŒ	Ø!ˆ�r   c              ƒ   ó   K  — | S ­wr   r'   r   s    r   r   zAsyncEnvironment.__aenter__œ   ó   è ø€ Øˆùó   ‚c              ‡   ó@   K  — | j                   j                  «        y ­wr   )rK   Úclose©r   Ú_excs     r   r   zAsyncEnvironment.__aexit__Ÿ   s   è ø€ Ø�	‰	�‰Õùó   ‚c                 ó6   ‡ ‡‡— ˆˆˆ fd„}t         |«       «      S )a4  Start a new transaction, returning an :py:class:`AsyncTransaction`.

        Accepts the same arguments as :py:meth:`lmdb.Environment.begin`.
        Can be used with ``await`` or ``async with``::

            async with aenv.begin(write=True) as txn:
                await txn.put(b'key', b'value')
        c               “   ó  •K  — t        j                  «       } | j                  ‰j                  t	        j
                  ‰j                  j                  g‰¢­i ‰¤Ž«      ƒ d {  –—† }t        |‰j                  «      S 7 Œ­wr   )	r7   r8   r9   r:   r1   r;   rK   ÚbeginÚAsyncTransaction)r=   Útxnr,   r-   r   s     €€€r   Ú_beginz&AsyncEnvironment.begin.<locals>._begin­   si   øè ø€ Ü×+Ñ+Ó-ˆDØ×,Ñ,Ø—‘Ü×!Ñ! $§)¡)§/¡/ÐC°DÒC¸FÑCó÷ ˆCô $ C¨¯©Ó8Ð8ð	ús   ƒAA?Á"A=Á#A?©r   )r   r,   r-   rZ   s   ``` r   rW   zAsyncEnvironment.begin¤   s   ú€ ö	9ô $¡F£HÓ-Ð-r   c                 ó^   — t        | j                  |«      }t        |«      rt        |«      ‚|S r   )r*   rK   ÚcallableÚAttributeError©r   ÚnameÚattrs      r   Ú__getattr__zAsyncEnvironment.__getattr__Ë   ó)   € Ü�t—y‘y $Ó'ˆÜ�DŒ>Ü  Ó&Ð&Øˆr   r   )r"   r#   r$   r%   r&   r+   r   r   r   rW   r4   r   ÚpathÚmax_key_sizeÚmax_readersÚflagsr>   ÚstatÚinforQ   ÚcopyÚcopyfdr.   ÚreadersÚreader_checkÚset_mapsizeÚopen_dbÚdbsrb   r'   r   r   r   r   …   s  „ ñ
ð &€Ià€Fó"òòò
.ñ( ˜×(Ñ(Ó)€DÙ × 8Ñ 8Ó9€LÙ˜{×6Ñ6Ó7€KÙ˜×*Ñ*Ó+€Eá˜×)Ñ)Ó*€DÙ˜×)Ñ)Ó*€DÙ˜+×+Ñ+Ó,€EÙ˜×)Ñ)Ó*€DÙ˜;×-Ñ-Ó.€FÙ˜×)Ñ)Ó*€DÙ˜K×/Ñ/Ó0€GÙ  ×!9Ñ!9Ó:€LÙ × 7Ñ 7Ó8€KÙ˜K×/Ñ/Ó0€GÙ
˜Ÿ™Ó
(€Cór   r   c                   ó   — e Zd ZdZdZdZd
d„Zd„ Zd„ Zd„ Z	 e
ej                  «      Z eej                  «      Z eej                  «      Z eej                   «      Z eej"                  «      Z eej$                  «      Z eej&                  «      Z eej(                  «      Z eej*                  «      Z eej,                  «      Zd	„ Zy)rX   u  Async wrapper for :py:class:`lmdb.Transaction`.

    All methods of the underlying :py:class:`~lmdb.Transaction` are available.
    Most are dispatched to an executor; ``id()`` is called directly.

    An :py:class:`asyncio.Lock` serializes all operations dispatched through
    this transaction, including operations on its cursors.  This makes
    :py:func:`asyncio.gather` safe on the same transaction.

    Supports ``async with`` â€” write transactions are committed on clean exit
    and aborted on exception.
    )Ú_txnr:   rA   rr   Nc                 óR   — || _         || _        t        j                  «       | _        y r   )rr   r:   r7   ÚLockrA   )r   rY   r
   s      r   r   zAsyncTransaction.__init__ä   s   € ØˆŒ	Ø!ˆŒÜ—\‘\“^ˆ�
r   c              ƒ   ó   K  — | S ­wr   r'   r   s    r   r   zAsyncTransaction.__aenter__ë   rN   rO   c              ƒ   ó^  K  — | j                   4 ƒd {  –—†  |r| j                  j                  «        nLt        j                  «       }|j                  | j                  | j                  j                  «      ƒ d {  –—†  d d d «      ƒd {  –—†  y 7 Œ~7 Œ7 Œ	# 1 ƒd {  –—†7  sw Y   y xY w­wr   )rA   rr   Úabortr7   r8   r9   r:   Úcommit)r   r   Ú_exc_valÚ_exc_tbr=   s        r   r   zAsyncTransaction.__aexit__î   so   è ø€ Ø—:—:“:ÙØ—	‘	—‘Õ!ä×/Ñ/Ó1�Ø×*Ñ*¨4¯>©>¸4¿9¹9×;KÑ;KÓL×LÐL÷ —:‘:øð
 Møð ø—:—:‘:üsW   ‚B-“B”B-—A%BÁ<BÁ=BÂB-ÂBÂB-ÂBÂB-ÂB*ÂB!ÂB*Â&B-c                 ó6   ‡ ‡‡— ˆˆˆ fd„}t         |«       «      S )a;  Open a cursor, returning an :py:class:`AsyncCursor`.

        Accepts the same arguments as :py:meth:`lmdb.Transaction.cursor`.
        Can be used with ``await`` or ``async with``::

            async with txn.cursor() as cur:
                await cur.first()
                items = await cur.iternext()
        c            	   “   ó”  •K  — ‰j                   4 ƒd {  –—†  t        j                  «       } | j                  ‰j                  t        j                  ‰j                  j                  g‰¢­i ‰¤Ž«      ƒ d {  –—† }d d d «      ƒd {  –—†  t        ‰j                  ‰j                   «      S 7 Œ˜7 Œ77 Œ)# 1 ƒd {  –—†7  sw Y   Œ9xY w­wr   )
rA   r7   r8   r9   r:   r1   r;   rr   ÚcursorÚAsyncCursor)r=   Úcurr,   r-   r   s     €€€r   Ú_cursorz(AsyncTransaction.cursor.<locals>._cursor  s”   øè ø€ Ø—z—z“zÜ×/Ñ/Ó1�Ø ×0Ñ0Ø—N‘NÜ×%Ñ% d§i¡i×&6Ñ&6ÐH¸ÒHÀÑHó÷ �÷ "—zô ˜s D§N¡N°D·J±JÓ?Ð?ð "øðøð "ø—z—z‘züsW   ƒC”B-•C˜AB3Á7B/Á8B3Á<CÂB1Â&CÂ/B3Â1CÂ3CÂ9B<Â:CÃCr[   )r   r,   r-   r€   s   ``` r   r}   zAsyncTransaction.cursorø   s   ú€ ö	@ô $¡G£IÓ.Ð.r   c                 ó^   — t        | j                  |«      }t        |«      rt        |«      ‚|S r   )r*   rr   r]   r^   r_   s      r   rb   zAsyncTransaction.__getattr__  rc   r   r   )r"   r#   r$   r%   r&   r+   r   r   r   r}   r4   r   ÚidrB   rh   Údroprx   rw   ÚgetÚputÚreplaceÚpopÚdeleterb   r'   r   r   rX   rX   Ò   sÇ   „ ñð /€Ià€Fó$òòMò/ñ, 
�k—n‘nÓ	%€Bá × 0Ñ 0Ó1€DÙ × 0Ñ 0Ó1€DÙ! +×"4Ñ"4Ó5€FÙ  ×!2Ñ!2Ó3€EÙ
˜{Ÿ™Ó
/€CÙ
˜{Ÿ™Ó
/€CÙ" ;×#6Ñ#6Ó7€GÙ
˜{Ÿ™Ó
/€CÙ! +×"4Ñ"4Ó5€Fór   rX   c                   ó²  — e Zd ZdZdZdZd	d„Zd„ Zd„ Z e	e
j                  «      Z e	e
j                  «      Z e	e
j                  «      Z ee
j                  «      Z ee
j                   «      Z ee
j"                  «      Z ee
j$                  «      Z ee
j&                  «      Z ee
j(                  «      Z ee
j*                  «      Z ee
j,                  «      Z ee
j.                  «      Z ee
j0                  «      Z ee
j2                  «      Z ee
j4                  «      Z ee
j6                  «      Z ee
j8                  «      Z ee
j:                  «      Z ee
j<                  «      Z ee
j>                  «      Z ee
j@                  «      Z  ee
jB                  «      Z! ee
jD                  «      Z" ee
jF                  «      Z# ee
jH                  «      Z$ ee
jJ                  «      Z% e&e
jN                  «      Z' e&e
jP                  «      Z( e&e
jR                  «      Z) e&e
jT                  «      Z* e&e
jV                  «      Z+ e&e
jX                  «      Z,d„ Z-y)
r~   uÖ  Async wrapper for :py:class:`lmdb.Cursor`.

    All methods of the underlying :py:class:`~lmdb.Cursor` are available.
    Most are dispatched to an executor; ``key()``, ``value()``, and
    ``item()`` are called directly.

    Iterator methods (``iternext()``, ``iterprev()``, etc.) are consumed in
    the executor and returned as a list.

    Shares the parent transaction's :py:class:`asyncio.Lock`.

    Supports ``async with`` â€” the cursor is closed on exit.
    )r€   r:   rA   r€   Nc                 óZ   — || _         || _        |xs t        j                  «       | _        y r   )r€   r:   r7   rt   rA   )r   r}   r
   Úlocks       r   r   zAsyncCursor.__init__6  s"   € ØˆŒØ!ˆŒØÒ+œWŸ\™\›^ˆ�
r   c              ƒ   ó   K  — | S ­wr   r'   r   s    r   r   zAsyncCursor.__aenter__=  rN   rO   c              ‡   ó@   K  — | j                   j                  «        y ­wr   )r€   rQ   rR   s     r   r   zAsyncCursor.__aexit__@  s   è ø€ Ø�‰×ÑÕùrT   c                 ó^   — t        | j                  |«      }t        |«      rt        |«      ‚|S r   )r*   r€   r]   r^   r_   s      r   rb   zAsyncCursor.__getattr__j  s)   € Ü�t—|‘| TÓ*ˆÜ�DŒ>Ü  Ó&Ð&Øˆr   )NN).r"   r#   r$   r%   r&   r+   r   r   r   r4   r   ÚkeyÚvalueÚitemrB   rQ   ÚfirstÚ	first_dupÚlastÚlast_dupÚprevÚprev_dupÚ
prev_nodupÚnextÚnext_dupÚ
next_nodupÚset_keyÚset_key_dupÚ	set_rangeÚset_range_duprˆ   Úcountr…   Úputmultir†   r‡   r„   ÚgetmultirH   ÚiternextÚiternext_dupÚiternext_nodupÚiterprevÚiterprev_dupÚiterprev_noduprb   r'   r   r   r~   r~   #  sý  „ ñð 2€Ià€Fó,òòñ
 �v—z‘zÓ
"€CÙ˜Ÿ™Ó&€EÙ˜Ÿ™Ó$€Dá  §¡Ó.€EÙ  §¡Ó.€EÙ$ V×%5Ñ%5Ó6€IÙ §¡Ó,€DÙ# F§O¡OÓ4€HÙ §¡Ó,€DÙ# F§O¡OÓ4€HÙ% f×&7Ñ&7Ó8€JÙ §¡Ó,€DÙ# F§O¡OÓ4€HÙ% f×&7Ñ&7Ó8€JÙ" 6§>¡>Ó2€GÙ& v×'9Ñ'9Ó:€KÙ$ V×%5Ñ%5Ó6€IÙ(¨×)=Ñ)=Ó>€MÙ! &§-¡-Ó0€FÙ  §¡Ó.€EÙ
˜vŸz™zÓ
*€CÙ# F§O¡OÓ4€HÙ" 6§>¡>Ó2€GÙ
˜vŸz™zÓ
*€CÙ
˜vŸz™zÓ
*€CÙ# F§O¡OÓ4€Há˜vŸ™Ó/€HÙ" 6×#6Ñ#6Ó7€LÙ$ V×%:Ñ%:Ó;€NÙ˜vŸ™Ó/€HÙ" 6×#6Ñ#6Ó7€LÙ$ V×%:Ñ%:Ó;€Nór   r~   r   )r%   r7   r1   Ú r   r   r   r   r   r4   r>   rB   rH   r   rX   r~   r'   r   r   Ú<module>rª      sc   ðñ*ó  Û ç .Ñ .ó+÷Gñ Gò<ò	ò
ò÷$Jñ J÷ZNñ N÷bKò Kr   