
    i?1iS                        d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZ d dlmZmZ  G d de      Z G d	 d
e      Zy)    )annotations)Any)"filter_out_none_values_recursivelyignore_docsparse_date_fields)ApifyApiError)catch_not_found_or_throw
pluck_data)ResourceClientResourceClientAsyncc                      e Zd ZdZedd	 	 	 	 	 	 	 	 	 d fd       ZddZddddZddZdd	dd
Z	dd	ddZ
ddddZddZddddZddZdd	 	 	 	 	 	 	 	 	 d dZddd!dZdd	 	 	 	 	 	 	 d"dZd#dZddd	 	 	 	 	 	 	 d$dZ xZS )%RequestQueueClientz3Sub-client for manipulating a single request queue.N
client_keyc               Z    |j                  dd      }t        |   |d|i| || _        y)zInitialize the RequestQueueClient.

        Args:
            client_key (str, optional): A unique identifier of the client accessing the request queue
        resource_pathrequest-queuesNpopsuper__init__r   selfr   argskwargsr   	__class__s        }/home/www/therecruiter.miabetepe.com/venv/lib/python3.12/site-packages/apify_client/clients/resource_clients/request_queue.pyr   zRequestQueueClient.__init__   4     

?4DE$FmFvF$    c                "    | j                         S )Retrieve the request queue.

        https://docs.apify.com/api/v2#/reference/request-queues/queue/get-request-queue

        Returns:
            dict, optional: The retrieved request queue, or None, if it does not exist
        _getr   s    r   getzRequestQueueClient.get   s     yy{r   namec               >    d|i}| j                  t        |            S )&  Update the request queue with specified fields.

        https://docs.apify.com/api/v2#/reference/request-queues/queue/update-request-queue

        Args:
            name (str, optional): The new name for the request queue

        Returns:
            dict: The updated request queue
        r'   _updater   r   r'   updated_fieldss      r   updatezRequestQueueClient.update)   s'     D
 ||>~NOOr   c                "    | j                         S )~Delete the request queue.

        https://docs.apify.com/api/v2#/reference/request-queues/queue/delete-request-queue
        _deleter$   s    r   deletezRequestQueueClient.delete:   s    
 ||~r   limitc                   | j                  || j                        }| j                  j                  | j	                  d      d|      }t        t        |j                                     S )V  Retrieve a given number of requests from the beginning of the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/queue-head/get-head

        Args:
            limit (int, optional): How many requests to retrieve

        Returns:
            dict: The desired number of requests from the beginning of the queue.
        r5   	clientKeyheadGETurlmethodparams_paramsr   http_clientcall_urlr   r
   jsonr   r5   request_paramsresponses       r   	list_headzRequestQueueClient.list_headA   s_     ET__M##((		&!! ) 
 !HMMO!<==r   c                   | j                  ||| j                        }| j                  j                  | j	                  d      d|      }t        t        |j                                     S )  Retrieve a given number of unlocked requests from the beginning of the queue and lock them for a given time.

        https://docs.apify.com/api/v2#/reference/request-queues/queue-head-with-locks/get-head-and-lock

        Args:
            lock_secs (int): How long the requests will be locked for, in seconds
            limit (int, optional): How many requests to retrieve


        Returns:
            dict: The desired number of locked requests from the beginning of the queue.
        lockSecsr5   r9   	head/lockPOSTr<   r@   r   	lock_secsr5   rG   rH   s        r   list_and_lock_headz%RequestQueueClient.list_and_lock_headV   sd     yQUQ`Q`a##((		+&! ) 
 !HMMO!<==r   	forefrontc                   | j                  || j                        }| j                  j                  | j	                  d      d||      }t        t        |j                                     S )m  Add a request to the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/request-collection/add-request

        Args:
            request (dict): The request to add to the queue
            forefront (bool, optional): Whether to add the request to the head or the end of the queue

        Returns:
            dict: The added request.
        rT   r9   requestsrO   r=   r>   rE   r?   r@   r   requestrT   rG   rH   s        r   add_requestzRequestQueueClient.add_requestm   sb     	T__U##((		*%!	 ) 
 !HMMO!<==r   c                   	 | j                   j                  | j                  d|       d| j                               }t	        t        |j                                     S # t        $ r}t        |       Y d}~yd}~ww xY wa.  Retrieve a request from the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/request/get-request

        Args:
            request_id (str): ID of the request to retrieve

        Returns:
            dict, optional: The retrieved request, or None, if it did not exist.
        	requests/r;   r<   N	rB   rC   rD   rA   r   r
   rE   r   r	   r   
request_idrH   excs       r   get_requestzRequestQueueClient.get_request   sw    		*'',,II	*67||~ - H
 %Z%@AA 	*$S))	*s   AA" "	B +A;;B c                   |d   }| j                  || j                        }| j                  j                  | j	                  d|       d||      }t        t        |j                                     S )j  Update a request in the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/request/update-request

        Args:
            request (dict): The updated request
            forefront (bool, optional): Whether to put the updated request in the beginning or the end of the queue

        Returns:
            dict: The updated request
        idrW   r_   PUTrY   r@   r   r[   rT   rb   rG   rH   s         r   update_requestz!RequestQueueClient.update_request   sr     T]
	T__U##((		Ij\23!	 ) 
 !HMMO!<==r   c                    | j                  | j                        }| j                  j                  | j	                  d|       d|       yzDelete a request from the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/request/delete-request

        Args:
            request_id (str): ID of the request to delete.
        r9   r_   DELETEr<   NrA   r   rB   rC   rD   r   rb   rG   s      r   delete_requestz!RequestQueueClient.delete_request   sR     oo & 
 			Ij\23! 	 	
r   c                   | j                  | j                  ||      }| j                  j                  | j	                  d| d      d|      }t        t        |j                                     S )  Prolong the lock on a request.

        https://docs.apify.com/api/v2#/reference/request-queues/request-lock/prolong-request-lock

        Args:
            request_id (str): ID of the request to prolong the lock
            forefront (bool, optional): Whether to put the request in the beginning or the end of the queue after lock expires
            lock_secs (int): By how much to prolong the lock, in seconds
        r9   rT   rM   r_   /lockrh   r<   r@   r   rb   rT   rQ   rG   rH   s         r   prolong_request_lockz'RequestQueueClient.prolong_request_lock   sk      9_hi##((		Ij\78! ) 
 !HMMO!<==r   c                   | j                  | j                  |      }| j                  j                  | j	                  d| d      d|       ya`  Delete the lock on a request.

        https://docs.apify.com/api/v2#/reference/request-queues/request-lock/delete-request-lock

        Args:
            request_id (str): ID of the request to delete the lock
            forefront (bool, optional): Whether to put the request in the beginning or the end of the queue after the lock is deleted
        r9   rT   r_   ru   rn   r<   Nro   r   rb   rT   rG   s       r   delete_request_lockz&RequestQueueClient.delete_request_lock   sN     9U		Ij\78! 	 	
r   c                   | j                  | j                  |      }| j                  j                  | j	                  d      d||      }t        t        |j                                     S )@  Add requests to the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/add-requests

        Args:
            requests (list[dict]): list of the requests to add
            forefront (bool, optional): Whether to add the requests to the head or the end of the queue
        rz   requests/batchrO   r=   r>   r?   rE   r@   r   rX   rT   rG   rH   s        r   batch_add_requestsz%RequestQueueClient.batch_add_requests   sc     9U##((		*+!	 ) 
 !HMMO!<==r   c                    | j                  | j                        }| j                  j                  | j	                  d      d||      }t        t        |j                                     S )Delete given requests from the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/batch-request-operations/delete-requests

        Args:
            requests (list[dict]): list of the requests to delete
        rm   r   rn   r   r@   r   rX   rG   rH   s       r   batch_delete_requestsz(RequestQueueClient.batch_delete_requests
  sa     @##((		*+!	 ) 
 !HMMO!<==r   r5   exclusive_start_idc                   | j                  ||| j                        }| j                  j                  | j	                  d      d|      }t        t        |j                                     S )J  List requests in the queue.

        https://docs.apify.com/api/v2#/reference/request-queues/request-collection/list-requests

        Args:
            limit (int, optional): How many requests to retrieve
            exclusive_start_id (str, optional): All requests up to this one (including) are skipped from the result
        r5   r   r9   rX   r;   r<   r@   r   r5   r   rG   rH   s        r   list_requestsz RequestQueueClient.list_requests  se     EFXdhdsdst##((		*%! ) 
 !HMMO!<==r   )
r   r   r   r   r   
str | Noner   r   returnNone)r   r   r   dict | None)r   r   r'   r   r   dict)r   r   r   r   )r   r   r5   
int | Noner   r   )r   r   rQ   intr5   r   r   r   )r   r   r[   r   rT   bool | Noner   r   )r   r   rb   strr   r   )r   r   rb   r   r   r   )
r   r   rb   r   rT   r   rQ   r   r   r   )r   r   rb   r   rT   r   r   r   )r   r   rX   
list[dict]rT   r   r   r   )r   r   rX   r   r   r   )r   r   r5   r   r   r   r   r   __name__
__module____qualname____doc__r   r   r%   r.   r3   rI   rR   r\   rd   rj   rq   rw   r|   r   r   r   __classcell__r   s   @r   r   r      sF   = "&% %% % 	%
 
% % @D P" DH >* ]a >. Z^ >.0 ]a >2
, "&	> >> 	>
 > 
>4 dh 
* "&	> >> 	>
 
>0>, !)-	> > > '	>
 
>r   r   c                  *    e Zd ZdZedd	 	 	 	 	 	 	 	 	 d fd       ZddZddddZddZdd	dd
Z	dd	ddZ
ddddZddZddddZddZdd	 	 	 	 	 	 	 	 	 d dZdd	 	 	 	 	 	 	 d!dZdd	 	 	 	 	 	 	 d"dZd#dZddd	 	 	 	 	 	 	 d$dZ xZS )%RequestQueueClientAsyncz9Async sub-client for manipulating a single request queue.Nr   c               Z    |j                  dd      }t        |   |d|i| || _        y)zInitialize the RequestQueueClientAsync.

        Args:
            client_key (str, optional): A unique identifier of the client accessing the request queue
        r   r   Nr   r   s        r   r   z RequestQueueClientAsync.__init__9  r   r   c                >   K   | j                          d{   S 7 w)r!   Nr"   r$   s    r   r%   zRequestQueueClientAsync.getI  s      YY[      r&   c               Z   K   d|i}| j                  t        |             d{   S 7 w)r)   r'   Nr*   r,   s      r   r.   zRequestQueueClientAsync.updateS  s1      D
 \\"D^"TUUUUs   "+)+c                >   K   | j                          d{   S 7 w)r0   Nr1   r$   s    r   r3   zRequestQueueClientAsync.deleted  s     
 \\^###r   r4   c                  K   | j                  || j                        }| j                  j                  | j	                  d      d|       d{   }t        t        |j                                     S 7 &w)r7   r8   r:   r;   r<   Nr@   rF   s       r   rI   z!RequestQueueClientAsync.list_headk  sm      ET__M))..		&!! / 
 
 !HMMO!<==
   AA9A7'A9c                  K   | j                  ||| j                        }| j                  j                  | j	                  d      d|       d{   }t        t        |j                                     S 7 &w)rK   rL   rN   rO   r<   Nr@   rP   s        r   rR   z*RequestQueueClientAsync.list_and_lock_head  sr      yQUQ`Q`a))..		+&! / 
 
 !HMMO!<==
   AA:A8'A:rS   c                  K   | j                  || j                        }| j                  j                  | j	                  d      d||       d{   }t        t        |j                                     S 7 &w)rV   rW   rX   rO   rY   Nr@   rZ   s        r   r\   z#RequestQueueClientAsync.add_request  sp      	T__U))..		*%!	 / 
 
 !HMMO!<==
r   c                "  K   	 | j                   j                  | j                  d|       d| j                                d{   }t	        t        |j                                     S 7 &# t        $ r}t        |       Y d}~yd}~ww xY wwr^   r`   ra   s       r   rd   z#RequestQueueClientAsync.get_request  s     		*!--22II	*67||~ 3  H
 %Z%@AA  	*$S))	*sA   BAA. A,%A. +B,A. .	B7BBBBc                 K   |d   }| j                  || j                        }| j                  j                  | j	                  d|       d||       d{   }t        t        |j                                     S 7 &w)rf   rg   rW   r_   rh   rY   Nr@   ri   s         r   rj   z&RequestQueueClientAsync.update_request  s      T]
	T__U))..		Ij\23!	 / 
 
 !HMMO!<==
s   ABB 'Bc                   K   | j                  | j                        }| j                  j                  | j	                  d|       d|       d{    y7 wrl   ro   rp   s      r   rq   z&RequestQueueClientAsync.delete_request  sX      @##		Ij\23! $ 
 	
 	
s   AAAAc                  K   | j                  | j                  ||      }| j                  j                  | j	                  d| d      d|       d{   }t        t        |j                                     S 7 &w)rs   rt   r_   ru   rh   r<   Nr@   rv   s         r   rw   z,RequestQueueClientAsync.prolong_request_lock  sy       9_hi))..		Ij\78! / 
 
 !HMMO!<==
s   AA>A<'A>c                  K   | j                  | j                  |      }| j                  j                  | j	                  d| d      d|       d{    y7 wry   ro   r{   s       r   r|   z+RequestQueueClientAsync.delete_request_lock	  s\      9U##		Ij\78! $ 
 	
 	
s   AAAAc                  K   | j                  | j                  |      }| j                  j                  | j	                  d      d||       d{   }t        t        |j                                     S 7 &w)r~   rz   r   rO   r   Nr@   r   s        r   r   z*RequestQueueClientAsync.batch_add_requests  sq      9U))..		*+!	 / 
 
 !HMMO!<==
r   c                   K   | j                  | j                        }| j                  j                  | j	                  d      d||       d{   }t        t        |j                                     S 7 &w)r   rm   r   rn   r   Nr@   r   s       r   r   z-RequestQueueClientAsync.batch_delete_requests7  so      @))..		*+!	 / 
 
 !HMMO!<==
r   r   c                  K   | j                  ||| j                        }| j                  j                  | j	                  d      d|       d{   }t        t        |j                                     S 7 &w)r   r   rX   r;   r<   Nr@   r   s        r   r   z%RequestQueueClientAsync.list_requestsI  ss      EFXdhdsdst))..		*%! / 
 
 !HMMO!<==
r   )
r   r   r   r   r   r   r   r   r   r   )r   r   r   r   )r   r   r'   r   r   r   )r   r   r   r   )r   r   r5   r   r   r   )r   r   rQ   r   r5   r   r   r   )r   r   r[   r   rT   r   r   r   )r   r   rb   r   r   r   )r   r   rb   r   r   r   )
r   r   rb   r   rT   r   rQ   r   r   r   )r   r   rb   r   rT   r   r   r   )r   r   rX   r   rT   r   r   r   )r   r   rX   r   r   r   )r   r   r5   r   r   r   r   r   r   r   s   @r   r   r   6  sh   C "&%%%% % 	%
 
% %! KO V"$ OS >* hl >. ei >.0 hl >2
( "&	>%>> 	>
 > 
>< "&	
%

 	

 

4 "&	>%>> 	>
 
>0>* !)-	>%> > '	>
 
>r   r   N)
__future__r   typingr   apify_shared.utilsr   r   r   apify_client._errorsr   apify_client._utilsr	   r
   apify_client.clients.baser   r   r   r    r   r   <module>r      s8    "  a a . D Ig> g>T	i>1 i>r   