diff options
| author | engn33r <engn33r@users.noreply.github.com> | 2021-01-31 12:20:31 -0500 |
|---|---|---|
| committer | engn33r <engn33r@users.noreply.github.com> | 2021-01-31 12:20:31 -0500 |
| commit | aace06b24fef03d6d8f2c6d16c2e23325360c67b (patch) | |
| tree | 94fbf3181fc007f18ee28e7d66302f74cf93b4d3 /websocket | |
| parent | 15a92eed55cbdb2f389aa4059cc2b1fc9551edc5 (diff) | |
| download | websocket-client-aace06b24fef03d6d8f2c6d16c2e23325360c67b.tar.gz | |
Add first draft of Sphinx documentation
Diffstat (limited to 'websocket')
| -rw-r--r-- | websocket/_abnf.py | 46 | ||||
| -rw-r--r-- | websocket/_app.py | 166 | ||||
| -rw-r--r-- | websocket/_core.py | 279 | ||||
| -rw-r--r-- | websocket/_exceptions.py | 16 | ||||
| -rw-r--r-- | websocket/_handshake.py | 2 | ||||
| -rw-r--r-- | websocket/_logging.py | 11 | ||||
| -rw-r--r-- | websocket/_socket.py | 16 | ||||
| -rw-r--r-- | websocket/_url.py | 49 |
8 files changed, 371 insertions, 214 deletions
diff --git a/websocket/_abnf.py b/websocket/_abnf.py index a0000fa..ff3b3cf 100644 --- a/websocket/_abnf.py +++ b/websocket/_abnf.py @@ -1,4 +1,8 @@ """ + +""" + +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -105,7 +109,7 @@ VALID_CLOSE_STATUS = ( class ABNF(object): """ ABNF frame class. - see http://tools.ietf.org/html/rfc5234 + See http://tools.ietf.org/html/rfc5234 and http://tools.ietf.org/html/rfc6455#section-5.2 """ @@ -139,8 +143,7 @@ class ABNF(object): def __init__(self, fin=0, rsv1=0, rsv2=0, rsv3=0, opcode=OPCODE_TEXT, mask=1, data=""): """ - Constructor for ABNF. - please check RFC for arguments. + Constructor for ABNF. Please check RFC for arguments. """ self.fin = fin self.rsv1 = rsv1 @@ -155,7 +158,10 @@ class ABNF(object): def validate(self, skip_utf8_validation=False): """ - validate the ABNF frame. + Validate the ABNF frame. + + Parameters + ---------- skip_utf8_validation: skip utf8 validation. """ if self.rsv1 or self.rsv2 or self.rsv3: @@ -193,15 +199,18 @@ class ABNF(object): @staticmethod def create_frame(data, opcode, fin=1): """ - create frame to send text, binary and other data. + Create frame to send text, binary and other data. - data: data to send. This is string value(byte array). - if opcode is OPCODE_TEXT and this value is unicode, + Parameters + ---------- + data: <type> + data to send. This is string value(byte array). + If opcode is OPCODE_TEXT and this value is unicode, data value is converted into unicode string, automatically. - - opcode: operation code. please see OPCODE_XXX. - - fin: fin flag. if set to 0, create continue fragmentation. + opcode: <type> + operation code. please see OPCODE_XXX. + fin: <type> + fin flag. if set to 0, create continue fragmentation. """ if opcode == ABNF.OPCODE_TEXT and isinstance(data, six.text_type): data = data.encode("utf-8") @@ -210,7 +219,7 @@ class ABNF(object): def format(self): """ - format this object to string(byte array) to send data to server. + Format this object to string(byte array) to send data to server. """ if any(x not in (0, 1) for x in [self.fin, self.rsv1, self.rsv2, self.rsv3]): raise ValueError("not 0 or 1") @@ -252,11 +261,14 @@ class ABNF(object): @staticmethod def mask(mask_key, data): """ - mask or unmask data. Just do xor for each byte - - mask_key: 4 byte string(byte). - - data: data to mask/unmask. + Mask or unmask data. Just do xor for each byte + + Parameters + ---------- + mask_key: <type> + 4 byte string(byte). + data: <type> + data to mask/unmask. """ if data is None: data = "" diff --git a/websocket/_app.py b/websocket/_app.py index bbf64f5..9b94c77 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -1,4 +1,8 @@ """ + +""" + +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -19,10 +23,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - -""" -WebSocketApp provides higher level APIs. -""" import inspect import select import sys @@ -41,6 +41,9 @@ from . import _logging __all__ = ["WebSocketApp"] class Dispatcher: + """ + Dispatcher + """ def __init__(self, app, ping_timeout): self.app = app self.ping_timeout = ping_timeout @@ -55,6 +58,9 @@ class Dispatcher: check_callback() class SSLDispatcher: + """ + SSLDispatcher + """ def __init__(self, app, ping_timeout): self.app = app self.ping_timeout = ping_timeout @@ -78,8 +84,7 @@ class SSLDispatcher: class WebSocketApp(object): """ - Higher level of APIs are provided. - The interface is like JavaScript WebSocket object. + Higher level of APIs are provided. The interface is like JavaScript WebSocket object. """ def __init__(self, url, header=None, @@ -90,39 +95,54 @@ class WebSocketApp(object): subprotocols=None, on_data=None): """ - url: websocket url. - header: custom header for websocket handshake. - on_open: callable object which is called at opening websocket. - this function has one argument. The argument is this class object. - on_message: callable object which is called when received data. - on_message has 2 arguments. - The 1st argument is this class object. - The 2nd argument is utf-8 string which we get from the server. - on_error: callable object which is called when we get error. - on_error has 2 arguments. - The 1st argument is this class object. - The 2nd argument is exception object. - on_close: callable object which is called when closed the connection. - this function has one argument. The argument is this class object. - on_cont_message: callback object which is called when receive continued - frame data. - on_cont_message has 3 arguments. - The 1st argument is this class object. - The 2nd argument is utf-8 string which we get from the server. - The 3rd argument is continue flag. if 0, the data continue - to next frame data - on_data: callback object which is called when a message received. - This is called before on_message or on_cont_message, - and then on_message or on_cont_message is called. - on_data has 4 argument. - The 1st argument is this class object. - The 2nd argument is utf-8 string which we get from the server. - The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came. - The 4th argument is continue flag. if 0, the data continue - keep_running: this parameter is obsolete and ignored. - get_mask_key: a callable to produce new mask keys, - see the WebSocket.set_mask_key's docstring for more information - subprotocols: array of available sub protocols. default is None. + WebSocketApp initialization + + Parameters + ---------- + url: <type> + websocket url. + header: <type> + custom header for websocket handshake. + on_open: <type> + callable object which is called at opening websocket. + this function has one argument. The argument is this class object. + on_message: <type> + callable object which is called when received data. + on_message has 2 arguments. + The 1st argument is this class object. + The 2nd argument is utf-8 string which we get from the server. + on_error: <type> + callable object which is called when we get error. + on_error has 2 arguments. + The 1st argument is this class object. + The 2nd argument is exception object. + on_close: <type> + callable object which is called when closed the connection. + this function has one argument. The argument is this class object. + on_cont_message: <type> + callback object which is called when receive continued + frame data. + on_cont_message has 3 arguments. + The 1st argument is this class object. + The 2nd argument is utf-8 string which we get from the server. + The 3rd argument is continue flag. if 0, the data continue + to next frame data + on_data: <type> + callback object which is called when a message received. + This is called before on_message or on_cont_message, + and then on_message or on_cont_message is called. + on_data has 4 argument. + The 1st argument is this class object. + The 2nd argument is utf-8 string which we get from the server. + The 3rd argument is data type. ABNF.OPCODE_TEXT or ABNF.OPCODE_BINARY will be came. + The 4th argument is continue flag. if 0, the data continue + keep_running: <type> + this parameter is obsolete and ignored. + get_mask_key: <type> + a callable to produce new mask keys, + see the WebSocket.set_mask_key's docstring for more information + subprotocols: <type> + array of available sub protocols. default is None. """ self.url = url self.header = header if header is not None else [] @@ -145,10 +165,15 @@ class WebSocketApp(object): def send(self, data, opcode=ABNF.OPCODE_TEXT): """ - send message. - data: message to send. If you set opcode to OPCODE_TEXT, - data must be utf-8 string or unicode. - opcode: operation code of data. default is OPCODE_TEXT. + send message + + Parameters + ---------- + data: <type> + Message to send. If you set opcode to OPCODE_TEXT, + data must be utf-8 string or unicode. + opcode: <type> + Operation code of data. default is OPCODE_TEXT. """ if not self.sock or self.sock.send(data, opcode) == 0: @@ -157,7 +182,7 @@ class WebSocketApp(object): def close(self, **kwargs): """ - close websocket connection. + Close websocket connection. """ self.keep_running = False if self.sock: @@ -182,29 +207,45 @@ class WebSocketApp(object): host=None, origin=None, dispatcher=None, suppress_origin=False, proxy_type=None): """ - run event loop for WebSocket framework. + Run event loop for WebSocket framework. + This loop is infinite loop and is alive during websocket is available. - sockopt: values for socket.setsockopt. + + Parameters + ---------- + sockopt: <type> + values for socket.setsockopt. sockopt must be tuple and each element is argument of sock.setsockopt. - sslopt: ssl socket optional dict. - ping_interval: automatically send "ping" command + sslopt: <type> + ssl socket optional dict. + ping_interval: <type> + automatically send "ping" command every specified period(second) if set to 0, not send automatically. - ping_timeout: timeout(second) if the pong message is not received. - http_proxy_host: http proxy host name. - http_proxy_port: http proxy port. If not set, set to 80. - http_no_proxy: host names, which doesn't use proxy. - skip_utf8_validation: skip utf8 validation. - host: update host header. - origin: update origin header. - dispatcher: customize reading data from socket. - suppress_origin: suppress outputting origin header. + ping_timeout: <type> + timeout(second) if the pong message is not received. + http_proxy_host: <type> + http proxy host name. + http_proxy_port: <type> + http proxy port. If not set, set to 80. + http_no_proxy: <type> + host names, which doesn't use proxy. + skip_utf8_validation: bool + skip utf8 validation. + host: <type> + update host header. + origin: <type> + update origin header. + dispatcher: <type> + customize reading data from socket. + suppress_origin: <type> + suppress outputting origin header. Returns ------- - False if caught KeyboardInterrupt - True if other exception was raised during a loop + teardown: bool + False if caught KeyboardInterrupt, True if other exception was raised during a loop """ if ping_timeout is not None and ping_timeout <= 0: @@ -225,6 +266,7 @@ class WebSocketApp(object): def teardown(close_frame=None): """ Tears down the connection. + If close_frame is set, we will invoke the on_close handler with the statusCode and reason from there. """ @@ -320,8 +362,10 @@ class WebSocketApp(object): return Dispatcher(self, timeout) def _get_close_args(self, data): - """ this functions extracts the code, reason from the close body - if they exists, and if the self.on_close except three arguments """ + """ + _get_close_args extracts the code, reason from the close body + if they exists, and if the self.on_close except three arguments + """ # if the on_close callback is "old", just return empty list if sys.version_info < (3, 0): if not self.on_close or len(inspect.getargspec(self.on_close).args) != 3: diff --git a/websocket/_core.py b/websocket/_core.py index 5723936..5268f8d 100644 --- a/websocket/_core.py +++ b/websocket/_core.py @@ -1,3 +1,10 @@ +from __future__ import print_function +""" +_core.py +==================================== +WebSocket Python client +""" + """ websocket - WebSocket client library for Python @@ -19,8 +26,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ -from __future__ import print_function - import socket import struct import threading @@ -40,21 +45,11 @@ from ._utils import * __all__ = ['WebSocket', 'create_connection'] -""" -websocket python client. -========================= - -This version support only hybi-13. -Please see http://tools.ietf.org/html/rfc6455 for protocol. -""" - - class WebSocket(object): """ Low level WebSocket interface. - This class is based on - The WebSocket protocol draft-hixie-thewebsocketprotocol-76 - http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76 + + This class is based on the WebSocket protocol `draft-hixie-thewebsocketprotocol-76 <http://tools.ietf.org/html/draft-hixie-thewebsocketprotocol-76>`_ We can connect to the websocket server and send/receive data. The following example is an echo client. @@ -67,14 +62,22 @@ class WebSocket(object): 'Hello, Server' >>> ws.close() - get_mask_key: a callable to produce new mask keys, see the set_mask_key - function's docstring for more details - sockopt: values for socket.setsockopt. + Parameters + ---------- + get_mask_key: func + a callable to produce new mask keys, see the set_mask_key + function's docstring for more details + sockopt: tuple + values for socket.setsockopt. sockopt must be tuple and each element is argument of sock.setsockopt. - sslopt: dict object for ssl socket option. - fire_cont_frame: fire recv event for each cont frame. default is False - enable_multithread: if set to True, lock send method. - skip_utf8_validation: skip utf8 validation. + sslopt: dict + dict object for ssl socket option. + fire_cont_frame: bool + fire recv event for each cont frame. default is False + enable_multithread: bool + if set to True, lock send method. + skip_utf8_validation: bool + skip utf8 validation. """ def __init__(self, get_mask_key=None, sockopt=None, sslopt=None, @@ -82,6 +85,10 @@ class WebSocket(object): skip_utf8_validation=False, **_): """ Initialize WebSocket object. + + Parameters + ---------- + sslopt: specify ssl certification verification options """ self.sock_opt = sock_opt(sockopt, sslopt) self.handshake_response = None @@ -119,13 +126,16 @@ class WebSocket(object): def set_mask_key(self, func): """ - set function to create musk key. You can customize mask key generator. + Set function to create mask key. You can customize mask key generator. Mainly, this is for testing purpose. - func: callable object. the func takes 1 argument as integer. - The argument means length of mask key. - This func must return string(byte array), - which length is argument specified. + Parameters + ---------- + func: func + callable object. the func takes 1 argument as integer. + The argument means length of mask key. + This func must return string(byte array), + which length is argument specified. """ self.get_mask_key = func @@ -139,7 +149,10 @@ class WebSocket(object): """ Set the timeout to the websocket. - timeout: timeout time (in seconds). This value could be either float/integer. + Parameters + ---------- + timeout: int or float + timeout time (in seconds). This value could be either float/integer. """ self.sock_opt.timeout = timeout if self.sock: @@ -149,7 +162,7 @@ class WebSocket(object): def getsubprotocol(self): """ - get subprotocol + Get subprotocol """ if self.handshake_response: return self.handshake_response.subprotocol @@ -160,7 +173,7 @@ class WebSocket(object): def getstatus(self): """ - get handshake status + Get handshake status """ if self.handshake_response: return self.handshake_response.status @@ -171,7 +184,7 @@ class WebSocket(object): def getheaders(self): """ - get handshake response header + Get handshake response header """ if self.handshake_response: return self.handshake_response.headers @@ -195,26 +208,37 @@ class WebSocket(object): ... header=["User-Agent: MyProgram", ... "x-custom: header"]) - timeout: socket timeout time. This value is integer. - if you set None for this value, - it means "use default_timeout value" - - options: "header" -> custom http header list or dict. - "cookie" -> cookie value. - "origin" -> custom origin url. - "suppress_origin" -> suppress outputting origin header. - "host" -> custom host header string. - "http_proxy_host" - http proxy host name. - "http_proxy_port" - http proxy port. If not set, set to 80. - "http_no_proxy" - host names, which doesn't use proxy. - "http_proxy_auth" - http proxy auth information. - tuple of username and password. - default is None - "redirect_limit" -> number of redirects to follow. - "subprotocols" - array of available sub protocols. - default is None. - "socket" - pre-initialized stream socket. - + timeout: <type> + socket timeout time. This value is integer. + if you set None for this value, it means "use default_timeout value" + + Parameters + ---------- + options: + - header: list or dict + custom http header list or dict. + - cookie: str + cookie value. + - origin: <type> + custom origin url. + - suppress_origin: <type> + suppress outputting origin header. + - host: <type> + custom host header string. + - http_proxy_host: <type> + http proxy host name. + - http_proxy_port: <type> + http proxy port. If not set, set to 80. + - http_no_proxy: <type> + host names, which doesn't use proxy. + - http_proxy_auth: <type> + http proxy auth information. tuple of username and password. default is None + - redirect_limit: <type> + number of redirects to follow. + - subprotocols: <type> + array of available sub protocols. default is None. + - socket: <type> + pre-initialized stream socket. """ # FIXME: "subprotocols" are getting lost, not passed down # FIXME: "header", "cookie", "origin" and "host" too @@ -242,11 +266,14 @@ class WebSocket(object): """ Send the data as string. - payload: Payload must be utf-8 string or unicode, + Parameters + ---------- + payload: <type> + Payload must be utf-8 string or unicode, if the opcode is OPCODE_TEXT. Otherwise, it must be string(byte array) - - opcode: operation code to send. Please see OPCODE_XXX. + opcode: <type> + operation code to send. Please see OPCODE_XXX. """ frame = ABNF.create_frame(payload, opcode) @@ -256,8 +283,6 @@ class WebSocket(object): """ Send the data frame. - frame: frame data created by ABNF.create_frame - >>> ws = create_connection("ws://echo.websocket.org/") >>> frame = ABNF.create_frame("Hello", ABNF.OPCODE_TEXT) >>> ws.send_frame(frame) @@ -266,6 +291,10 @@ class WebSocket(object): >>> cont_frame = ABNF.create_frame("Foo Bar", ABNF.OPCODE_CONT, 1) >>> ws.send_frame(frame) + Parameters + ---------- + frame: <type> + frame data created by ABNF.create_frame """ if self.get_mask_key: frame.get_mask_key = self.get_mask_key @@ -286,9 +315,12 @@ class WebSocket(object): def ping(self, payload=""): """ - send ping data. + Send ping data. - payload: data payload to send server. + Parameters + ---------- + payload: <type> + data payload to send server. """ if isinstance(payload, six.text_type): payload = payload.encode("utf-8") @@ -296,9 +328,12 @@ class WebSocket(object): def pong(self, payload): """ - send pong data. + Send pong data. - payload: data payload to send server. + Parameters + ---------- + payload: <type> + data payload to send server. """ if isinstance(payload, six.text_type): payload = payload.encode("utf-8") @@ -308,7 +343,9 @@ class WebSocket(object): """ Receive string data(byte array) from the server. - return value: string(byte array) value. + Returns + ---------- + data: string (byte array) value. """ with self.readlock: opcode, data = self.recv_data() @@ -323,10 +360,16 @@ class WebSocket(object): """ Receive data with operation code. - control_frame: a boolean flag indicating whether to return control frame - data, defaults to False + Parameters + ---------- + control_frame: bool + a boolean flag indicating whether to return control frame + data, defaults to False - return value: tuple of operation code and string(byte array) value. + Returns + ------- + opcode, frame.data: tuple + tuple of operation code and string(byte array) value. """ opcode, frame = self.recv_data_frame(control_frame) return opcode, frame.data @@ -335,10 +378,16 @@ class WebSocket(object): """ Receive data with operation code. - control_frame: a boolean flag indicating whether to return control frame - data, defaults to False + Parameters + ---------- + control_frame: bool + a boolean flag indicating whether to return control frame + data, defaults to False - return value: tuple of operation code and string(byte array) value. + Returns + ------- + frame.opcode, frame: tuple + tuple of operation code and string(byte array) value. """ while True: frame = self.recv_frame() @@ -371,19 +420,24 @@ class WebSocket(object): def recv_frame(self): """ - receive data as frame from server. + Receive data as frame from server. - return value: ABNF frame object. + Returns + ------- + self.frame_buffer.recv_frame(): ABNF frame object """ return self.frame_buffer.recv_frame() def send_close(self, status=STATUS_NORMAL, reason=six.b("")): """ - send close data to the server. - - status: status code to send. see STATUS_XXX. + Send close data to the server. - reason: the reason to close. This must be string or bytes. + Parameters + ---------- + status: <type> + status code to send. see STATUS_XXX. + reason: str or bytes + the reason to close. This must be string or bytes. """ if status < 0 or status >= ABNF.LENGTH_16: raise ValueError("code is invalid range") @@ -394,11 +448,14 @@ class WebSocket(object): """ Close Websocket object - status: status code to send. see STATUS_XXX. - - reason: the reason to close. This must be string. - - timeout: timeout until receive a close frame. + Parameters + ---------- + status: <type> + status code to send. see STATUS_XXX. + reason: <type> + the reason to close. This must be string. + timeout: <type> + timeout until receive a close frame. If None, it will wait forever until receive a close frame. """ if self.connected: @@ -439,7 +496,9 @@ class WebSocket(object): self.sock.shutdown(socket.SHUT_RDWR) def shutdown(self): - """close socket, immediately.""" + """ + close socket, immediately. + """ if self.sock: self.sock.close() self.sock = None @@ -461,7 +520,7 @@ class WebSocket(object): def create_connection(url, timeout=None, class_=WebSocket, **options): """ - connect to url and return websocket object. + Connect to url and return websocket object. Connect to url and return the WebSocket object. Passing optional timeout parameter will set the timeout on the socket. @@ -474,33 +533,49 @@ def create_connection(url, timeout=None, class_=WebSocket, **options): ... header=["User-Agent: MyProgram", ... "x-custom: header"]) - - timeout: socket timeout time. This value could be either float/integer. + Parameters + ---------- + timeout: <type> + socket timeout time. This value could be either float/integer. if you set None for this value, it means "use default_timeout value" - - class_: class to instantiate when creating the connection. It has to implement + class_: <type> + class to instantiate when creating the connection. It has to implement settimeout and connect. It's __init__ should be compatible with WebSocket.__init__, i.e. accept all of it's kwargs. - options: "header" -> custom http header list or dict. - "cookie" -> cookie value. - "origin" -> custom origin url. - "suppress_origin" -> suppress outputting origin header. - "host" -> custom host header string. - "http_proxy_host" - http proxy host name. - "http_proxy_port" - http proxy port. If not set, set to 80. - "http_no_proxy" - host names, which doesn't use proxy. - "http_proxy_auth" - http proxy auth information. - tuple of username and password. - default is None - "enable_multithread" -> enable lock for multithread. - "redirect_limit" -> number of redirects to follow. - "sockopt" -> socket options - "sslopt" -> ssl option - "subprotocols" - array of available sub protocols. - default is None. - "skip_utf8_validation" - skip utf8 validation. - "socket" - pre-initialized stream socket. + options: <type> + - header: <type> + custom http header list or dict. + - cookie: <type> + cookie value. + - origin: <type> + custom origin url. + - suppress_origin: <type> + suppress outputting origin header. + - host: <type> + custom host header string. + - http_proxy_host: <type> + http proxy host name. + - http_proxy_port: <type> + http proxy port. If not set, set to 80. + - http_no_proxy: <type> + host names, which doesn't use proxy. + - http_proxy_auth: <type> + http proxy auth information. tuple of username and password. default is None + - enable_multithread: <type> + enable lock for multithread. + - redirect_limit: <type> + number of redirects to follow. + - sockopt: <type> + socket options + - sslopt: <type> + ssl option + - subprotocols: <type> + array of available sub protocols. default is None. + - skip_utf8_validation: bool + skip utf8 validation. + - socket: <type> + pre-initialized stream socket. """ sockopt = options.pop("sockopt", []) sslopt = options.pop("sslopt", {}) diff --git a/websocket/_exceptions.py b/websocket/_exceptions.py index 2070790..ed84013 100644 --- a/websocket/_exceptions.py +++ b/websocket/_exceptions.py @@ -1,4 +1,8 @@ """ +Define WebSocket exceptions +""" + +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -20,29 +24,23 @@ Copyright (C) 2010 Hiroki Ohtani(liris) """ - -""" -define websocket exceptions -""" - - class WebSocketException(Exception): """ - websocket exception class. + WebSocket exception class. """ pass class WebSocketProtocolException(WebSocketException): """ - If the websocket protocol is invalid, this exception will be raised. + If the WebSocket protocol is invalid, this exception will be raised. """ pass class WebSocketPayloadException(WebSocketException): """ - If the websocket payload is invalid, this exception will be raised. + If the WebSocket payload is invalid, this exception will be raised. """ pass diff --git a/websocket/_handshake.py b/websocket/_handshake.py index b69b8b7..9ead737 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -115,7 +115,7 @@ def _get_handshake_headers(resource, host, port, options): headers.append("Origin: http://%s" % hostport) key = _create_sec_websocket_key() - + # Append Sec-WebSocket-Key & Sec-WebSocket-Version if not manually specified if not 'header' in options or 'Sec-WebSocket-Key' not in options['header']: key = _create_sec_websocket_key() diff --git a/websocket/_logging.py b/websocket/_logging.py index c947778..722b68c 100644 --- a/websocket/_logging.py +++ b/websocket/_logging.py @@ -1,4 +1,8 @@ """ + +""" + +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -39,9 +43,12 @@ __all__ = ["enableTrace", "dump", "error", "warning", "debug", "trace", def enableTrace(traceable, handler = logging.StreamHandler()): """ - turn on/off the traceability. + Turn on/off the traceability. - traceable: boolean value. if set True, traceability is enabled. + Parameters + ---------- + traceable: bool + If set to True, traceability is enabled. """ global _traceEnabled _traceEnabled = traceable diff --git a/websocket/_socket.py b/websocket/_socket.py index 7be3913..a3395ea 100644 --- a/websocket/_socket.py +++ b/websocket/_socket.py @@ -1,4 +1,8 @@ """ + +""" + +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -62,7 +66,10 @@ def setdefaulttimeout(timeout): """ Set the global timeout setting to connect. - timeout: default socket timeout time. This value is second. + Parameters + ---------- + timeout: <type> + default socket timeout time. This value is second. """ global _default_timeout _default_timeout = timeout @@ -70,7 +77,12 @@ def setdefaulttimeout(timeout): def getdefaulttimeout(): """ - Return the global timeout setting(second) to connect. + Get default timeout + + Returns + ---------- + _default_timeout: <type> + Return the global timeout setting (in seconds) to connect. """ return _default_timeout diff --git a/websocket/_url.py b/websocket/_url.py index a394fc3..bc66637 100644 --- a/websocket/_url.py +++ b/websocket/_url.py @@ -1,4 +1,7 @@ """ + +""" +""" websocket - WebSocket client library for Python Copyright (C) 2010 Hiroki Ohtani(liris) @@ -35,7 +38,10 @@ def parse_url(url): parse url and the result is tuple of (hostname, port, resource path and the flag of secure mode) - url: url string. + Parameters + ---------- + url: str + url string. """ if ":" not in url: raise ValueError("url is invalid") @@ -120,27 +126,30 @@ def get_proxy_info( hostname, is_secure, proxy_host=None, proxy_port=0, proxy_auth=None, no_proxy=None, proxy_type='http'): """ - try to retrieve proxy host and port from environment + Try to retrieve proxy host and port from environment if not provided in options. - result is (proxy_host, proxy_port, proxy_auth). + Result is (proxy_host, proxy_port, proxy_auth). proxy_auth is tuple of username and password - of proxy authentication information. - - hostname: websocket server name. - - is_secure: is the connection secure? (wss) - looks for "https_proxy" in env - before falling back to "http_proxy" - - options: "http_proxy_host" - http proxy host name. - "http_proxy_port" - http proxy port. - "http_no_proxy" - host names, which doesn't use proxy. - "http_proxy_auth" - http proxy auth information. - tuple of username and password. - default is None - "proxy_type" - if set to "socks5" PySocks wrapper - will be used in place of a http proxy. - default is "http" + of proxy authentication information. + + Parameters + ---------- + hostname: <type> + websocket server name. + is_secure: <type> + is the connection secure? (wss) looks for "https_proxy" in env + before falling back to "http_proxy" + options: <type> + - http_proxy_host: <type> + http proxy host name. + - http_proxy_port: <type> + http proxy port. + - http_no_proxy: <type> + host names, which doesn't use proxy. + - http_proxy_auth: <type> + http proxy auth information. tuple of username and password. default is None + - proxy_type: <type> + if set to "socks5" PySocks wrapper will be used in place of a http proxy. default is "http" """ if _is_no_proxy_host(hostname, no_proxy): return None, 0, None |
