;
Êâ"Ic               @   s¹  d  Z  d d l Z d d l Td d l Z d d l Z d d l Z y d d l m Z Wn e k
 o d Z Yn Xd g Z e j	 e j
 e ƒ ƒ e Z e j j ƒ  j d ƒ o­ i  Z d e d	 <d
 e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d e d <d  e d! <d" e d# <d$ e d% <e j d& ƒ n Gd' „  d( e j ƒ Z d d) „ Z Gd* „  d+ e j ƒ Z d, d- „ Z e ƒ  Z e d. „ Z d S(/   u˜  This module provides socket operations and some related functions.
On Unix, it supports IP (Internet Protocol) and Unix domain sockets.
On other systems, it only supports IP. Functions specific for a
socket are available as methods of the socket object.

Functions:

socket() -- create a new socket object
socketpair() -- create a pair of new socket objects [*]
fromfd() -- create a socket object from an open file descriptor [*]
gethostname() -- return the current hostname
gethostbyname() -- map a hostname to its IP number
gethostbyaddr() -- map an IP number or hostname to DNS info
getservbyname() -- map a service name and a protocol name to a port number
getprotobyname() -- mape a protocol name (e.g. 'tcp') to a number
ntohs(), ntohl() -- convert 16, 32 bit int from network to host byte order
htons(), htonl() -- convert 16, 32 bit int from host to network byte order
inet_aton() -- convert IP addr string (123.45.67.89) to 32-bit packed format
inet_ntoa() -- convert 32-bit packed format IP to string (123.45.67.89)
socket.getdefaulttimeout() -- get the default timeout value
socket.setdefaulttimeout() -- set the default timeout value
create_connection() -- connects to an address, with an optional timeout

 [*] not available on all platforms!

Special objects:

SocketType -- type object for socket objects
error -- exception raised for I/O errors
has_ipv6 -- boolean value indicating if IPv6 is supported

Integer constants:

AF_INET, AF_UNIX -- socket domains (first argument to socket() call)
SOCK_STREAM, SOCK_DGRAM, SOCK_RAW -- socket types (second argument)

Many other constants may be defined; these may be used in calls to
the setsockopt() and getsockopt() methods.
i    N(   u   *(   u   EBADFi	   u   getfqdnu   winu   The operation was interrupted.i'  u   A bad file handle was passed.i'  u   Permission denied.i'  u!   A fault occurred on the network??i'  u#   An invalid operation was attempted.i&'  u    The socket operation would blocki3'  u,   A blocking operation is already in progress.i4'  u   The network address is in use.i@'  u   The connection has been reset.iF'  u   The network has been shut down.iJ'  u   The operation timed out.iL'  u   Connection refused.iM'  u   The name is too long.iO'  u   The host is down.iP'  u   The host is unreachable.iQ'  u   errorTabc             B   s‰   |  Ee  Z d  Z d d d g Z e e d d d „ Z d „  Z d „  Z	 d „  Z
 d	 d d
 d d d d „Z d „  Z d „  Z d „  Z d S(   u:   A subclass of _socket.socket adding the makefile() method.u   __weakref__u   _io_refsu   _closedi    c             C   s2   t  j j |  | | | | ƒ d |  _ d |  _ d  S(   Ni    F(   u   _socketu   socketu   __init__u   _io_refsu   Falseu   _closed(   u   selfu   familyu   typeu   protou   fileno(    (    u#   /mit/python/lib/python3.0/socket.pyu   __init__X   s    	c             C   sg   t  j j |  ƒ } | j d ƒ oA d |  j j |  j j |  j o d p d | d d … f } n | S(   u.   Wrap __repr__() to reveal the real class name.u   <socket objectu
   <%s.%s%s%su
    [closed] u    i   N(   u   _socketu   socketu   __repr__u
   startswithu	   __class__u
   __module__u   __name__u   _closed(   u   selfu   s(    (    u#   /mit/python/lib/python3.0/socket.pyu   __repr__]   s    	c             C   sM   t  |  j ƒ  ƒ } |  j |  j |  j |  j d | ƒ} | j |  j ƒ  ƒ | S(   uj   dup() -> socket object

        Return a new socket object connected to the same system resource.
        u   fileno(   u   dupu   filenou	   __class__u   familyu   typeu   protou
   settimeoutu
   gettimeout(   u   selfu   fdu   sock(    (    u#   /mit/python/lib/python3.0/socket.pyu   dupg   s    $c             C   s7   |  j  ƒ  \ } } t |  j |  j |  j d | ƒ| f S(   uú   accept() -> (socket object, address info)

        Wait for an incoming connection.  Return a new socket
        representing the connection, and the address of the client.
        For IP sockets, the address info is a pair (hostaddr, port).
        u   fileno(   u   _acceptu   socketu   familyu   typeu   proto(   u   selfu   fdu   addr(    (    u#   /mit/python/lib/python3.0/socket.pyu   acceptq   s    u   encodingu   newlineu   rc            C   sñ  x4 | D], } | d d d h k o t  d ƒ ‚ q q Wd | k } d | k p | } | p | p t ‚ d | k } d }	 | o |	 d 7}	 n | o |	 d 7}	 n t |  |	 ƒ }
 |  j d 7_ | d
 k o
 d } n | d k  o t j } n | d k o4 | p t  d	 ƒ ‚ n |  j ƒ  |
 _ | |
 _	 |
 S| o  | o t j
 |
 |
 | ƒ } n> | o t j |
 | ƒ } n! | p t ‚ t j |
 | ƒ } | o |  j ƒ  | _ | | _	 | St j | | | ƒ } |  j ƒ  | _ | | _	 | S(   u  makefile(...) -> an I/O stream connected to the socket

        The arguments are as for io.open() after the filename,
        except the only mode characters supported are 'r', 'w' and 'b'.
        The semantics are similar too.  (XXX refactor to share code?)
        u   ru   wu   bu&   invalid mode %r (only r, w, b allowed)u    i   iÿÿÿÿi    u!   unbuffered streams must be binaryN(   u
   ValueErroru   AssertionErroru   SocketIOu   _io_refsu   Noneu   iou   DEFAULT_BUFFER_SIZEu   filenou   nameu   modeu   BufferedRWPairu   BufferedReaderu   BufferedWriteru   TextIOWrapper(   u   selfu   modeu	   bufferingu   encodingu   newlineu   cu   writingu   readingu   binaryu   rawmodeu   rawu   bufferu   text(    (    u#   /mit/python/lib/python3.0/socket.pyu   makefile{   sN     
			c             C   s?   |  j  d k o |  j  d 8_  n |  j o |  j ƒ  n d  S(   Ni    i   (   u   _io_refsu   _closedu   close(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   _decref_socketios«   s    
c             C   s   t  j j |  ƒ d  S(   N(   u   _socketu   socketu   close(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   _real_close±   s    c             C   s+   d |  _ |  j d k o |  j ƒ  n d  S(   Ni    T(   u   Trueu   _closedu   _io_refsu   _real_close(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   close´   s    	N(   u   __name__u
   __module__u   __doc__u	   __slots__u   AF_INETu   SOCK_STREAMu   Noneu   __init__u   __repr__u   dupu   acceptu   makefileu   _decref_socketiosu   _real_closeu   close(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/socket.pyu   socketR   s   
	
	
	
/		u   socketc             C   s   t  |  ƒ } t | | | | ƒ S(   u¾    fromfd(fd, family, type[, proto]) -> socket object

    Create a socket object from a duplicate of the given file
    descriptor.  The remaining arguments are the same as for socket().
    (   u   dupu   socket(   u   fdu   familyu   typeu   protou   nfd(    (    u#   /mit/python/lib/python3.0/socket.pyu   fromfd¹   s    c             B   s\   |  Ee  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 S(
   u¬   Raw I/O implementation for stream sockets.

    This class supports the makefile() method on sockets.  It provides
    the raw I/O interface on top of a socket object.
    c             C   se   | d k o t  d | ƒ ‚ n t j j |  ƒ | |  _ | |  _ d | k |  _ d | k |  _ d  S(   Nu   ru   wu   rwu   invalid mode: %r(   u   ru   wu   rw(   u
   ValueErroru   iou	   RawIOBaseu   __init__u   _socku   _modeu   _readingu   _writing(   u   selfu   socku   mode(    (    u#   /mit/python/lib/python3.0/socket.pyu   __init__Í   s    		c             C   s$   |  j  ƒ  |  j ƒ  |  j j | ƒ S(   N(   u   _checkClosedu   _checkReadableu   _socku	   recv_into(   u   selfu   b(    (    u#   /mit/python/lib/python3.0/socket.pyu   readintoÖ   s    

c             C   s$   |  j  ƒ  |  j ƒ  |  j j | ƒ S(   N(   u   _checkClosedu   _checkWritableu   _socku   send(   u   selfu   b(    (    u#   /mit/python/lib/python3.0/socket.pyu   writeÛ   s    

c             C   s   |  j  o |  j S(   N(   u   _readingu   closed(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   readableà   s    c             C   s   |  j  o |  j S(   N(   u   _writingu   closed(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   writableã   s    c             C   s   |  j  j ƒ  S(   N(   u   _socku   fileno(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   filenoæ   s    c             C   s#   |  j  o d  St j j |  ƒ d  S(   N(   u   closedu   iou	   RawIOBaseu   close(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   closeé   s    
c             C   s   |  j  j ƒ  d  S(   N(   u   _socku   _decref_socketios(   u   self(    (    u#   /mit/python/lib/python3.0/socket.pyu   __del__î   s    N(   u   __name__u
   __module__u   __doc__u   __init__u   readintou   writeu   readableu   writableu   filenou   closeu   __del__(   u
   __locals__(    (    u#   /mit/python/lib/python3.0/socket.pyu   SocketIOÃ   s   
								u   SocketIOu    c          	   C   s›   |  j  ƒ  }  |  p |  d k o t ƒ  }  n y t |  ƒ \ } } } Wn t k
 o Yn; X| j d | ƒ x& | D] }  d |  k o Pqu qu W| }  |  S(   u  Get fully qualified domain name from name.

    An empty argument is interpreted as meaning the local host.

    First the hostname returned by gethostbyaddr() is checked, then
    possibly existing aliases. In case no FQDN is available, hostname
    from gethostname() is returned.
    u   0.0.0.0i    u   .(   u   stripu   gethostnameu   gethostbyaddru   erroru   insert(   u   nameu   hostnameu   aliasesu   ipaddrs(    (    u#   /mit/python/lib/python3.0/socket.pyu   getfqdnò   s    	 	c             C   sí   d } |  \ } } xÈ t  | | d t ƒ D]± } | \ } } } }	 }
 d } yE t | | | ƒ } | t k	 o | j | ƒ n | j |
 ƒ | SWq( t k
 o< } z& | } | d k	 o | j ƒ  n WYd d } ~ Xq( Xq( Wt | ƒ ‚ d S(   u›  Connect to *address* and return the socket object.

    Convenience function.  Connect to *address* (a 2-tuple ``(host,
    port)``) and return the socket object.  Passing the optional
    *timeout* parameter will set the timeout on the socket instance
    before attempting to connect.  If no *timeout* is supplied, the
    global default timeout setting returned by :func:`getdefaulttimeout`
    is used.
    u!   getaddrinfo returns an empty listi    N(	   u   getaddrinfou   SOCK_STREAMu   Noneu   socketu   _GLOBAL_DEFAULT_TIMEOUTu
   settimeoutu   connectu   erroru   close(   u   addressu   timeoutu   msgu   hostu   portu   resu   afu   socktypeu   protou	   canonnameu   sau   socku   err(    (    u#   /mit/python/lib/python3.0/socket.pyu   create_connection  s"     &(   u   __doc__u   _socketu   osu   sysu   iou   errnou   EBADFu   ImportErroru   __all__u   extendu   _get_exports_listu   socketu   _realsocketu   platformu   loweru
   startswithu   errorTabu   appendu   fromfdu	   RawIOBaseu   SocketIOu   getfqdnu   objectu   _GLOBAL_DEFAULT_TIMEOUTu   create_connection(    (    (    u#   /mit/python/lib/python3.0/socket.pyu   <module>+   sD   
$	














g
/	