PageRenderTime 52ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 1ms

/documentation_files/socket.py

https://github.com/kensington/kdevelop-python
Python | 421 lines | 268 code | 34 blank | 119 comment | 33 complexity | 8f61a7c349671b5dbe1d904a484d2528 MD5 | raw file
  1. #!/usr/bin/env python2.7
  2. # -*- coding: utf-8 -*-
  3. """:synopsis: Low-level networking interface.
  4. This module provides access to the BSD *socket* interface. It is available on
  5. all modern Unix systems, Windows, Mac OS X, BeOS, OS/2, and probably additional
  6. platforms.
  7. """
  8. """AF_INET
  9. AF_INET6
  10. These constants represent the address (and protocol) families, used for the
  11. first argument to :func:`socket`. If the :const:`AF_UNIX` constant is not
  12. defined then this protocol is unsupported.
  13. """
  14. AF_UNIX = None
  15. """SOCK_DGRAM
  16. SOCK_RAW
  17. SOCK_RDM
  18. SOCK_SEQPACKET
  19. These constants represent the socket types, used for the second argument to
  20. :func:`socket`. (Only :const:`SOCK_STREAM` and :const:`SOCK_DGRAM` appear to be
  21. generally useful.)
  22. """
  23. SOCK_STREAM = None
  24. """SOMAXCONN
  25. MSG_*
  26. SOL_*
  27. IPPROTO_*
  28. IPPORT_*
  29. INADDR_*
  30. IP_*
  31. IPV6_*
  32. EAI_*
  33. AI_*
  34. NI_*
  35. TCP_*
  36. Many constants of these forms, documented in the Unix documentation on sockets
  37. and/or the IP protocol, are also defined in the socket module. They are
  38. generally used in arguments to the :meth:`setsockopt` and :meth:`getsockopt`
  39. methods of socket objects. In most cases, only those symbols that are defined
  40. in the Unix header files are defined; for a few symbols, default values are
  41. provided.
  42. """
  43. SO_ = None
  44. """RCVALL_*
  45. Constants for Windows' WSAIoctl(). The constants are used as arguments to the
  46. :meth:`ioctl` method of socket objects.
  47. """
  48. SIO_ = None
  49. """
  50. TIPC related constants, matching the ones exported by the C socket API. See
  51. the TIPC documentation for more information.
  52. """
  53. TIPC_ = None
  54. """
  55. This constant contains a boolean value which indicates if IPv6 is supported on
  56. this platform.
  57. """
  58. has_ipv6 = None
  59. """
  60. This is a Python type object that represents the socket object type. It is the
  61. same as ``type(socket(more))``.
  62. """
  63. SocketType = None
  64. def create_connection(address,timeout,source_address):
  65. """
  66. Convenience function. Connect to *address* (a 2-tuple ``(host, port)``),
  67. and return the socket object. Passing the optional *timeout* parameter will
  68. set the timeout on the socket instance before attempting to connect. If no
  69. *timeout* is supplied, the global default timeout setting returned by
  70. :func:`getdefaulttimeout` is used.
  71. If supplied, *source_address* must be a 2-tuple ``(host, port)`` for the
  72. socket to bind to as its source address before connecting. If host or port
  73. are '' or 0 respectively the OS default behavior will be used.
  74. """
  75. pass
  76. def getaddrinfo(host,port,family=0,socktype=0,proto=0,flags=0):
  77. """
  78. Translate the *host*/*port* argument into a sequence of 5-tuples that contain
  79. all the necessary arguments for creating a socket connected to that service.
  80. *host* is a domain name, a string representation of an IPv4/v6 address
  81. or ``None``. *port* is a string service name such as ``'http'``, a numeric
  82. port number or ``None``. By passing ``None`` as the value of *host*
  83. and *port*, you can pass ``NULL`` to the underlying C API.
  84. The *family*, *socktype* and *proto* arguments can be optionally specified
  85. in order to narrow the list of addresses returned. Passing zero as a
  86. value for each of these arguments selects the full range of results.
  87. The *flags* argument can be one or several of the ``AI_*`` constants,
  88. and will influence how results are computed and returned.
  89. For example, :const:`AI_NUMERICHOST` will disable domain name resolution
  90. and will raise an error if *host* is a domain name.
  91. The function returns a list of 5-tuples with the following structure:
  92. ``(family, socktype, proto, canonname, sockaddr)``
  93. In these tuples, *family*, *socktype*, *proto* are all integers and are
  94. meant to be passed to the :func:`socket` function. *canonname* will be
  95. a string representing the canonical name of the *host* if
  96. :const:`AI_CANONNAME` is part of the *flags* argument; else *canonname*
  97. will be empty. *sockaddr* is a tuple describing a socket address, whose
  98. format depends on the returned *family* (a ``(address, port)`` 2-tuple for
  99. :const:`AF_INET`, a ``(address, port, flow info, scope id)`` 4-tuple for
  100. :const:`AF_INET6`), and is meant to be passed to the :meth:`socket.connect`
  101. method.
  102. The following example fetches address information for a hypothetical TCP
  103. connection to ``www.python.org`` on port 80 (results may differ on your
  104. system if IPv6 isn't enabled)::
  105. >>> socket.getaddrinfo("www.python.org", 80, 0, 0, socket.SOL_TCP)
  106. [(2, 1, 6, '', ('82.94.164.162', 80)),
  107. (10, 1, 6, '', ('2001:888:2000:d::a2', 80, 0, 0))]
  108. """
  109. pass
  110. def getfqdn(name):
  111. """
  112. Return a fully qualified domain name for *name*. If *name* is omitted or empty,
  113. it is interpreted as the local host. To find the fully qualified name, the
  114. hostname returned by :func:`gethostbyaddr` is checked, followed by aliases for the
  115. host, if available. The first name which includes a period is selected. In
  116. case no fully qualified domain name is available, the hostname as returned by
  117. :func:`gethostname` is returned.
  118. """
  119. pass
  120. def gethostbyname(hostname):
  121. """
  122. Translate a host name to IPv4 address format. The IPv4 address is returned as a
  123. string, such as ``'100.50.200.5'``. If the host name is an IPv4 address itself
  124. it is returned unchanged. See :func:`gethostbyname_ex` for a more complete
  125. interface. :func:`gethostbyname` does not support IPv6 name resolution, and
  126. :func:`getaddrinfo` should be used instead for IPv4/v6 dual stack support.
  127. """
  128. pass
  129. def gethostbyname_ex(hostname):
  130. """
  131. Translate a host name to IPv4 address format, extended interface. Return a
  132. triple ``(hostname, aliaslist, ipaddrlist)`` where *hostname* is the primary
  133. host name responding to the given *ip_address*, *aliaslist* is a (possibly
  134. empty) list of alternative host names for the same address, and *ipaddrlist* is
  135. a list of IPv4 addresses for the same interface on the same host (often but not
  136. always a single address). :func:`gethostbyname_ex` does not support IPv6 name
  137. resolution, and :func:`getaddrinfo` should be used instead for IPv4/v6 dual
  138. stack support.
  139. """
  140. pass
  141. def gethostname():
  142. """
  143. Return a string containing the hostname of the machine where the Python
  144. interpreter is currently executing.
  145. If you want to know the current machine's IP address, you may want to use
  146. ``gethostbyname(gethostname())``. This operation assumes that there is a
  147. valid address-to-host mapping for the host, and the assumption does not
  148. always hold.
  149. Note: :func:`gethostname` doesn't always return the fully qualified domain
  150. name; use ``getfqdn()`` (see above).
  151. """
  152. pass
  153. def gethostbyaddr(ip_address):
  154. """
  155. Return a triple ``(hostname, aliaslist, ipaddrlist)`` where *hostname* is the
  156. primary host name responding to the given *ip_address*, *aliaslist* is a
  157. (possibly empty) list of alternative host names for the same address, and
  158. *ipaddrlist* is a list of IPv4/v6 addresses for the same interface on the same
  159. host (most likely containing only a single address). To find the fully qualified
  160. domain name, use the function :func:`getfqdn`. :func:`gethostbyaddr` supports
  161. both IPv4 and IPv6.
  162. """
  163. pass
  164. def getnameinfo(sockaddr,flags):
  165. """
  166. Translate a socket address *sockaddr* into a 2-tuple ``(host, port)``. Depending
  167. on the settings of *flags*, the result can contain a fully-qualified domain name
  168. or numeric address representation in *host*. Similarly, *port* can contain a
  169. string port name or a numeric port number.
  170. """
  171. pass
  172. def getprotobyname(protocolname):
  173. """
  174. Translate an Internet protocol name (for example, ``'icmp'``) to a constant
  175. suitable for passing as the (optional) third argument to the :func:`socket`
  176. function. This is usually only needed for sockets opened in "raw" mode
  177. (:const:`SOCK_RAW`); for the normal socket modes, the correct protocol is chosen
  178. automatically if the protocol is omitted or zero.
  179. """
  180. pass
  181. def getservbyname(servicename,protocolname):
  182. """
  183. Translate an Internet service name and protocol name to a port number for that
  184. service. The optional protocol name, if given, should be ``'tcp'`` or
  185. ``'udp'``, otherwise any protocol will match.
  186. """
  187. pass
  188. def getservbyport(port,protocolname):
  189. """
  190. Translate an Internet port number and protocol name to a service name for that
  191. service. The optional protocol name, if given, should be ``'tcp'`` or
  192. ``'udp'``, otherwise any protocol will match.
  193. """
  194. pass
  195. def socket(family,type,proto):
  196. """
  197. Create a new socket using the given address family, socket type and protocol
  198. number. The address family should be :const:`AF_INET` (the default),
  199. :const:`AF_INET6` or :const:`AF_UNIX`. The socket type should be
  200. :const:`SOCK_STREAM` (the default), :const:`SOCK_DGRAM` or perhaps one of the
  201. other ``SOCK_`` constants. The protocol number is usually zero and may be
  202. omitted in that case.
  203. """
  204. pass
  205. def socketpair(family,type,proto):
  206. """
  207. Build a pair of connected socket objects using the given address family, socket
  208. type, and protocol number. Address family, socket type, and protocol number are
  209. as for the :func:`socket` function above. The default family is :const:`AF_UNIX`
  210. if defined on the platform; otherwise, the default is :const:`AF_INET`.
  211. Availability: Unix.
  212. """
  213. pass
  214. def _fromfd(fd,family,type,proto):
  215. """
  216. Duplicate the file descriptor *fd* (an integer as returned by a file object's
  217. :meth:`fileno` method) and build a socket object from the result. Address
  218. family, socket type and protocol number are as for the :func:`socket` function
  219. above. The file descriptor should refer to a socket, but this is not checked ---
  220. subsequent operations on the object may fail if the file descriptor is invalid.
  221. This function is rarely needed, but can be used to get or set socket options on
  222. a socket passed to a program as standard input or output (such as a server
  223. started by the Unix inet daemon). The socket is assumed to be in blocking mode.
  224. Availability: Unix.
  225. """
  226. pass
  227. def ntohl(x):
  228. """
  229. Convert 32-bit positive integers from network to host byte order. On machines
  230. where the host byte order is the same as network byte order, this is a no-op;
  231. otherwise, it performs a 4-byte swap operation.
  232. """
  233. pass
  234. def ntohs(x):
  235. """
  236. Convert 16-bit positive integers from network to host byte order. On machines
  237. where the host byte order is the same as network byte order, this is a no-op;
  238. otherwise, it performs a 2-byte swap operation.
  239. """
  240. pass
  241. def htonl(x):
  242. """
  243. Convert 32-bit positive integers from host to network byte order. On machines
  244. where the host byte order is the same as network byte order, this is a no-op;
  245. otherwise, it performs a 4-byte swap operation.
  246. """
  247. pass
  248. def htons(x):
  249. """
  250. Convert 16-bit positive integers from host to network byte order. On machines
  251. where the host byte order is the same as network byte order, this is a no-op;
  252. otherwise, it performs a 2-byte swap operation.
  253. """
  254. pass
  255. def inet_aton(ip_string):
  256. """
  257. Convert an IPv4 address from dotted-quad string format (for example,
  258. '123.45.67.89') to 32-bit packed binary format, as a string four characters in
  259. length. This is useful when conversing with a program that uses the standard C
  260. library and needs objects of type :ctype:`struct in_addr`, which is the C type
  261. for the 32-bit packed binary this function returns.
  262. :func:`inet_aton` also accepts strings with less than three dots; see the
  263. Unix manual page :manpage:`inet(3)` for details.
  264. If the IPv4 address string passed to this function is invalid,
  265. :exc:`socket.error` will be raised. Note that exactly what is valid depends on
  266. the underlying C implementation of :cfunc:`inet_aton`.
  267. :func:`inet_aton` does not support IPv6, and :func:`inet_pton` should be used
  268. instead for IPv4/v6 dual stack support.
  269. """
  270. pass
  271. def inet_ntoa(packed_ip):
  272. """
  273. Convert a 32-bit packed IPv4 address (a string four characters in length) to its
  274. standard dotted-quad string representation (for example, '123.45.67.89'). This
  275. is useful when conversing with a program that uses the standard C library and
  276. needs objects of type :ctype:`struct in_addr`, which is the C type for the
  277. 32-bit packed binary data this function takes as an argument.
  278. If the string passed to this function is not exactly 4 bytes in length,
  279. :exc:`socket.error` will be raised. :func:`inet_ntoa` does not support IPv6, and
  280. :func:`inet_ntop` should be used instead for IPv4/v6 dual stack support.
  281. """
  282. pass
  283. def inet_pton(address_family,ip_string):
  284. """
  285. Convert an IP address from its family-specific string format to a packed, binary
  286. format. :func:`inet_pton` is useful when a library or network protocol calls for
  287. an object of type :ctype:`struct in_addr` (similar to :func:`inet_aton`) or
  288. :ctype:`struct in6_addr`.
  289. Supported values for *address_family* are currently :const:`AF_INET` and
  290. :const:`AF_INET6`. If the IP address string *ip_string* is invalid,
  291. :exc:`socket.error` will be raised. Note that exactly what is valid depends on
  292. both the value of *address_family* and the underlying implementation of
  293. :cfunc:`inet_pton`.
  294. Availability: Unix (maybe not all platforms).
  295. """
  296. pass
  297. def inet_ntop(address_family,packed_ip):
  298. """
  299. Convert a packed IP address (a string of some number of characters) to its
  300. standard, family-specific string representation (for example, ``'7.10.0.5'`` or
  301. ``'5aef:2b::8'``) :func:`inet_ntop` is useful when a library or network protocol
  302. returns an object of type :ctype:`struct in_addr` (similar to :func:`inet_ntoa`)
  303. or :ctype:`struct in6_addr`.
  304. Supported values for *address_family* are currently :const:`AF_INET` and
  305. :const:`AF_INET6`. If the string *packed_ip* is not the correct length for the
  306. specified address family, :exc:`ValueError` will be raised. A
  307. :exc:`socket.error` is raised for errors from the call to :func:`inet_ntop`.
  308. Availability: Unix (maybe not all platforms).
  309. """
  310. pass
  311. def getdefaulttimeout():
  312. """
  313. Return the default timeout in floating seconds for new socket objects. A value
  314. of ``None`` indicates that new socket objects have no timeout. When the socket
  315. module is first imported, the default is ``None``.
  316. """
  317. pass
  318. def setdefaulttimeout(timeout):
  319. """
  320. Set the default timeout in floating seconds for new socket objects. A value of
  321. ``None`` indicates that new socket objects have no timeout. When the socket
  322. module is first imported, the default is ``None``.
  323. """
  324. pass