
    Df                         d Z g dZddlZddlmZmZ ddlmZ ddlm	Z	 	 ddl
mZ n# e$ r	 ddlmZ Y nw xY wdd
Zd Zd ZddZddZddZddZd Zedk    rddlZ ej                     dS dS )z
HTTP Utilities
(from web.py)
)expireslastmodified	prefixurlmodifiedchangequeryurlprofiler    N   )netutils)webapi)	iteritems)	urlencode c                     t           j        j                            d          }t	          |                    d                    D ]}| dz  } | sd} | S )zY
    Sorry, this function is really difficult to explain.
    Maybe some other time.
    /z../z./)webctxpathlstriprangecount)baser   is      7/var/www/media/lib/python3.11/site-packages/web/http.pyr   r      sY    
 ',

c
"
"C399S>>""   K    c                     t          | t                    rt          j        |           } t          j                                        | z   }t          j        dt          j        |                     dS )zw
    Outputs an `Expires` header for `delta` from now.
    `delta` is a `timedelta` object or a number of seconds.
    secondsExpiresN)	
isinstanceintdatetime	timedeltautcnowr   headerr   httpdate)deltadate_objs     r   r   r   )   sd    
 % 2"5111 ''))E1HJy#,x0011111r   c                 T    t          j        dt          j        |                      dS )z0Outputs a `Last-Modified` header for `datetime`.zLast-ModifiedN)r   r&   r   r'   )r)   s    r   r   r   4   s$    JX 6 677777r   c                 *   t          d t          j        j                            dd                              d          D                       }t          j        t          j        j                            dd                              d          d                   }d}|r
d	|v s||v rd
}| r |r| t          j	        d          z
  |k    rd
}| rt          |            |rt          j        dd|z   dz              |rt          j                    d
S )a&  
    Checks to see if the page has been modified since the version in the
    requester's cache.

    When you publish pages, you can include `Last-Modified` and `ETag`
    with the date the page was last modified and an opaque token for
    the particular version, respectively. When readers reload the page,
    the browser sends along the modification date and etag value for
    the version it has in its cache. If the page hasn't changed,
    the server can just return `304 Not Modified` and not have to
    send the whole page again.

    This function takes the last-modified date `date` and the ETag `etag`
    and checks the headers to see if they match. If they do, it returns
    `True`, or otherwise it raises NotModified error. It also sets
    `Last-Modified` and `ETag` output headers.
    c                 8    g | ]}|                     d           S )z" )strip).0xs     r   
<listcomp>zmodified.<locals>.<listcomp>L   s"    UUU1UUUr   HTTP_IF_NONE_MATCHr   ,HTTP_IF_MODIFIED_SINCE;r	   F*Tr
   r   ETag")setr   r   envgetsplitr   parsehttpdater#   r$   r   r&   notmodified)dateetagnmvalidates        r   r   r   9   s*   $ 	UU0Db I I O OPS T TUUU	 	A 	#'+//*BBGGMMcRRSTUVVAH !88tqyyH   ($Q////144H T -
63:+,,, otr   c                     dfd	t          fd|                                 D                       } t          |           S )z
    Same as urllib.urlencode, but supports unicode strings.

        >>> urlencode({'text':'foo bar'})
        'text=foo+bar'
        >>> urlencode({'x': [1, 2]}, doseq=True)
        'x=1&x=2'
    Fc                 v    |r#t          | t                    rfd| D             S t          j        |           S )Nc                 &    g | ]} |          S  rF   )r.   vconverts     r   r0   z.urlencode.<locals>.convert.<locals>.<listcomp>o   s!    ...1GGAJJ...r   )r!   listr   safestr)valuedoseqrH   s     r   rH   zurlencode.<locals>.convertm   sF     	(Zt,, 	(........='''r   c                 2    g | ]\  }}| |          fS rF   rF   )r.   krG   rH   rL   s      r   r0   zurlencode.<locals>.<listcomp>s   s.    CCCTQ1gga''(CCCr   rL   )F)dictitemsurllib_urlencode)queryrL   rH   s    `@r   r   r   c   sd    ( ( ( ( ( ( CCCCCU[[]]CCCDDEE////r   c                     | t          j        d          } t          |          D ]#\  }}||                     |d           || |<   $t           j        j        }| r|dt          | d          z   z  }|S )z
    Imagine you're at `/foo?a=1&b=2`. Then `changequery(a=3)` will return
    `/foo?a=3&b=2` -- the same URL but with the arguments you requested
    changed.
    Nr:   )method?TrO   )r   rawinputr   popr   r   r   )rS   kwrN   rG   outs        r   r   r   w   s     }E***"  19IIaE!HH
',C 2sYuD11111Jr   Fc                     | t           j        j        } |                     d          rt           j        j        | z   }n| }|r|dt          ||          z   z  }|S )zt
    Makes url by concatenating web.ctx.homepath and path and the
    query string created using the arguments.
    Nr   rV   rO   )r   r   r   
startswithhomepathr   )r   rL   rY   rZ   s       r   r   r      se    
 |w|s g%	 0sYr/////Jr   c                 "     ddl m  fd}|S )zCOutputs basic profiling information at the bottom of each response.r	   )profilec                                 | |          \  }}t          |          dt          j        |          z   dz   gz   S )Nz<pre>z</pre>)rI   r   websafe)eorZ   resultappr_   s       r   profile_internalz"profiler.<locals>.profile_internal   sH    "ggcll1a((VCyyGck&&9&99HDEEEr   )r   r_   )re   rf   r_   s   ` @r   r   r      sB    F F F F F F r   __main__)r   )NN)r	   )N)NF)__doc____all__r#   r   r   r   r   r   
py3helpersr   urllib.parser   rR   ImportErrorurllibr   r   r   r   r   r   r   __name__doctesttestmodrF   r   r   <module>rq      sz   
                  ! ! ! ! ! !5::::::: 5 5 5444444445
 
 
 
2 2 28 8 8
' ' ' 'T0 0 0 0(   &   $   zNNNGO s   ' 55