Spade
Mini Shell
| Directory:~$ /lib/python2.7/site-packages/future/backports/ |
| [Home] [System Details] [Kill Me] |
�
,�]c@`s�dZddlmZddlmZddlmZddlmZddlmZddlZddlTddl Z ddl
Z
ddlZyddlZWne
k
r�dZnXeed d
�Zeedd�Zeed
d�ZddgZeje je��eZe
jj�jd�r�iZded<ded<ded<ded<ded<ded<ded<ded
<d!ed"<d#ed$<d%ed&<d'ed(<d)ed*<d+ed,<d-ed.<ejd/�nd0ejfd1��YZdd2�Zeejd3�rd4�Zneed5�rCde
dd6�Z!ne"eeg�Z#d7ej$fd8��YZ%d9d:�Zⅆlm'Z'e'dd<�Z(dS(=uThis
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 [*]
fromshare() -- create a socket object from data received from
socket.share() [*]
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() -- map 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 and
optional source address.
[*] 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(tunicode_literals(tprint_function(tdivision(tabsolute_import(tsuperN(t*uEBADFi uEAGAINiuEWOULDBLOCKugetfqdnucreate_connectionuwinuThe
operation was interrupted.i'uA bad file handle was
passed.i'uPermission 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'uThe network address is in use.i@'uThe connection
has been reset.iF'uThe network has been shut down.iJ'uThe
operation timed out.iL'uConnection refused.iM'uThe name is too
long.iO'uThe host is down.iP'uThe host is
unreachable.iQ'uerrorTabtsocketcB`s�eZdZdddgZeeddd�Zd�Zd�Z d�Z
d �Zd
�Zd�Z
ddd
�Zd�Zejd�Zd�Zd�ZRS(u:A subclass
of _socket.socket adding the makefile()
method.u__weakref__u_io_refsu_closedicC`sZ|dkr(tjj||||�ntjj|||||�d|_t|_dS(Ni(tNonet_socketRt__init__t_io_refstFalset_closed(tselftfamilyttypetprototfileno((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR cs
cC`s|S(N((R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt __enter__kscG`s|js|j�ndS(N(Rtclose(R
targs((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt__exit__ns cC`sftjj|�}|jd�rbd|jj|jjt|dt�rNdpQd|df}n|S(u.Wrap
__repr__() to reveal the real class name.u<socket objectu
<%s.%s%s%su_closedu
[closed] ui( RRt__repr__t
startswitht __class__t
__module__t__name__tgetattrR(R
ts((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRrs cC`std��dS(NuCannot
serialize socket
object(t TypeError(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt__getstate__|scC`sMt|j��}|j|j|j|jd|�}|j|j��|S(ujdup()
-> socket object
Return a new socket object connected to the same system resource.
R(tdupRRRRRt
settimeoutt
gettimeout(R
tfdtsock((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRs$cC`sh|j�\}}t|j|j|jd|�}t�dkr^|j�r^|jt �n||fS(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).
RN(
t_acceptRRRRtgetdefaulttimeoutRR!tsetblockingtTrue(R
R"taddrR#((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytaccept�s
!urcK`s�d|kr
|d}|d=nd
}d|krF|d}|d=nd
}d|krl|d}|d=nd
}x)|D]!}|dkrytd��qyqyWd|k}d|kp�|} d|k}
d}| r�|d7}n|r�|d7}nt||�}|jd 7_|d
kr(d
}n|dkr@tj}n|dkre|
satd��n|S| r�|r�tj|||�}
n-| r�tj||�}
ntj||�}
|
r�|
Stj |
|||�}||_
|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?)
unewlineuerrorsuencodinguruwubu&invalid mode %r (only r,
w, b allowed)uii����iu!unbuffered streams must be
binaryN(uruwub(Rt
ValueErrortSocketIOR
tiotDEFAULT_BUFFER_SIZEtBufferedRWPairtBufferedReadertBufferedWritert
TextIOWrappertmode(R
R2t bufferingt_3to2kwargstnewlineterrorstencodingtctwritingtreadingtbinarytrawmodetrawtbufferttext((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytmakefile�sV
cC`s;|jdkr!|jd8_n|jr7|j�ndS(Nii(R
RR(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt_decref_socketios�s cC`s|j|�dS(N(R(R
t_ss((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt_real_close�scC`s)t|_|jdkr%|j�ndS(Ni(R'RR
RC(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR�s cC`st|_t�j�S(udetach()
-> file descriptor
Close the socket object without closing the underlying file
descriptor.
The object cannot be used after this call, but the file descriptor
can be reused for other purposes. The file descriptor is returned.
(R'RRtdetach(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRD�s N(RRt__doc__t __slots__tAF_INETtSOCK_STREAMRR RRRRRR)R@RARRRCRRD(((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR]s
0 cC`st|�}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().
(RR(R"RRRtnfd((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytfromfd�susharecC`stddd|�S(u�
fromshare(info) -> socket object
Create a socket object from a the bytes object returned by
socket.share(pid).
i(R(tinfo((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt fromshare�su
socketpaircC`s�|dkr3y
t}Wq3tk
r/t}q3Xntj|||�\}}t||||j��}t||||j��}||fS(uasocketpair([family[,
type[, proto]]]) -> (socket object, socket object)
Create a pair of socket objects from the sockets returned by the
platform
socketpair() function.
The arguments are the same as for socket() except the default
family is
AF_UNIX if defined on the platform; otherwise, the default is
AF_INET.
N(RtAF_UNIXt NameErrorRGRt
socketpairRRD(RRRtatb((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRO�s
R+cB`steZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z e
d��Ze
d ��Zd
�Z
RS(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.
cC`s�|d krtd|��ntjj|�||_d|krQ|d7}n||_d|k|_d|k|_t|_ dS(
Nuruwurwurbuwburwbuinvalid mode: %rub(uruwurwurbuwburwb(
R*R,t RawIOBaseR t_sockt_modet_readingt_writingRt_timeout_occurred(R
R#R2((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR s
cC`s�|j�|j�|jr,td��nxjtr�y|jj|�SWq/tk
rht|_�q/tk
r�}|j dt
kr�dS�q/Xq/WdS(u3Read up to len(b) bytes into the writable buffer
*b* and return
the number of bytes read. If the socket is non-blocking and no
bytes
are available, None is returned.
If *b* is non-empty, a 0 return value indicates that the connection
was shutdown at the other end.
u!cannot read from timed out
objectiN(t_checkClosedt_checkReadableRWtIOErrorR'RSt recv_intottimeoutterrorRt_blocking_errnosR(R
RQte((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytreadinto)s
cC`s\|j�|j�y|jj|�SWn-tk
rW}|jdtkrQdS�nXdS(uWrite the given bytes or bytearray
object *b* to the socket
and return the number of bytes written. This can be less than
len(b) if not all data could be written. If the socket is
non-blocking and no bytes could be written None is returned.
iN(RXt_checkWritableRStsendR]RR^R(R
RQR_((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytwriteBs
cC`s|jrtd��n|jS(u2True if the SocketIO is open
for reading.
uI/O operation on closed
socket.(tclosedR*RU(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytreadableRs cC`s|jrtd��n|jS(u2True
if the SocketIO is open for writing.
uI/O operation on closed
socket.(RdR*RV(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytwritableYs cC`s%|jrtd��nt�j�S(u2True
if the SocketIO is open for seeking.
uI/O operation on closed
socket.(RdR*Rtseekable(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRg`s cC`s|j�|jj�S(u=Return
the file descriptor of the underlying socket.
(RXRSR(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRgs
cC`s|js|j�SdSdS(Ni����(RdR(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytnamems
cC`s|jS(N(RT(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR2tscC`s7|jr
dStjj|�|jj�d|_dS(u�Close
the SocketIO object. This doesn't close the underlying
socket, except if all references to it have disappeared.
N(RdR,RRRRSRAR(R
((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyRxs
(RRRER R`RcReRfRgRtpropertyRhR2R(((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyR+s ucC`s�|j�}|s|dkr+t�}nyt|�\}}}Wntk
rWn8X|jd|�x$|D]}d|kroPqoqoW|}|S(uGet 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.
u0.0.0.0iu.(tstriptgethostnamet
gethostbyaddrR]tinsert(Rhthostnametaliasestipaddrs((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytgetfqdn�s
(t_GLOBAL_DEFAULT_TIMEOUTcC`s|\}}d}x�t||dt�D]�}|\}}} }
}d}yYt||| �}|tk rz|j|�n|r�|j|�n|j|�|SWq(tk
r�}
|
}|dk r�|j �q�q(Xq(W|dk r�|�ntd��dS(udConnect
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. If *source_address* is set it must be a tuple of (host, port)
for the socket to bind as a source address before making the
connection.
An host of '' or port 0 tells the OS to use the default.
iu!getaddrinfo returns an empty listN(
RtgetaddrinfoRHRRrR
tbindtconnectR]R(taddressR\tsource_addressthosttportterrtrestaftsocktypeRt canonnametsaR#t_((s;/usr/lib/python2.7/site-packages/future/backports/socket.pytcreate_connection�s(
()REt
__future__RRRRtfuture.builtinsRRtostsysR,terrnotImportErrorRRtEBADFtEAGAINtEWOULDBLOCKt__all__textendt_get_exports_listRt_realsockettplatformtlowerRterrorTabtappendRJthasattrRLRHROtsetR^RRR+RqRrR�(((s;/usr/lib/python2.7/site-packages/future/backports/socket.pyt<module>-s`
$
� w