o
    'h*                     @  s  U d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ ddlmZ ercdd	lm Z  dd
l!m"Z" ddl#m$Z$ e%ddgZ&de'd< e%g de&B Z(de'd< e(e%g dB Z)de'd< dZ*de'd< dZ+de'd< h dZ,de'd< dTd d!Z-	dUdVd'd(Z.dWd+d,Z/dXd1d2Z0		3dYdZd<d=Z1d[dAdBZ2d\dDdEZ3d]dIdJZ4d^dKdLZ5d_dPdQZ6d`dRdSZ7dS )azCBits and pieces used by the driver that don't really fit elsewhere.    )annotationsN)abc)	TYPE_CHECKINGAny	ContainerIterableMappingNoReturnOptionalSequenceUnion)	ASCENDING)	CursorNotFoundDuplicateKeyErrorExecutionTimeoutNotPrimaryErrorOperationFailureWriteConcernError
WriteErrorWTimeoutError_wtimeout_error)HelloCompat)_Hint)
_IndexList)_DocumentOutiP-  [   	frozenset_SHUTDOWN_CODES)iJ'  i{'  i{4  iR-  i|4     _NOT_PRIMARY_CODES)      Y   i)#  i     _RETRYABLE_ERROR_CODESi  int_REAUTHENTICATION_REQUIRED_CODE   _AUTHENTICATION_FAILURE_CODE>	   copydbgetnonce	saslstart
createuser
updateuserauthenticatesaslcontinuecopydbgetnoncecopydbsaslstartset_SENSITIVE_COMMANDSkeysr   returnstrc                 C  s   d dd | D S )z9Generate an index name from the set of fields it is over._c                 S  s   g | ]}d j | qS )z{}_{})format).0item r;   R/var/www/html/olx_land/venv/lib/python3.10/site-packages/pymongo/helpers_shared.py
<listcomp>q   s    z#_gen_index_name.<locals>.<listcomp>)join)r4   r;   r;   r<   _gen_index_nameo   s   r?   key_or_listr   	directionOptional[Union[int, str]]8Sequence[tuple[str, Union[int, str, Mapping[str, Any]]]]c                 C  s   |durt | tstdt|  | |fgS t | tr!| tfgS t | tjr+t| S t | tjr7t| 	 S t | tt
fsGtdt|  g }| D ]}t |trV|tf}|| qK|S )zHelper to generate a list of (key, direction) pairs.

    Takes such a list, or a single key, or a single key and direction.
    Nz'Expected a string and a direction, not zKif no direction is specified, key_or_list must be an instance of list, not )
isinstancer6   	TypeErrortyper   r   	ItemsViewlistr   itemstupleappend)r@   rA   valuesr:   r;   r;   r<   _index_listt   s(   




rM   
index_listdict[str, Any]c                 C  s   t | tttjfstdt|  t| stdi }t | tjr5| D ]}| | }t	|| |||< q#|S | D ]}t |t
rB|tf}|\}}t	|| |||< q7|S )zbHelper to generate an index specifying document.

    Takes a list of (key, direction) pairs.
    z@must use a dictionary or a list of (key, direction) pairs, not: zkey_or_list must not be empty)rD   rH   rJ   r   r   rE   reprlen
ValueError_validate_index_key_pairr6   r   )rN   indexkeyvaluer:   r;   r;   r<   _index_document   s(   





rW   rU   r   rV   Nonec                 C  sD   t | tstdt|  t |tttjfs tdt| d S )Nz<first item in each key pair must be an instance of str, not zasecond item in each key pair must be 1, -1, '2d', or another valid MongoDB index specifier., not )rD   r6   rE   rF   r%   r   r   )rU   rV   r;   r;   r<   rS      s   
rS   Fresponser   max_wire_versionOptional[int]allowable_errors$Optional[Container[Union[int, str]]]parse_write_concern_errorboolc           
      C  s`  d| vrt | d| d| ||r-d| v r-| d }| d}|r)|d|i t| | d r3dS | }d| v rP| d  D ]}|drO|dsO|} nq?|d }|d}	|rl|	durf|	|v redS n||v rldS |	durz|	tv ryt|| ntj|v sd	|v rt|| |	d
v rt	||	| ||	dkrt
||	| ||	dkrt||	| |t ||	| |)z+Check the response to a command for errors.okz$errcodewriteConcernErrorerrorLabelsNrawerrmsgznode is recovering)*  i*  i&1  2   +   )r   getupdate_raise_write_concern_errorrL   r   r   r   LEGACY_ERRORr   r   r   )
rY   rZ   r\   r^   _error_labelsdetailsshardre   ra   r;   r;   r<   _check_command_response   sX   



rq   write_errors	list[Any]r	   c                 C  s@   | d }| ddkrt| dd|t| d| d|)Nra   rf   re   )ri   r   r   )rr   errorr;   r;   r<   _raise_last_write_error   s   rv   ru   c                 C  s8   t | rt| d| d| t| d| d| )Nre   ra   )r   r   ri   r   )ru   r;   r;   r<   rk     s   rk   resultMapping[str, Any]Optional[Mapping[str, Any]]c                 C  s0   |  d}|r|  d}|r| }||d< |S )z%Return the writeConcernError or None.rb   rc   )ri   copy)rw   wceerror_labelsr;   r;   r<   _get_wce_doc  s   

r}   c                 C  s2   |  d}|rt| t| }|rt| dS dS )z?Backward compatibility helper for write command error handling.writeErrorsN)ri   rv   r}   rk   )rw   rr   r{   r;   r;   r<   _check_write_command_response  s   
r   fields'Union[Mapping[str, Any], Iterable[str]]option_namec                 C  s\   t | tjr| S t | tjtjfr'tdd | D s!t| dt| dS t| d)zTakes a sequence of field names and returns a matching dictionary.

    ["a", "b"] becomes {"a": 1, "b": 1}

    and

    ["a.b.c", "d", "a.c"] becomes {"a.b.c": 1, "d": 1, "a.c": 1}
    c                 s  s    | ]}t |tV  qd S N)rD   r6   )r9   fieldr;   r;   r<   	<genexpr>6  s    z'_fields_list_to_dict.<locals>.<genexpr>z5 must be a list of key names, each an instance of str   z' must be a mapping or list of key names)	rD   r   r   r   SetallrE   dictfromkeys)r   r   r;   r;   r<   _fields_list_to_dict'  s   r   c                  C  s\   t jr,t  } z"zt| d | d | d dt j W W ~ dS  ty)   Y W ~ dS w ~ w dS )z1Print exceptions raised by subscribers to stderr.r   r      N)sysstderrexc_info	tracebackprint_exceptionOSError)einfor;   r;   r<   _handle_exception=  s   $r   )r4   r   r5   r6   r   )r@   r   rA   rB   r5   rC   )rN   r   r5   rO   )rU   r   rV   r   r5   rX   )NF)
rY   r   rZ   r[   r\   r]   r^   r_   r5   rX   )rr   rs   r5   r	   )ru   r   r5   r	   )rw   rx   r5   ry   )rw   rx   r5   rX   )r   r   r   r6   r5   rx   )r5   rX   )8__doc__
__future__r   r   r   collectionsr   typingr   r   r   r   r   r	   r
   r   r   pymongor   pymongo.errorsr   r   r   r   r   r   r   r   r   pymongo.hellor   pymongo.cursor_sharedr   pymongo.operationsr   pymongo.typingsr   r   r   __annotations__r   r$   r&   r(   r3   r?   rM   rW   rS   rq   rv   rk   r}   r   r   r   r;   r;   r;   r<   <module>   sX   ,,






C
	


