1616from uuid import UUID , uuid4
1717
1818import requests , requests .exceptions
19- from requests .adapters import HTTPAdapter , DEFAULT_POOLBLOCK
19+ from requests .adapters import HTTPAdapter
2020from six .moves .urllib .parse import urlsplit , urlunsplit
2121from six .moves .urllib .error import HTTPError
2222
@@ -263,7 +263,8 @@ def __init__(self, hostname,
263263 swat .cas .rest .connection .REST_CASConnection ):
264264 import base64
265265
266- # Use the httpAddress action to retieve information about REST endpoints
266+ # Use the httpAddress action to retieve information about
267+ # REST endpoints
267268 httpAddress = hostname .get_action ('builtins.httpAddress' )
268269 address = httpAddress ()
269270 domain = address .virtualHost
@@ -273,18 +274,21 @@ def __init__(self, hostname,
273274 domain = hostname ._sw_connection ._current_hostname
274275 protocol = address .protocol
275276 port = address .port
276-
277- # protocol = hostname._protocol
278277 auth = hostname ._sw_connection ._auth .decode ('utf-8' ).replace (
279278 '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 (':' )
283281 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." )
286284 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 )
288292
289293 self ._settings = {'protocol' : protocol or 'https' ,
290294 'domain' : domain ,
0 commit comments