
    ^i
                     N   S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	J
r
  SSKJrJrJrJr  SSKJrJrJr  \" S	5      r " S
 S5      r\	 " S S\5      5       r\	 " S S\5      5       r\	 " S S\5      5       r\	 " S S\5      5       r\	 " S S\5      5       r " S S\\\   5      rg)zResult classes.    )ABC)Counter)CallableMapping)	dataclassfield)AnyClassVarGenericTypeVar   )_normalize_date_normalize_text_normalize_urlTc                   p    \ rS rSr% Sr\\\\\\\\\\S.
r\	\
\\\/\4   4      \S'   S\S\SS4S	 jrS
rg)
BaseResult   z=Base class for all results. Contains normalization functions.)
titlebodyhrefurl	thumbnailimagedateauthor	publisherinfo_normalizersnamevaluereturnNc                     U(       a*  U R                   R                  U5      =n(       a  U" U5      n[        R                  XU5        g)zHOverride setattr to apply normalization functions to certain attributes.N)r   getobject__setattr__)selfr    r!   
normalizers       F/home/james-whalen/.local/lib/python3.13/site-packages/ddgs/results.pyr&   BaseResult.__setattr__   s:    D$5$5$9$9$$??j?u%E4u-     )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r
   r   strr   r	   __annotations__r&   __static_attributes__r,   r+   r)   r   r      sh    G !#!$BL(73#(<#<=> . .C .D .r+   r   c                   D    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
g)	
TextResult%   zText search result. r   r   r   r,   N)r-   r.   r/   r0   r1   r   r2   r3   r   r   r4   r,   r+   r)   r6   r6   %   s     E3OD#ND#Nr+   r6   c                   |    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   Sr\\S	'   Sr\\S
'   Srg)ImagesResult.   zImage search result.r8   r   r   r   r   heightwidthsourcer,   N)r-   r.   r/   r0   r1   r   r2   r3   r   r   r   r<   r=   r>   r4   r,   r+   r)   r:   r:   .   sG    E3OE3OIsCMFCE3OFCr+   r:   c                   n    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   Sr\\S	'   S
rg)
NewsResult;   zNews search result.r8   r   r   r   r   r   r>   r,   N)r-   r.   r/   r0   r1   r   r2   r3   r   r   r   r   r>   r4   r,   r+   r)   r@   r@   ;   s<    D#NE3OD#NCME3OFCr+   r@   c                       \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   Sr\\S	'   Sr\\S
'   \" \S9r\\\4   \S'   Sr\\S'   Sr\\S'   Sr\\S'   \" \S9r\\\4   \S'   Sr\\S'   Srg)VideosResultG   zVideo search result.r8   r   contentdescriptionduration
embed_html	embed_urlimage_token)default_factoryimagesprovider	publishedr   
statisticsuploaderr,   N)r-   r.   r/   r0   r1   r   r2   r3   rE   rF   rG   rH   rI   rJ   r   dictrL   rM   rN   r   rO   rP   r4   r,   r+   r)   rC   rC   G   s    E3OGSKHcJIsK"48FDcN8HcIsIs!&t!<JS#X<Hcr+   rC   c                   n    \ rS rSr% SrSr\\S'   Sr\\S'   Sr	\\S'   Sr
\\S'   Sr\\S'   Sr\\S	'   S
rg)BooksResultZ   zBook search result.r8   r   r   r   r   r   r   r,   N)r-   r.   r/   r0   r1   r   r2   r3   r   r   r   r   r   r4   r,   r+   r)   rS   rS   Z   s>    E3OFCIsD#NCMIsr+   rS   c                       \ rS rSrSrS\\   SS4S jrS\S\4S jr	S\
4S	 jrS\SS4S
 jrS\\   SS4S jrS\\\\4      4S jrSrg)ResultsAggregatorf   zAggregates incoming results.

Items are deduplicated by `cache_field`. Append just increments a counter;
`extract_results` returns items sorted by descending frequency.
cache_fieldsr"   Nc                 x    U(       d  Sn[        U5      e[        U5      U l        [        5       U l        0 U l        g )Nz)At least one cache_field must be provided)
ValueErrorsetrX   r   _counter_cache)r'   rX   msgs      r)   __init__ResultsAggregator.__init__m   s1    =CS/!-&-i$&r+   itemc                     UR                    H,  nX R                  ;   d  M  [        UR                   U   5      s  $    SU< SU R                   3n[        U5      e)NzItem z has none of the cache fields )__dict__rX   r2   AttributeError)r'   ra   keyr^   s       r)   _get_keyResultsAggregator._get_keyu   sW    ==C'''4==-.. ! dX;D<M<M;NOS!!r+   c                 ,    [        U R                  5      $ )z(Return the number of items in the cache.)lenr]   )r'   s    r)   __len__ResultsAggregator.__len__|   s    4;;r+   c                 @   U R                  U5      nX R                  ;  dY  [        UR                  R	                  SS5      5      [        U R                  U   R                  R	                  SS5      5      :  a  XR                  U'   U R
                  U==   S-  ss'   g)zAdd an item to the cache.

Register an occurrence of `item`. First time we see its key,
we store the item; every time we bump the counter.
r   r8   r   N)rf   r]   ri   rc   r$   r\   )r'   ra   re   s      r)   appendResultsAggregator.append   s     mmD!kk!S):):62)F%G#KK%%))&"5K
 &
  $KKcar+   itemsc                 8    U H  nU R                  U5        M     g)z!Add a list of items to the cache.N)rm   )r'   ro   ra   s      r)   extendResultsAggregator.extend   s    DKK r+   c                     U R                   R                  5        VVs/ s H  u  pU R                  U   R                  PM      snn$ s  snnf )zXReturn a list of items, sorted by descending frequency. Each item is returned as a dict.)r\   most_commonr]   rc   )r'   re   _s      r)   extract_dictsResultsAggregator.extract_dicts   s:    8<8Q8Q8ST8SfcC ))8STTTs   %A)r]   r\   rX   )r-   r.   r/   r0   r1   r[   r2   r_   r   rf   intrj   rm   listrq   rQ   r	   rv   r4   r,   r+   r)   rV   rV   f   s    'SX '$ '"Q "3 "    1    DG  
UtDcN3 Ur+   rV   N)r1   abcr   collectionsr   collections.abcr   r   dataclassesr   r   typingr	   r
   r   r   utilsr   r   r   r   r   r6   r:   r@   rC   rS   rV   r,   r+   r)   <module>r      s       - ( 2 2 C CCL. ..    	: 	 	    :  $ *  .UWQZ .Ur+   