
    e?1iV                    H   d dl mZ d dlZd dlZd dlZd dlZd dlmZmZ d dlm	Z	 d dl
mZmZmZ dZdZ edee      Z ed	      Zdd
Zedd       Ze	 d	 	 	 	 	 dd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zeefdd       Zy)    )annotationsN)datetimetimezone)Enum)AnyTypeVarcast   At
ListOrDictTc                    | S )zbMark that a method's documentation should not be rendered. Functionally, this decorator is a noop. )methods    \/home/www/therecruiter.miabetepe.com/venv/lib/python3.12/site-packages/apify_shared/utils.pyignore_docsr      s    M    c                4    t        t        t        |             S )zWReturn copy of the dictionary, recursively omitting all keys for which values are None.)r	   dict+filter_out_none_values_recursively_internal)
dictionarys    r   "filter_out_none_values_recursivelyr      s     A*MNNr   c                    i }| j                         D ]1  \  }}t        |t              rt        ||du xs |du       }|-|||<   3 |s|ry|S )zRecursively filters out None values from a dictionary.

    Unfortunately, it's necessary to have an internal function for the correct result typing,
    without having to create complicated overloads
    TN)items
isinstancer   r   )r   remove_empty_dictsresultkvs        r   r   r      sl     F  " 1a;A?QUY?Y?w]osw]wxA=F1I	
 (Mr   c                `    t        t        j                  d| t        j                              S )z(Check if the given content type is JSON.z^application/jsonflagsboolresearch
IGNORECASEcontent_types    r   is_content_type_jsonr*   2   s!     		.BMMRSSr   c                `    t        t        j                  d| t        j                              S )z'Check if the given content type is XML.z^application/.*xml$r!   r#   r(   s    r   is_content_type_xmlr,   8   s!     		0,bmmTUUr   c                `    t        t        j                  d| t        j                              S )z(Check if the given content type is text.z^text/r!   r#   r(   s    r   is_content_type_textr.   >   s      		)\GHHr   c                L    t        | t        t        t        j                  f      S )aa  Check if the input value is a file-like object or bytes.

    The check for IOBase is not ideal, it would be better to use duck typing,
    but then the check would be super complex, judging from how the 'requests' library does it.
    This way should be good enough for the vast majority of use cases, if it causes issues, we can improve it later.
    )r   bytes	bytearrayioIOBase)values    r   is_file_or_bytesr5   D   s     eeY		:;;r   c                <    t        j                  | ddt              S )z?Dump JSON to a string with the correct settings and serializer.F   )ensure_asciiindentdefault)jsondumpsstr)objs    r   
json_dumpsr?   O   s     ::caEEr   c                >    t        | t              r| j                  S | S )zaExtract the value of an enumeration member if it is an Enum, otherwise return the original value.)r   r   r4   )maybe_enum_members    r   maybe_extract_enum_member_valuerB   U   s!     #T* &&&r   c           	        dk  r| S t        | t              r| D cg c]  }t        |dz
         c}S t        | t              r1dfd}| j	                         D ci c]  \  }}| |||       c}}S | S c c}w c c}}w )zPRecursively parse date fields in a list or dictionary up to the specified depth.r      c                   |}| j                  t              rht        |t              rXt	        j
                  t              5  t        j                  |d      j                  t        j                        }d d d        |S t        |t              rt        |dz
        }|S t        |t              rt        |      }|S # 1 sw Y   |S xY w)Nz%Y-%m-%dT%H:%M:%S.%fZ)tzinforD   )endswithPARSE_DATE_FIELDS_KEY_SUFFIXr   r=   
contextlibsuppress
ValueErrorr   strptimereplacer   utcr   parse_date_fieldslist)keyr4   parsed_value	max_depths      r   parsez parse_date_fields.<locals>.parseh   s     L||89jPS>T((4 r#+#4#4U<S#T#\#\dldpdp#\#qLr  	 E4(0	AF   E4(0	Br  s   5C  C
)rQ   r=   r4   objectreturnrU   )r   rP   rO   r   r   )datarS   itemrT   rQ   r4   s    `    r   rO   rO   ]   s     1}$CGH4!$	A6HH$		  <@::<H<CU3&&HHK# I Is   A9A>)r   r   rV   r   )r   r   rV   r   )N)r   r   r   zbool | NonerV   zdict | None)r)   r=   rV   r$   )r4   r   rV   r$   )r>   r   rV   r=   )rA   r   rV   r   )rW   r   rS   intrV   r   )
__future__r   rI   r2   r;   r%   r   r   enumr   typingr   r   r	   PARSE_DATE_FIELDS_MAX_DEPTHrH   rP   r   r   r   r   r   r   r*   r,   r.   r5   r?   rB   rO   r   r   r   <module>r^      s(   "  	  	 '  % % # \4.
CL
 O O
  '+#  ( T T
 V V
 I I
 < < F F
   9T  r   