summaryrefslogtreecommitdiff
path: root/src/leap/util/web.py
diff options
context:
space:
mode:
authorkali <kali@leap.se>2012-11-09 18:13:32 +0900
committerkali <kali@leap.se>2012-11-09 18:13:32 +0900
commit8fd77ba036cb78c81939bbfce312b12cdc90d881 (patch)
tree80eabe6d7fcb34dfe25a3e0d2105523e0ab66437 /src/leap/util/web.py
parent1902e63cb4149316c5eab27ea8bf1721095d1a68 (diff)
working version of the fake provider.
wizard can now be completely tested against this.
Diffstat (limited to 'src/leap/util/web.py')
-rw-r--r--src/leap/util/web.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/leap/util/web.py b/src/leap/util/web.py
index 6ddf4b21..b2aef058 100644
--- a/src/leap/util/web.py
+++ b/src/leap/util/web.py
@@ -3,16 +3,37 @@ web related utilities
"""
+class UsageError(Exception):
+ """ """
+
+
def get_https_domain_and_port(full_domain):
"""
returns a tuple with domain and port
from a full_domain string that can
contain a colon
"""
+ if full_domain is None:
+ return None, None
+
+ https_sch = "https://"
+ http_sch = "http://"
+
+ if full_domain.startswith(https_sch):
+ full_domain = full_domain.lstrip(https_sch)
+ elif full_domain.startswith(http_sch):
+ raise UsageError(
+ "cannot be called with a domain "
+ "that begins with 'http://'")
+
domain_split = full_domain.split(':')
_len = len(domain_split)
if _len == 1:
domain, port = full_domain, 443
- if _len == 2:
+ elif _len == 2:
domain, port = domain_split
+ else:
+ raise UsageError(
+ "must be called with one only parameter"
+ "in the form domain[:port]")
return domain, port