diff --git a/scripts/tinytinypy b/scripts/tinytinypy index 58aed41..b422934 100644 --- a/scripts/tinytinypy +++ b/scripts/tinytinypy @@ -47,7 +47,7 @@ def parse(args): return configure_parser().parse_args(args=args) def main(): - URL_REGEX = re.compile(r'^(?P(https?://)?)(?P[^:/ ]+)(:(?P\d+))?(?P.*)$') + URL_REGEX = re.compile(r'^(?P[a-z]+://)?(?P[^:/ ]+)(:(?P\d+))?(?P.*)$') # Retrieve args from config and shell storedArgs = sys.argv.copy() storedArgs.pop(0) @@ -65,11 +65,11 @@ def main(): raise ValueError("Password is missing!") # TODO make more beautiful for user # Parse url urlM = URL_REGEX.match(args.url).groupdict() + proto = urlM.get('proto') or 'https' host = urlM['host'] # Call api - # TODO Support scheme (http / https) # TODO Support port - server = Connection(host) + server = Connection(proto=proto, host=host) server.login(args.user, passwd) args.func(server, args) diff --git a/tinytinypy/main.py b/tinytinypy/main.py index c8e85f0..73e5a86 100644 --- a/tinytinypy/main.py +++ b/tinytinypy/main.py @@ -98,13 +98,14 @@ class Connection: } def __init__(self, proto, host, endpoint="/api/"): - if proto not in SUPPORTED_PROTO: + protos = self.__class__.SUPPORTED_PROTO + if proto not in protos: raise ValueError(f"Protocol '{proto}' not supported") self._proto = proto self._host = host self._endpoint = endpoint self._sid = None - self.__conn = SUPPORTED_PROTO[proto](host=host) + self.__conn = protos[proto](host=host) atexit.register(lambda: self.__conn.close()) def __raiseError(self, op, info):