
    ^i                         S r SSKrSSKrSSKJr  SSKJrJr  SSKJr  SSK	J
r
  SSKJr  \R                  " S	5      rS
\S\S\4S jrS\S\4S jrS\S\4S jrS\\-  S\4S jrS\S-  S\S-  4S jrg)z
Utilities.    N)suppress)datetimetimezone)unescape)unquote   )DDGSExceptionz<.*?>
html_bytesqueryreturnc                    S HV  u  p#n[        [        5         U R                  U5      U-   nU R                  XE5      nXU R                  5       sSSS5        s  $    SU< S3n[	        U5      e! , (       d  f       M{  = f)zExtract vqd from html bytes.))s   vqd="      ")s   vqd=      &)s   vqd='r      'Nz_extract_vqd() query=z Could not extract vqd.)r   
ValueErrorindexdecoder	   )r
   r   c1c1_lenc2startendmsgs           D/home/james-whalen/.local/lib/python3.13/site-packages/ddgs/utils.py_extract_vqdr      s    B
 j!$$R(61E""2-CC(//1 "! #E8#:
;C

 "!s   7A//
A>	urlc                 J    U (       a  [        U 5      R                  SS5      $ S$ )z(Unquote URL and replace spaces with '+'. + )r   replace)r   s    r   _normalize_urlr$      s     -073<S)8b8    rawc                    U (       d  g[         R                  SU 5      n[        U5      n[        R                  " SU5      n[        U5       Vs0 s H.  n[        R                  " U5      S   S:X  d  M"  [        U5      S_M0     nnU(       a  UR                  U5      nSR                  UR                  5       5      $ s  snf )zNormalize text.

Strip HTML tags, unescape HTML entities, normalize Unicode,
remove "c" category characters, and collapse whitespace.
r"   NFCr   CNr    )_REGEX_STRIP_TAGSsubr   unicodedata	normalizesetcategoryord	translatejoinsplit)r&   textch	c_to_nones       r   _normalize_textr7   $   s        S)D D>D   -D *-TY2k6J6J26Nq6QUX6XR$IY~~i( 88DJJL!! Zs   !B<3B<datec                     [        U [        5      (       a3  [        R                  " U [        R
                  5      R                  5       $ U $ )z8Normalize date from integer to ISO format if applicable.)
isinstanceintr   fromtimestampr   utc	isoformat)r8   s    r   _normalize_dater?   ?   s6    EOPTVYEZEZ8!!$5??Ad`ddr%   proxyc                     U S:X  a  S$ U $ )z.Expand "tb" to a full proxy URL if applicable.tbzsocks5h://127.0.0.1:9150 )r@   s    r   _expand_proxy_tb_aliasrD   D   s    ).$%AEAr%   )__doc__rer,   
contextlibr   r   r   htmlr   urllib.parser   
exceptionsr	   compiler*   bytesstrr   r$   r7   r;   r?   rD   rC   r%   r   <module>rN      s     	   '    %JJw' U 3 3  9 9 9
" " "6e#) e e
B#* Bt Br%   