ó
"b<]c           @   sG  d  Z  d d d d d d d g Z d d	 l Z d d	 l Z d d	 l Z d d	 l Z d d	 l Z d
 d l m Z m	 Z	 m
 Z d
 d l m Z y d d l m Z Wn! e k
 rÀ d d l m Z n Xd d „ Z d „  Z d „  Z d	 d	 d „ Z d d „ Z d	 d „ Z d	 e d „ Z d „  Z e d k rCd d	 l Z e j ƒ  n  d	 S(   s   
HTTP Utilities
(from web.py)
t   expirest   lastmodifiedt	   prefixurlt   modifiedt   changequeryt   urlt   profileriÿÿÿÿNi   (   t   nett   utilst   webapi(   t	   iteritems(   t	   urlencodet    c         C   sR   t  j j j d ƒ } x' t | j d ƒ ƒ D] } |  d 7}  q+ W|  sN d }  n  |  S(   sY   
    Sorry, this function is really difficult to explain.
    Maybe some other time.
    t   /s   ../s   ./(   t   webt   ctxt   patht   lstript   xranget   count(   t   baseR   t   i(    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR      s    	c         C   sZ   t  |  t t f ƒ r* t j d |  ƒ }  n  t j j ƒ  |  } t j d t j	 | ƒ ƒ d S(   sx   
    Outputs an `Expires` header for `delta` from now. 
    `delta` is a `timedelta` object or a number of seconds.
    t   secondst   ExpiresN(
   t
   isinstancet   intt   longt   datetimet	   timedeltat   utcnowR   t   headerR   t   httpdate(   t   deltat   date_obj(    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR    $   s    c         C   s   t  j d t j |  ƒ ƒ d S(   s0   Outputs a `Last-Modified` header for `datetime`.s   Last-ModifiedN(   R   R   R   R   (   R!   (    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   /   s    c         C   s^  y d d l  m } Wn! t k
 r7 d d l m } n X| g  t j j j d d ƒ j	 d ƒ D] } | j
 d ƒ ^ q] ƒ } t j t j j j d d ƒ j	 d	 ƒ d
 ƒ } t } | rÙ d | k sÍ | | k rÙ t } qÙ n  |  r| r|  t j d d ƒ | k rt } qn  |  r t |  ƒ n  | rAt j d d | d ƒ n  | rVt j ƒ  ‚ n t Sd S(   s3  
    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.
    iÿÿÿÿ(   t   set(   t   Sett   HTTP_IF_NONE_MATCHR   t   ,s   " t   HTTP_IF_MODIFIED_SINCEt   ;i    t   *R   i   t   ETagt   "N(   t   __builtin__R"   t   ImportErrort   setsR#   R   R   t   envt   gett   splitt   stripR   t   parsehttpdatet   Falset   TrueR   R   R   R   t   notmodified(   t   datet   etagR"   t   xt   nt   mt   validate(    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   4   s(    C.i    c            s\   t  ‡  f d † ‰  t g  |  j ƒ  D]! \ } } | ˆ  | | ƒ f ^ q" ƒ }  t |  d | ƒS(   sÊ   
    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'
    c            sC   | r2 t  |  t ƒ r2 g  |  D] } ˆ  | ƒ ^ q St j |  ƒ Sd  S(   N(   R   t   listR   t   safestr(   t   valuet   doseqt   v(   t   convert(    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyRA   h   s    R?   (   R3   t   dictt   itemst   urllib_urlencode(   t   queryR?   t   kR@   (    (   RA   s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   ^   s    
:c         K   sš   |  d k r! t j d d ƒ }  n  xC t | ƒ D]5 \ } } | d k rY |  j | d ƒ q. | |  | <q. Wt j j } |  r– | d t |  d t ƒ7} n  | S(   s¤   
    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.
    t   methodR/   t   ?R?   N(	   t   NoneR   t   rawinputR
   t   popR   R   R   R4   (   RE   t   kwRF   R@   t   out(    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   r   s    c         K   sj   |  d k r t j j }  n  |  j d ƒ r= t j j |  } n |  } | rf | d t | d | ƒ7} n  | S(   su   
    Makes url by concatenating web.ctx.homepath and path and the 
    query string created using the arguments.
    R   RH   R?   N(   RI   R   R   R   t
   startswitht   homepathR   (   R   R?   RL   RM   (    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   †   s    c            s&   d d l  m ‰ ‡  ‡ f d †  } | S(   sC   Outputs basic profiling information at the bottom of each response.iÿÿÿÿ(   t   profilec            s=   ˆ ˆ  ƒ |  | ƒ \ } } t  | ƒ d t j | ƒ d g S(   Ns   <pre>s   </pre>(   R<   R   t   websafe(   t   et   oRM   t   result(   t   appRP   (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyt   profile_internalš   s    (   R   RP   (   RU   RV   (    (   RU   RP   s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyR   –   s    t   __main__(   t   __doc__t   __all__t   syst   ost	   threadingt   urllibR   R   R   R   R	   R   t
   py3helpersR
   t   urllib.parseR   RD   R,   R   R    R   RI   R   R   R3   R   R   t   __name__t   doctestt   testmod(    (    (    s¡   /mnt/my-files/home/darkz3ro/Desktop/my files/malware analysing and devlopment/viruses codes and analysis/APT34-leat/MuddyC3v1.0.1-/muddyc3_v1.0.1/lib/web/http.pyt   <module>   s4   	0		*	