Merge branch 'master' of https://github.com/liris/websocket-client
This commit is contained in:
@@ -102,6 +102,12 @@ class WebSocketTest(unittest.TestCase):
|
|||||||
self.assertEquals(p[2], "/r")
|
self.assertEquals(p[2], "/r")
|
||||||
self.assertEquals(p[3], True)
|
self.assertEquals(p[3], True)
|
||||||
|
|
||||||
|
p = ws._parse_url("wss://www.example.com:8080/r?key=value")
|
||||||
|
self.assertEquals(p[0], "www.example.com")
|
||||||
|
self.assertEquals(p[1], 8080)
|
||||||
|
self.assertEquals(p[2], "/r?key=value")
|
||||||
|
self.assertEquals(p[3], True)
|
||||||
|
|
||||||
self.assertRaises(ValueError, ws._parse_url, "http://www.example.com/r")
|
self.assertRaises(ValueError, ws._parse_url, "http://www.example.com/r")
|
||||||
|
|
||||||
def testWSKey(self):
|
def testWSKey(self):
|
||||||
|
14
websocket.py
14
websocket.py
@@ -131,6 +131,9 @@ def _parse_url(url):
|
|||||||
else:
|
else:
|
||||||
resource = "/"
|
resource = "/"
|
||||||
|
|
||||||
|
if parsed.query:
|
||||||
|
resource += "?" + parsed.query
|
||||||
|
|
||||||
return (hostname, port, resource, is_secure)
|
return (hostname, port, resource, is_secure)
|
||||||
|
|
||||||
def create_connection(url, timeout=None, **options):
|
def create_connection(url, timeout=None, **options):
|
||||||
@@ -141,10 +144,12 @@ def create_connection(url, timeout=None, **options):
|
|||||||
Passing optional timeout parameter will set the timeout on the socket.
|
Passing optional timeout parameter will set the timeout on the socket.
|
||||||
If no timeout is supplied, the global default timeout setting returned by getdefauttimeout() is used.
|
If no timeout is supplied, the global default timeout setting returned by getdefauttimeout() is used.
|
||||||
You can customize using 'options'.
|
You can customize using 'options'.
|
||||||
If you set "headers" dict object, you can set your own custom header.
|
If you set "header" dict object, you can set your own custom header.
|
||||||
|
|
||||||
>>> conn = create_connection("ws://echo.websocket.org/",
|
>>> conn = create_connection("ws://echo.websocket.org/",
|
||||||
... headers={"User-Agent": "MyProgram"})
|
... header={"User-Agent: MyProgram",
|
||||||
|
... "x-custom: header"})
|
||||||
|
|
||||||
|
|
||||||
timeout: socket timeout time. This value is integer.
|
timeout: socket timeout time. This value is integer.
|
||||||
if you set None for this value, it means "use default_timeout value"
|
if you set None for this value, it means "use default_timeout value"
|
||||||
@@ -363,11 +368,12 @@ class WebSocket(object):
|
|||||||
"""
|
"""
|
||||||
Connect to url. url is websocket url scheme. ie. ws://host:port/resource
|
Connect to url. url is websocket url scheme. ie. ws://host:port/resource
|
||||||
You can customize using 'options'.
|
You can customize using 'options'.
|
||||||
If you set "headers" dict object, you can set your own custom header.
|
If you set "header" dict object, you can set your own custom header.
|
||||||
|
|
||||||
>>> ws = WebSocket()
|
>>> ws = WebSocket()
|
||||||
>>> ws.connect("ws://echo.websocket.org/",
|
>>> ws.connect("ws://echo.websocket.org/",
|
||||||
... headers={"User-Agent": "MyProgram"})
|
... header={"User-Agent: MyProgram",
|
||||||
|
... "x-custom: header"})
|
||||||
|
|
||||||
timeout: socket timeout time. This value is integer.
|
timeout: socket timeout time. This value is integer.
|
||||||
if you set None for this value,
|
if you set None for this value,
|
||||||
|
Reference in New Issue
Block a user