+
    ja                        R t ^ RIt^ RIt^ RIt^RIHt ^RIHt Rt^t	^t
^t^t^t^t^t^t^tRtRtRtRtR	tR
tRtRt]
]]]]]]]]]]]]]]]/t]P7                  4        U Uu/ uF  w  rWbK	  	  upp t^t^t^t^t ^t!^t"^t#^t$^	t%^
t&^t'^t(Rt)]PT                  ! ])4      t+Rt, ! R R4      t-]-t.RR R llt/R R lt0R R lt1R R lt2R R lt3R R R llt4R!R R llt5R# u upp i )"a6  
Dirty Worker Binary Protocol

Binary message framing over Unix sockets, inspired by OpenBSD msgctl/msgsnd.
Replaces JSON protocol for efficient binary data transfer.

Header Format (16 bytes):
+--------+--------+--------+--------+--------+--------+--------+--------+
|  Magic (2B)     | Ver(1) | MType  |        Payload Length (4B)        |
+--------+--------+--------+--------+--------+--------+--------+--------+
|                       Request ID (8 bytes)                            |
+--------+--------+--------+--------+--------+--------+--------+--------+

- Magic: 0x47 0x44 ("GD" for Gunicorn Dirty)
- Version: 0x01
- MType: Message type (REQUEST, RESPONSE, ERROR, CHUNK, END)
- Length: Payload size (big-endian uint32, max 64MB)
- Request ID: uint64 (replaces UUID string)

Payload is TLV-encoded (see tlv.py).
N)DirtyProtocolError)
TLVEncoders   GDrequestresponseerrorchunkendstashstatusmanagez>2sBBIQc                   4  a  ] tR t^bt o Rt]t]t]t]	t
]t]t]t]t]t]t]V 3R lR l4       t]V 3R lR l4       t]R&V 3R lR ll4       t]V 3R	 lR
 l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]V 3R lR l4       t]R'V 3R lR ll4       t ]R(V 3R lR ll4       t!]V 3R lR l4       t"]V 3R lR l4       t#]V 3R lR l4       t$]V 3R lR l4       t%]V 3R lR  l4       t&]V 3R! lR" l4       t']V 3R# lR$ l4       t(R%t)V t*R# ))BinaryProtocolz-Binary message protocol for dirty worker IPC.c                2   < V ^8  d   QhRS[ RS[ RS[ RS[/# )   msg_type
request_idpayload_lengthreturnintbytes)format__classdict__s   "L/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/dirty/protocol.py__annotate__BinaryProtocol.__annotate__s   s)     7 7 7 7c 7e 7    c                N    \         P                  ! \        \        \        V W!4      # )z
Encode the 16-byte message header.

Args:
    msg_type: Message type (MSG_TYPE_REQUEST, etc.)
    request_id: Unique request identifier (uint64)
    payload_length: Length of the TLV-encoded payload

Returns:
    bytes: 16-byte header
)structpackHEADER_FORMATMAGICVERSION)r   r   r   s   &&&r   encode_headerBinaryProtocol.encode_headerr   s      {{=%()7 	7r   c                &   < V ^8  d   QhRS[ RS[/# r   datar   r   tuple)r   r   s   "r   r   r      s     ., .,E .,e .,r   c                   \        V 4      \        8  d!   \        R\        V 4       R\         2V R7      h\        P                  ! \
        V R\         4      w  rr4pV\        8w  d!   \        RV: R\        : 2V R,          R7      hV\        8w  d   \        RV R\         2V R,          R7      hV\        9  d   \        R	VR
 2V R,          R7      hV\        8  d   \        RV R\         R24      hW5V3# )z
Decode the 16-byte message header.

Args:
    data: 16 bytes of header data

Returns:
    tuple: (msg_type, request_id, payload_length)

Raises:
    DirtyProtocolError: If header is invalid
zHeader too short:  bytes, expected raw_dataNzInvalid magic: z, expected :N   NzUnsupported protocol version: zUnknown message type: 0x02xzMessage too large: z bytes (max: ))
lenHEADER_SIZEr   r   unpackr    r!   r"   MSG_TYPE_TO_STRMAX_MESSAGE_SIZE)r'   magicversionr   lengthr   s   &     r   decode_headerBinaryProtocol.decode_header   s    t9{"$$SYK/@N 
 8>}}4-8
4* E>$!%+eY?c 
 g$0	WINc 
 ?*$*8C.9c 
 $$$%fX];K:LAN  V++r   Nc                >   < V ^8  d   QhRS[ RS[RS[RS[RS[RS[/# )r   r   app_pathactionargskwargsr   )r   strr)   dictr   )r   r   s   "r   r   r      s:        3  #  s  " 37 CH r   c           	         RTRTRV'       d   \        V4      M. RT;'       g    / /p\        P                  ! V4      p\        P	                  \
        V \        V4      4      pWv,           # )a  
Encode a request message.

Args:
    request_id: Unique request identifier (uint64)
    app_path: Import path of the dirty app
    action: Action to call on the app
    args: Positional arguments
    kwargs: Keyword arguments

Returns:
    bytes: Complete message (header + payload)
r<   r=   r>   r?   )listr   encoder   r#   MSG_TYPE_REQUESTr1   )r   r<   r=   r>   r?   payload_dictpayloadheaders   &&&&&   r   encode_requestBinaryProtocol.encode_request   sd    " f$DJBfll	
 ##L1--.>
.1'l<r   c                &   < V ^8  d   QhRS[ RS[/# r   r   r   r   )r   r   s   "r   r   r      s        C  E  r   c                    RV/p\         P                  ! V4      p\        P                  \        V \        V4      4      pWC,           # )z
Encode a success response message.

Args:
    request_id: Request identifier this responds to
    result: Result value (must be TLV-serializable)

Returns:
    bytes: Complete message (header + payload)
result)r   rD   r   r#   MSG_TYPE_RESPONSEr1   )r   rN   rF   rG   rH   s   &&   r   encode_responseBinaryProtocol.encode_response   sC     !&)##L1--.?.1'l<r   c                &   < V ^8  d   QhRS[ RS[/# rL   r   )r   r   s   "r   r   r      s            r   c                X   ^RI Hp \        W4      '       d   VP                  4       pM=\        V\        4      '       d   TpM$R\        V4      P                  R\        V4      R/ /pRV/p\        P                  ! V4      p\        P                  \        V \        V4      4      pWe,           # )z
Encode an error response message.

Args:
    request_id: Request identifier this responds to
    error: DirtyError instance, dict, or Exception

Returns:
    bytes: Complete message (header + payload)

DirtyError
error_typemessagedetailsr   )errorsrU   
isinstanceto_dictrA   type__name__r@   r   rD   r   r#   MSG_TYPE_ERRORr1   )r   r   rU   
error_dictrF   rG   rH   s   &&     r   encode_errorBinaryProtocol.encode_error   s     	'e((Jt$$J d5k223u:2J  ,##L1--nj.1'l<r   c                &   < V ^8  d   QhRS[ RS[/# rL   r   )r   r   s   "r   r   r      s          u  r   c                    RV/p\         P                  ! V4      p\        P                  \        V \        V4      4      pWC,           # )z
Encode a chunk message for streaming responses.

Args:
    request_id: Request identifier this chunk belongs to
    data: Chunk data (must be TLV-serializable)

Returns:
    bytes: Complete message (header + payload)
r'   )r   rD   r   r#   MSG_TYPE_CHUNKr1   )r   r'   rF   rG   rH   s   &&   r   encode_chunkBinaryProtocol.encode_chunk   sA     ~##L1--nj.1'l<r   c                &   < V ^8  d   QhRS[ RS[/# rL   r   )r   r   s   "r   r   r     s      s u r   c                <    \         P                  \        V ^ 4      pV# )z
Encode an end-of-stream message.

Args:
    request_id: Request identifier this ends

Returns:
    bytes: Complete message (header + empty payload)
)r   r#   MSG_TYPE_ENDr   rH   s   & r   
encode_endBinaryProtocol.encode_end  s      --lJJr   c                &   < V ^8  d   QhRS[ RS[/# rL   r   )r   r   s   "r   r   r   !  s      # % r   c                <    \         P                  \        V ^ 4      pV# )z
Encode a status query message.

Args:
    request_id: Request identifier

Returns:
    bytes: Complete message (header + empty payload)
)r   r#   MSG_TYPE_STATUSrj   s   & r   encode_statusBinaryProtocol.encode_status   s      --oz1Mr   c                2   < V ^8  d   QhRS[ RS[ RS[ RS[/# )r   r   opcountr   r   )r   r   s   "r   r   r   0  s)        #  3  s  5  r   c                    RVRV/p\         P                  ! V4      p\        P                  \        V \        V4      4      pWT,           # )z
Encode a worker management message.

Args:
    request_id: Request identifier
    op: Management operation (MANAGE_OP_ADD or MANAGE_OP_REMOVE)
    count: Number of workers to add/remove

Returns:
    bytes: Complete message (header + payload)
rs   rt   )r   rD   r   r#   MSG_TYPE_MANAGEr1   )r   rs   rt   rF   rG   rH   s   &&&   r   encode_manageBinaryProtocol.encode_manage/  sK     "U
 ##L1--oz.1'l<r   c                2   < V ^8  d   QhRS[ RS[ RS[RS[/# )r   r   rs   tabler   )r   r@   r   )r   r   s   "r   r   r   F  s*          #  c  <A r   c                    RVRV/pVe   W6R&   Ve   WFR&   Ve   WVR&   \         P                  ! V4      p\        P                  \        V \        V4      4      pW,           # )ag  
Encode a stash operation message.

Args:
    request_id: Unique request identifier (uint64)
    op: Stash operation code (STASH_OP_*)
    table: Table name
    key: Optional key for put/get/delete operations
    value: Optional value for put operation
    pattern: Optional pattern for keys operation

Returns:
    bytes: Complete message (header + payload)
rs   rz   keyvaluepattern)r   rD   r   r#   MSG_TYPE_STASHr1   )	r   rs   rz   r|   r}   r~   rF   rG   rH   s	   &&&&&&   r   encode_stashBinaryProtocol.encode_stashE  st    $ "U
 ?"%$)!&-###L1--nj.1'l<r   c                &   < V ^8  d   QhRS[ RS[/# r&   r(   )r   r   s   "r   r   r   g  s     *6 *6U *6u *6r   c                   \         P                  V 4      w  rp\        V 4      \        V,           8  d/   \	        R\        V,            R\        V 4       2V R,          R7      hV^ 8X  d   / pM+V \        \        V,            p \
        P                  ! V4      p\        V,          pWrV3#   \         d    h \         d   p\	        RT 2TR,          R7      hRp?ii ; i)aH  
Decode a complete message (header + payload).

Args:
    data: Complete message bytes

Returns:
    tuple: (msg_type_str, request_id, payload_dict)
           msg_type_str is the string name (e.g., "request")
           payload_dict is the decoded TLV payload as a dict

Raises:
    DirtyProtocolError: If message is malformed
zIncomplete message: expected z bytes, got N2   Nr,   Failed to decode TLV payload: N)	r   r9   r1   r2   r   r   decode_full	Exceptionr4   )r'   r   r   r8   rF   payload_dataemsg_type_strs   &       r   decode_messageBinaryProtocol.decode_messagef  s      (6'C'CD'I$ft9{V++$/f0D/E F4yk#c  Q;LK&,@AL)55lC 'x055 &  (4QC8)#. s   B( (C=C>CCc                :   < V ^8  d   QhRS[ P                  RS[/# )r   readerr   )asyncioStreamReaderrA   )r   r   s   "r   r   r     s!     9 9)=)= 9$ 9r   c                  "    V P                  \        4      G Rj  xL
 p\        P                  T4      w  r4pT^ 8  d3    T P                  T4      G Rj  xL
 p \        P                  ! T4      pM/ p\        T,          pRTR	T/p	T	P                  T4       T	#  L}  \        P                   dU   p\	        TP
                  4      ^ 8X  d   h \        R\	        TP
                  4       R\         2TP
                  R7      hRp?ii ; i L  \        P                   d6   p\        R\	        TP
                  4       RT 2TP
                  R7      hRp?ii ; i  \         d    h \         d   p\        RT 2TR,          R7      hRp?ii ; i5i)
a(  
Read a complete binary message from async stream.

Args:
    reader: asyncio StreamReader

Returns:
    dict: Message dict with 'type', 'id', and payload fields

Raises:
    DirtyProtocolError: If read fails or message is malformed
    asyncio.IncompleteReadError: If connection closed mid-read
NzIncomplete header: got r+   r,   zIncomplete payload: got r   r   r\   id)readexactlyr2   r   IncompleteReadErrorr1   partialr   r   r9   r   r   r   r4   update)
r   rH   r   r   r   r8   r   rF   r   rN   s
   &         r   read_message_async!BinaryProtocol.read_message_async  s     
	!--k::F (6'C'CF'K$f A:%+%7%7%??)55lC L 'x0,j9l#S ;** 	199~"$)#aii.)9 :'=* 		  @.. (.s199~.> ?  &x)YY  &  (4QC8)#. s   FB BB FD
 DD
 E 1)FB D1AD  DFD
 
E0EEFF	,F	-FF		Fc                >   < V ^8  d   QhRS[ P                  RS[RR/# )r   writerrW   r   N)r   StreamWriterrA   )r   r   s   "r   r   r     s*      '*>*> +/48r   c                   "   \         P                  V4      pV P                  V4       V P                  4       G Rj  xL
  R#  L5i)a  
Write a message to async stream.

Accepts dict format for backwards compatibility.

Args:
    writer: asyncio StreamWriter
    message: Message dict with 'type', 'id', and payload fields

Raises:
    DirtyProtocolError: If encoding fails
    ConnectionError: If write fails
N)r   _encode_from_dictwritedrain)r   rW   r'   s   && r   write_message_async"BinaryProtocol.write_message_async  s2       //8Tllns   :AAAc                @   < V ^8  d   QhRS[ P                   RS[RS[/# )r   socknr   )socketr   r   )r   r   s   "r   r   r     s&      FMM c e r   c                    Rp\        V4      V8  dk   V P                  V\        V4      ,
          4      pV'       g8   \        V4      ^ 8X  d   \        R4      h\        R\        V4       RV 2VR7      hW#,          pKz  V# )z
Receive exactly n bytes from a socket.

Args:
    sock: Socket to read from
    n: Number of bytes to read

Returns:
    bytes: Received data

Raises:
    DirtyProtocolError: If read fails or connection closed
r   zConnection closedzConnection closed after r+   r,   )r1   recvr   )r   r   r'   r   s   &&  r   _recv_exactlyBinaryProtocol._recv_exactly  sw     $i!mIIa#d)m,Et9>,-@AA(.s4yk9J1#N!  MDr   c                :   < V ^8  d   QhRS[ P                   RS[/# )r   r   r   r   rA   )r   r   s   "r   r   r     s     % %6== %T %r   c                   \         P                  V \        4      p\         P                  V4      w  r#pV^ 8  d.   \         P                  W4      p \        P
                  ! V4      pM/ p\        V,          pRVRV/p	V	P                  V4       V	#   \         d    h \         d   p\        RT 2TR,          R7      hRp?ii ; i)z
Read a complete message from socket (sync).

Args:
    sock: Socket to read from

Returns:
    dict: Message dict with 'type', 'id', and payload fields

Raises:
    DirtyProtocolError: If read fails or message is malformed
r   r   r,   Nr\   r   )
r   r   r2   r9   r   r   r   r   r4   r   )
r   rH   r   r   r8   r   rF   r   r   rN   s
   &         r   read_messageBinaryProtocol.read_message  s      --dK@'5'C'CF'K$f A:)77EL)55lC L 'x0,j9l# &  (4QC8)#. s   B C$C%B<<Cc                >   < V ^8  d   QhRS[ P                   RS[RR/# )r   r   rW   r   Nr   )r   r   s   "r   r   r   0  s&      FMM D T r   c                R    \         P                  V4      pV P                  V4       R# )z
Write a message to socket (sync).

Args:
    sock: Socket to write to
    message: Message dict with 'type', 'id', and payload fields

Raises:
    DirtyProtocolError: If encoding fails
    OSError: If write fails
N)r   r   sendall)r   rW   r'   s   && r   write_messageBinaryProtocol.write_message/  s      //8Tr   c                &   < V ^8  d   QhRS[ RS[/# )r   rW   r   )rA   r   )r   r   s   "r   r   r   @  s#     CL CL4 CLE CLr   c           
        V P                  R4      pV P                  R^ 4      p\        V\        4      '       d   \        V4      R,          p\        P                  V4      pVf   \        RV 24      hV\        8X  dX   \        P                  VV P                  RR4      V P                  RR4      V P                  R4      V P                  R	4      4      # V\        8X  d&   \        P                  VV P                  R
4      4      # V\        8X  d'   \        P                  VV P                  R/ 4      4      # V\        8X  d&   \        P                  VV P                  R4      4      # V\        8X  d   \        P!                  V4      # V\"        8X  dg   \        P%                  VV P                  R4      V P                  RR4      V P                  R4      V P                  R4      V P                  R4      4      # V\&        8X  d   \        P)                  V4      # V\*        8X  d7   \        P-                  VV P                  R4      V P                  R^4      4      # \        RV 24      h)z
Encode a message dict to binary format.

Supports the old dict-based API for backwards compatibility.

Args:
    message: Message dict with 'type', 'id', and payload fields

Returns:
    bytes: Complete encoded message
r\   r   l    zUnknown message type: r<    r=   r>   r?   rN   r   r'   rs   rz   r|   r}   r~   rt   zUnhandled message type: )getrZ   r@   hashMSG_TYPE_FROM_STRr   rE   r   rI   rO   rP   r^   r`   rd   re   ri   rk   r   r   ro   rp   rv   rw   )rW   r   r   r   s   &   r   r    BinaryProtocol._encode_from_dict?  s#    {{6*[[q)
 j#&&j),>>J$((6$'=l^%LMM''!00J+Hb)F#H%  **!11H%  '!..GR(  '!..F#  %!,,Z88'!..D!GR(E"G$I&  (!//
;;(!//D!GQ'  %'?z%JKKr    NN   NNN)+r]   
__module____qualname____firstlineno____doc__r2   r5   MSG_TYPE_REQUEST_STRrE   MSG_TYPE_RESPONSE_STRrO   MSG_TYPE_ERROR_STRr^   MSG_TYPE_CHUNK_STRrd   MSG_TYPE_END_STRri   MSG_TYPE_STASH_STRr   MSG_TYPE_STATUS_STRro   MSG_TYPE_MANAGE_STRrv   staticmethodr#   r9   rI   rP   r`   re   rk   rp   rw   r   r   r   r   r   r   r   r   __static_attributes____classdictcell__)r   s   @r   r   r   b   s    7 K'+-'N'N#L'N)O)O7 7 ., .,`      4    "    <    "          *      @ *6 *6` 9 9v  .  6 % %N   CL CLr   r   c          
      T    V ^8  d   QhR\         R\         R\        R\        R\        /# )r   r<   r=   r>   r?   r   )r@   r)   rA   )r   s   "r   r   r     s2      s C -1=Ar   c                t    R\         P                  RT RTRTRV'       d   \        V4      M. RT;'       g    / /# )a-  
Build a request message dict.

Args:
    request_id: Unique request identifier (int or str)
    app_path: Import path of the dirty app (e.g., 'myapp.ml:MLApp')
    action: Action to call on the app
    args: Positional arguments
    kwargs: Keyword arguments

Returns:
    dict: Request message dict
r\   r   r<   r=   r>   r?   )DirtyProtocolrE   rC   )r   r<   r=   r>   r?   s   &&&&&r   make_requestr     s@      	..jH&dT
&,,B r   c                $    V ^8  d   QhR\         /# r   r   rA   )r   s   "r   r   r     s       r   c                .    R\         P                  RV RV/# )z
Build a success response message dict.

Args:
    request_id: Request identifier this responds to
    result: Result value

Returns:
    dict: Response message dict
r\   r   rN   )r   rO   )r   rN   s   &&r   make_responser     s#     	//j& r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r     s      d r   c                    ^RI Hp \        W4      '       d   VP                  4       pM=\        V\        4      '       d   TpM$R\        V4      P                  R\        V4      R/ /pR\        P                  RV RV/# )z
Build an error response message dict.

Args:
    request_id: Request identifier this responds to
    error: DirtyError instance or dict with error info

Returns:
    dict: Error response message dict
rT   rV   rW   rX   r\   r   r   )
rY   rU   rZ   r[   rA   r\   r]   r@   r   r^   )r   r   rU   r_   s   &&  r   make_error_responser     sv     #%$$]]_
	E4	 	 
 $u+..s5zr

 	,,j r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r     s      D r   c                .    R\         P                  RV RV/# )z
Build a chunk message dict for streaming responses.

Args:
    request_id: Request identifier this chunk belongs to
    data: Chunk data

Returns:
    dict: Chunk message dict
r\   r   r'   )r   rd   )r   r'   s   &&r   make_chunk_messager     s#     	,,j r   c                $    V ^8  d   QhR\         /# r   r   )r   s   "r   r   r     s      D r   c                *    R\         P                  RV /# )z
Build an end-of-stream message dict.

Args:
    request_id: Request identifier this ends

Returns:
    dict: End message dict
r\   r   )r   ri   )r   s   &r   make_end_messager     s     	**j r   c                <    V ^8  d   QhR\         R\        R\        /# )r   rs   rz   r   )r   r@   rA   )r   s   "r   r   r     s"      s 3 >Br   c                f    R\         P                  RV RVRV/pVe   W6R&   Ve   WFR&   Ve   WVR&   V# )a]  
Build a stash operation message dict.

Args:
    request_id: Unique request identifier (int or str)
    op: Stash operation code (STASH_OP_*)
    table: Table name
    key: Optional key for put/get/delete operations
    value: Optional value for put operation
    pattern: Optional pattern for keys operation

Returns:
    dict: Stash message dict
r\   r   rs   rz   r|   r}   r~   )r   r   )r   rs   rz   r|   r}   r~   msgs   &&&&&& r   make_stash_messager     sR    " 	,,jb	C E
G IJr   c                <    V ^8  d   QhR\         R\         R\        /# )r   rs   rt   r   )r   rA   )r   s   "r   r   r     s!       C  r   c                2    R\         P                  RV RVRV/# )z
Build a worker management message dict.

Args:
    request_id: Unique request identifier (int or str)
    op: Management operation (MANAGE_OP_ADD or MANAGE_OP_REMOVE)
    count: Number of workers to add/remove

Returns:
    dict: Manage message dict
r\   r   rs   rt   )r   rv   )r   rs   rt   s   &&&r   make_manage_messager     s(     	--jb	 r   i   r   r   r   )6r   r   r   r   rY   r   tlvr   r!   r"   rE   rO   r^   rd   ri   r   ro   rv   r   r   r   r   r   r   r   r   r4   itemsr   STASH_OP_PUTSTASH_OP_GETSTASH_OP_DELETESTASH_OP_KEYSSTASH_OP_CLEARSTASH_OP_INFOSTASH_OP_ENSURESTASH_OP_DELETE_TABLESTASH_OP_TABLESSTASH_OP_EXISTSMANAGE_OP_ADDMANAGE_OP_REMOVEr    calcsizer2   r5   r   r   r   r   r   r   r   r   r   )kvs   00r   <module>r      s  
,    &  	
    ! "        *,&&"&((	 '6&;&;&=>&=daQT&=>      oom, $ aL aLR 2$<$ > c ?s   $C!