From ed0630aa7c9ae9d231ff5b52e3d0570839ad4e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 9 Mar 2016 12:40:13 +0100 Subject: [PATCH] Added parameter type checking for utils.join_url This made things a bit easier to debug, while re.sub() raises less descriptive errors. --- pillarsdk/utils.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pillarsdk/utils.py b/pillarsdk/utils.py index 888f1a5..900ef88 100644 --- a/pillarsdk/utils.py +++ b/pillarsdk/utils.py @@ -11,8 +11,10 @@ except ImportError: # from six: PY3 = sys.version_info[0] == 3 if PY3: + string_type = str text_type = str else: + string_type = basestring text_type = unicode @@ -25,7 +27,10 @@ def join_url(url, *paths): >>> join_url("pillar:5000", "shots") 'pillar:5000/shots' """ + + assert isinstance(url, string_type), 'URL must be string type, not %r' % url for path in paths: + assert isinstance(path, string_type), 'Path components must be string type, not %r' % path url = re.sub(r'/?$', re.sub(r'^/?', '/', path), url) return url