remove '_ws' from parse_ws_url, create_ws_url

This commit is contained in:
meejah
2016-03-30 11:02:19 -06:00
parent b04d030562
commit c6ca54d794
7 changed files with 47 additions and 47 deletions

View File

@@ -31,7 +31,7 @@ import six
from autobahn.wamp import protocol
from autobahn.wamp.types import ComponentConfig
from autobahn.websocket.util import parse_ws_url
from autobahn.websocket.util import parse_url
from autobahn.asyncio.websocket import WampWebSocketClientFactory
try:
@@ -127,7 +127,7 @@ class ApplicationRunner(object):
else:
return session
isSecure, host, port, resource, path, params = parse_ws_url(self.url)
isSecure, host, port, resource, path, params = parse_url(self.url)
if self.ssl is None:
ssl = isSecure

View File

@@ -34,7 +34,7 @@ from twisted.internet.defer import inlineCallbacks
from autobahn.wamp import protocol
from autobahn.wamp.types import ComponentConfig
from autobahn.websocket.util import parse_ws_url
from autobahn.websocket.util import parse_url
from autobahn.twisted.websocket import WampWebSocketClientFactory
# new API
@@ -159,7 +159,7 @@ class ApplicationRunner(object):
txaio.config.loop = reactor
txaio.start_logging(level='info')
isSecure, host, port, resource, path, params = parse_ws_url(self.url)
isSecure, host, port, resource, path, params = parse_url(self.url)
# factory for use ApplicationSession
def create():
@@ -574,7 +574,7 @@ if service:
"""
Setup the application component.
"""
is_secure, host, port, resource, path, params = parse_ws_url(self.url)
is_secure, host, port, resource, path, params = parse_url(self.url)
# factory for use ApplicationSession
def create():

View File

@@ -33,7 +33,7 @@ import six
import txaio
from autobahn.util import ObservableMixin
from autobahn.websocket.util import parse_ws_url
from autobahn.websocket.util import parse_url
from autobahn.wamp.types import ComponentConfig
__all__ = ('Connection')
@@ -190,7 +190,7 @@ class Component(ObservableMixin):
# allows to provide an URL instead of a list of transports
if type(transports) == six.text_type:
url = transports
is_secure, host, port, resource, path, params = parse_ws_url(url)
is_secure, host, port, resource, path, params = parse_url(url)
transport = {
'type': 'websocket',
'url': url,

View File

@@ -52,7 +52,7 @@ from autobahn.util import Stopwatch, newid, wildcards2patterns, encode_truncate
from autobahn.websocket.utf8validator import Utf8Validator
from autobahn.websocket.xormasker import XorMaskerNull, createXorMasker
from autobahn.websocket.compress import PERMESSAGE_COMPRESSION_EXTENSION
from autobahn.websocket.util import parse_ws_url
from autobahn.websocket.util import parse_url
from six.moves import urllib
import txaio
@@ -2929,7 +2929,7 @@ class WebSocketServerFactory(WebSocketFactory):
:type externalPort: int
"""
# parse WebSocket URI into components
(isSecure, host, port, resource, path, params) = parse_ws_url(url or "ws://localhost")
(isSecure, host, port, resource, path, params) = parse_url(url or "ws://localhost")
if len(params) > 0:
raise Exception("query parameters specified for server WebSocket URL")
self.url = url
@@ -3656,7 +3656,7 @@ class WebSocketClientFactory(WebSocketFactory):
:type proxy: dict or None
"""
# parse WebSocket URI into components
(isSecure, host, port, resource, path, params) = parse_ws_url(url or "ws://localhost")
(isSecure, host, port, resource, path, params) = parse_url(url or "ws://localhost")
self.url = url
self.isSecure = isSecure
self.host = host

View File

@@ -28,100 +28,100 @@ from __future__ import absolute_import
import unittest2 as unittest
from autobahn.websocket.util import create_ws_url, parse_ws_url
from autobahn.websocket.util import create_url, parse_url
class TestCreateWsUrl(unittest.TestCase):
def test_create_url01(self):
self.assertEqual(create_ws_url("localhost"), "ws://localhost:80/")
self.assertEqual(create_url("localhost"), "ws://localhost:80/")
def test_create_url02(self):
self.assertEqual(create_ws_url("localhost", port=8090), "ws://localhost:8090/")
self.assertEqual(create_url("localhost", port=8090), "ws://localhost:8090/")
def test_create_url03(self):
self.assertEqual(create_ws_url("localhost", path="ws"), "ws://localhost:80/ws")
self.assertEqual(create_url("localhost", path="ws"), "ws://localhost:80/ws")
def test_create_url04(self):
self.assertEqual(create_ws_url("localhost", path="/ws"), "ws://localhost:80/ws")
self.assertEqual(create_url("localhost", path="/ws"), "ws://localhost:80/ws")
def test_create_url05(self):
self.assertEqual(create_ws_url("localhost", path="/ws/foobar"), "ws://localhost:80/ws/foobar")
self.assertEqual(create_url("localhost", path="/ws/foobar"), "ws://localhost:80/ws/foobar")
def test_create_url06(self):
self.assertEqual(create_ws_url("localhost", isSecure=True), "wss://localhost:443/")
self.assertEqual(create_url("localhost", isSecure=True), "wss://localhost:443/")
def test_create_url07(self):
self.assertEqual(create_ws_url("localhost", isSecure=True, port=443), "wss://localhost:443/")
self.assertEqual(create_url("localhost", isSecure=True, port=443), "wss://localhost:443/")
def test_create_url08(self):
self.assertEqual(create_ws_url("localhost", isSecure=True, port=80), "wss://localhost:80/")
self.assertEqual(create_url("localhost", isSecure=True, port=80), "wss://localhost:80/")
def test_create_url09(self):
self.assertEqual(create_ws_url("localhost", isSecure=True, port=9090, path="ws", params={'foo': 'bar'}), "wss://localhost:9090/ws?foo=bar")
self.assertEqual(create_url("localhost", isSecure=True, port=9090, path="ws", params={'foo': 'bar'}), "wss://localhost:9090/ws?foo=bar")
def test_create_url10(self):
wsurl = create_ws_url("localhost", isSecure=True, port=9090, path="ws", params={'foo': 'bar', 'moo': 23})
wsurl = create_url("localhost", isSecure=True, port=9090, path="ws", params={'foo': 'bar', 'moo': 23})
self.assertTrue(wsurl == "wss://localhost:9090/ws?foo=bar&moo=23" or wsurl == "wss://localhost:9090/ws?moo=23&foo=bar")
def test_create_url11(self):
self.assertEqual(create_ws_url("127.0.0.1", path="ws"), "ws://127.0.0.1:80/ws")
self.assertEqual(create_url("127.0.0.1", path="ws"), "ws://127.0.0.1:80/ws")
def test_create_url12(self):
self.assertEqual(create_ws_url("62.146.25.34", path="ws"), "ws://62.146.25.34:80/ws")
self.assertEqual(create_url("62.146.25.34", path="ws"), "ws://62.146.25.34:80/ws")
def test_create_url13(self):
self.assertEqual(create_ws_url("subsub1.sub1.something.com", path="ws"), "ws://subsub1.sub1.something.com:80/ws")
self.assertEqual(create_url("subsub1.sub1.something.com", path="ws"), "ws://subsub1.sub1.something.com:80/ws")
def test_create_url14(self):
self.assertEqual(create_ws_url("::1", path="ws"), "ws://::1:80/ws")
self.assertEqual(create_url("::1", path="ws"), "ws://::1:80/ws")
def test_create_url15(self):
self.assertEqual(create_ws_url("0:0:0:0:0:0:0:1", path="ws"), "ws://0:0:0:0:0:0:0:1:80/ws")
self.assertEqual(create_url("0:0:0:0:0:0:0:1", path="ws"), "ws://0:0:0:0:0:0:0:1:80/ws")
class TestParseWsUrl(unittest.TestCase):
# parse_ws_url -> (isSecure, host, port, resource, path, params)
# parse_url -> (isSecure, host, port, resource, path, params)
def test_parse_url01(self):
self.assertEqual(parse_ws_url("ws://localhost"), (False, 'localhost', 80, '/', '/', {}))
self.assertEqual(parse_url("ws://localhost"), (False, 'localhost', 80, '/', '/', {}))
def test_parse_url02(self):
self.assertEqual(parse_ws_url("ws://localhost:80"), (False, 'localhost', 80, '/', '/', {}))
self.assertEqual(parse_url("ws://localhost:80"), (False, 'localhost', 80, '/', '/', {}))
def test_parse_url03(self):
self.assertEqual(parse_ws_url("wss://localhost"), (True, 'localhost', 443, '/', '/', {}))
self.assertEqual(parse_url("wss://localhost"), (True, 'localhost', 443, '/', '/', {}))
def test_parse_url04(self):
self.assertEqual(parse_ws_url("wss://localhost:443"), (True, 'localhost', 443, '/', '/', {}))
self.assertEqual(parse_url("wss://localhost:443"), (True, 'localhost', 443, '/', '/', {}))
def test_parse_url05(self):
self.assertEqual(parse_ws_url("wss://localhost/ws"), (True, 'localhost', 443, '/ws', '/ws', {}))
self.assertEqual(parse_url("wss://localhost/ws"), (True, 'localhost', 443, '/ws', '/ws', {}))
def test_parse_url06(self):
self.assertEqual(parse_ws_url("wss://localhost/ws?foo=bar"), (True, 'localhost', 443, '/ws?foo=bar', '/ws', {'foo': ['bar']}))
self.assertEqual(parse_url("wss://localhost/ws?foo=bar"), (True, 'localhost', 443, '/ws?foo=bar', '/ws', {'foo': ['bar']}))
def test_parse_url07(self):
self.assertEqual(parse_ws_url("wss://localhost/ws?foo=bar&moo=23"), (True, 'localhost', 443, '/ws?foo=bar&moo=23', '/ws', {'moo': ['23'], 'foo': ['bar']}))
self.assertEqual(parse_url("wss://localhost/ws?foo=bar&moo=23"), (True, 'localhost', 443, '/ws?foo=bar&moo=23', '/ws', {'moo': ['23'], 'foo': ['bar']}))
def test_parse_url08(self):
self.assertEqual(parse_ws_url("wss://localhost/ws?foo=bar&moo=23&moo=44"), (True, 'localhost', 443, '/ws?foo=bar&moo=23&moo=44', '/ws', {'moo': ['23', '44'], 'foo': ['bar']}))
self.assertEqual(parse_url("wss://localhost/ws?foo=bar&moo=23&moo=44"), (True, 'localhost', 443, '/ws?foo=bar&moo=23&moo=44', '/ws', {'moo': ['23', '44'], 'foo': ['bar']}))
def test_parse_url09(self):
self.assertRaises(Exception, parse_ws_url, "http://localhost")
self.assertRaises(Exception, parse_url, "http://localhost")
def test_parse_url10(self):
self.assertRaises(Exception, parse_ws_url, "https://localhost")
self.assertRaises(Exception, parse_url, "https://localhost")
def test_parse_url11(self):
self.assertRaises(Exception, parse_ws_url, "http://localhost:80")
self.assertRaises(Exception, parse_url, "http://localhost:80")
def test_parse_url12(self):
self.assertRaises(Exception, parse_ws_url, "http://localhost#frag1")
self.assertRaises(Exception, parse_url, "http://localhost#frag1")
def test_parse_url13(self):
self.assertRaises(Exception, parse_ws_url, "wss://")
self.assertRaises(Exception, parse_url, "wss://")
def test_parse_url14(self):
self.assertRaises(Exception, parse_ws_url, "ws://")
self.assertRaises(Exception, parse_url, "ws://")

View File

@@ -51,11 +51,11 @@ urlparse.uses_query.extend(wsschemes)
urlparse.uses_fragment.extend(wsschemes)
__all__ = (
"create_ws_url",
"parse_ws_url",
"create_url",
"parse_url",
)
def create_ws_url(hostname, port=None, isSecure=False, path=None, params=None):
def create_url(hostname, port=None, isSecure=False, path=None, params=None):
"""
Create a WebSocket URL from components.
@@ -102,7 +102,7 @@ def create_ws_url(hostname, port=None, isSecure=False, path=None, params=None):
return urllib.parse.urlunparse((scheme, netloc, ppath, None, query, None))
def parse_ws_url(url):
def parse_url(url):
"""
Parses as WebSocket URL into it's components and returns a tuple (isSecure, host, port, resource, path, params).

View File

@@ -63,7 +63,7 @@ from twisted.internet.protocol import Factory
from twisted.web.server import Site
from twisted.web.static import File
from autobahn.websocket.util import parse_ws_url
from autobahn.websocket.util import parse_url
from autobahn.twisted.websocket import WebSocketServerFactory, \
WebSocketServerProtocol
@@ -377,7 +377,7 @@ if __name__ == '__main__':
# parse WS URI into components and forward via options
# FIXME: add TLS support
isSecure, host, wsport, resource, path, params = parse_ws_url(options.wsuri)
isSecure, host, wsport, resource, path, params = parse_url(options.wsuri)
options.wsport = wsport
# if not options.silence: