ó
"b<]c           @   sC  d  Z  d d d d 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 y d d l m Z Wn! e	 k
 r  d d l m Z n Xd d l
 m Z d „  Z d „  Z d „  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z e d k r?d d l Z e j ƒ  n  d S(   s!   
Network Utilities
(from web.py)
t   validipaddrt   validip6addrt   validipportt   validipt	   validaddrt   urlquotet   httpdatet   parsehttpdatet	   htmlquotet   htmlunquotet   websafeiÿÿÿÿN(   t   quotei   (   t   PY2c         C   s9   y t  j t  j |  ƒ Wn t  j t f k
 r4 t SXt S(   s  
    Returns True if `address` is a valid IPv6 address.
    
        >>> validip6addr('::')
        True
        >>> validip6addr('aaaa:bbbb:cccc:dddd::1')
        True
        >>> validip6addr('1:2:3:4:5:6:7:8:9:10')
        False
        >>> validip6addr('12:10')
        False
    (   t   sockett	   inet_ptont   AF_INET6t   errort   AttributeErrort   Falset   True(   t   address(    (    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/net.pyR      s
    c         C   sy   y` |  j  d ƒ } t | ƒ d k r( t Sx4 | D], } d t | ƒ k oR d k n s/ t Sq/ WWn t k
 rt t SXt S(   sß   
    Returns True if `address` is a valid IPv4 address.
    
        >>> validipaddr('192.168.1.1')
        True
        >>> validipaddr('192.168.1.800')
        False
        >>> validipaddr('192.168.1')
        False
    t   .i   i    iÿ   (   t   splitt   lenR   t   intt
   ValueErrorR   (   R   t   octetst   x(    (    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/net.pyR    1   s    "c         C   sC   y* d t  |  ƒ k o  d k n s) t SWn t k
 r> t SXt S(   sÆ   
    Returns True if `port` is a valid IPv4 port.
    
        >>> validipport('9000')
        True
        >>> validipport('foo')
        False
        >>> validipport('1000000')
        False
    i    iÿÿ  (   R   R   R   R   (   t   port(    (    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/net.pyR   J   s    "s   0.0.0.0i  c         C   sÄ  | } | } t  j d |  ƒ } | r› t | j d ƒ ƒ r± | j d ƒ r‚ t | j d ƒ ƒ r• | j d ƒ t | j d ƒ ƒ f Sq˜ | j d ƒ | f Sq± n t |  ƒ r± |  | f S|  j d d ƒ }  t |  ƒ d k r>|  d sâ qºt |  d ƒ rÿ |  d } qºt |  d ƒ r"t |  d ƒ } qºt	 d j
 |  ƒ d ƒ ‚ n| t |  ƒ d k r¡|  \ } } t | ƒ svt | ƒ r’t	 d j
 |  ƒ d ƒ ‚ n  t | ƒ } n t	 d j
 |  ƒ d ƒ ‚ | | f S(   s  
    Returns `(ip_address, port)` from string `ip_addr_port`
    
        >>> validip('1.2.3.4')
        ('1.2.3.4', 8080)
        >>> validip('80')
        ('0.0.0.0', 80)
        >>> validip('192.168.0.1:85')
        ('192.168.0.1', 85)
        >>> validip('::')
        ('::', 8080)
        >>> validip('[::]:88')
        ('::', 88)
        >>> validip('[::1]:80')
        ('::1', 80)
    
    s   ^\[([^]]+)\](?::(\d+))?$i   i   t   :i    s    is not a valid IP address/port(   t   ret   searchR   t   groupR   R   R   R   R    R   t   join(   t   ipt   defaultaddrt   defaultportt   addrR   t   match(    (    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/net.pyR   ^   s6    %

c         C   s   d |  k r |  St  |  ƒ Sd S(   s  
    Returns either (ip_address, port) or "/path/to/socket" from string_
    
        >>> validaddr('/path/to/socket')
        '/path/to/socket'
        >>> validaddr('8000')
        ('0.0.0.0', 8000)
        >>> validaddr('127.0.0.1')
        ('127.0.0.1', 8080)
        >>> validaddr('127.0.0.1:8000')
        ('127.0.0.1', 8000)
        >>> validip('[::1]:80')
        ('::1', 80)
        >>> validaddr('fff')
        Traceback (most recent call last):
            ...
        ValueError: fff is not a valid IP address/port
    t   /N(   R   (   t   string_(    (    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/net.pyR      s    c         C   si   |  d k r d St rF t |  t ƒ r7 |  j d ƒ }  q[ t |  ƒ }  n t |  ƒ j d ƒ }  t |  ƒ Sd S(   sÎ   
    Quotes a string for use in a URL.
    
        >>> urlquote('://?f=1&j=1')
        '%3A//%3Ff%3D1%26j%3D1'
        >>> urlquote(None)
        ''
        >>> urlquote(u'\u203d')
        '%E2%80%BD'
    t    s   utf-8N(   t   NoneR   t
   isinstancet   unicodet   encodet   strR   (   t   val(    (    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/net.pyR   ©   s    c         C   s   |  j  d ƒ S(   sÂ   
    Formats a datetime object for use in HTTP headers.
    
        >>> import datetime
        >>> httpdate(datetime.datetime(1970, 1, 1, 1, 1, 1))
        'Thu, 01 Jan 1970 01:01:01 GMT'
    s   %a, %d %b %Y %H:%M:%S GMT(   t   strftime(   t   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/net.pyR   Á   s    c         C   s<   y t  j |  d ƒ } Wn t k
 r* d SXt j | d  Œ  S(   s¤   
    Parses an HTTP date into a datetime object.
    
        >>> parsehttpdate('Thu, 01 Jan 1970 01:01:01 GMT')
        datetime.datetime(1970, 1, 1, 1, 1, 1)
    s   %a, %d %b %Y %H:%M:%S %Zi   N(   t   timet   strptimeR   R*   t   datetime(   R(   t   t(    (    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/net.pyR   Ì   s
    c         C   s^   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d	 d
 ƒ }  |  S(   sw   
    Encodes `text` for raw use in HTML.
    
        >>> htmlquote(u"<'&\">")
        u'&lt;&#39;&amp;&quot;&gt;'
    u   &u   &amp;u   <u   &lt;u   >u   &gt;u   'u   &#39;u   "u   &quot;(   t   replace(   t   text(    (    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/net.pyR   Û   s    c         C   s^   |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d d ƒ }  |  j  d	 d
 ƒ }  |  S(   sx   
    Decodes `text` that's HTML quoted.
    
        >>> htmlunquote(u'&lt;&#39;&amp;&quot;&gt;')
        u'<\'&">'
    u   &quot;u   "u   &#39;u   'u   &gt;u   >u   &lt;u   <u   &amp;u   &(   R6   (   R7   (    (    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/net.pyR	   ê   s    c         C   s¥   |  d k r d St rX t |  t ƒ r7 |  j d ƒ }  q— t |  t ƒ s— t |  ƒ }  q— n? t |  t ƒ ry |  j d ƒ }  n t |  t ƒ s— t |  ƒ }  n  t |  ƒ Sd S(   så   Converts `val` so that it is safe for use in Unicode HTML.
    
        >>> websafe("<'&\">")
        u'&lt;&#39;&amp;&quot;&gt;'
        >>> websafe(None)
        u''
        >>> websafe(u'\u203d') == u'\u203d'
        True
    u    s   utf-8N(   R*   R   R+   R.   t   decodeR,   t   bytesR   (   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/net.pyR
   ù   s    
t   __main__(   t   __doc__t   __all__t   urllibR2   R4   R   R   t   urllib.parseR   t   ImportErrort
   py3helpersR   R   R    R   R   R   R   R   R   R   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/net.pyt   <module>   sD   				2							