16
16
from uuid import UUID , uuid4
17
17
18
18
import requests , requests .exceptions
19
- from requests .adapters import HTTPAdapter , DEFAULT_POOLBLOCK
19
+ from requests .adapters import HTTPAdapter
20
20
from six .moves .urllib .parse import urlsplit , urlunsplit
21
21
from six .moves .urllib .error import HTTPError
22
22
@@ -263,7 +263,8 @@ def __init__(self, hostname,
263
263
swat .cas .rest .connection .REST_CASConnection ):
264
264
import base64
265
265
266
- # Use the httpAddress action to retieve information about REST endpoints
266
+ # Use the httpAddress action to retieve information about
267
+ # REST endpoints
267
268
httpAddress = hostname .get_action ('builtins.httpAddress' )
268
269
address = httpAddress ()
269
270
domain = address .virtualHost
@@ -273,18 +274,21 @@ def __init__(self, hostname,
273
274
domain = hostname ._sw_connection ._current_hostname
274
275
protocol = address .protocol
275
276
port = address .port
276
-
277
- # protocol = hostname._protocol
278
277
auth = hostname ._sw_connection ._auth .decode ('utf-8' ).replace (
279
278
'Basic ' , '' )
280
- username , password = base64 .b64decode (auth ).decode ('utf-8' ).split (
281
- ':' )
282
- # domain = hostname._hostname
279
+ username , password = base64 .b64decode (auth ).decode (
280
+ 'utf-8' ).split (':' )
283
281
else :
284
- raise ValueError (
285
- "A 'swat.CAS' session can only be reused when it's connected via the REST APIs." )
282
+ raise ValueError ("A 'swat.CAS' session can only be reused "
283
+ " when it's connected via the REST APIs." )
286
284
else :
287
- domain = str (hostname )
285
+ url = urlsplit (hostname )
286
+
287
+ # Extract http/https from domain name if present and protocl not
288
+ # explicitly given
289
+ protocol = protocol or url .scheme
290
+
291
+ domain = url .hostname or str (hostname )
288
292
289
293
self ._settings = {'protocol' : protocol or 'https' ,
290
294
'domain' : domain ,
0 commit comments