yanyu-xin
2023-02-09
来自广东
from typing import NewType # 新建 UserId 类型 UserId = NewType('UserId', int) # 新建 Password 类型 UserPassword = NewType('UserPassword', str) # 新建 Protocol 类型 Protocol = NewType('Protocol', dict) def connect(ip:UserId, name=None:str, password=None:UserPassword, ports=None:int, keyt=None:int, http=None:Protocol, https=None:Protocol) -> bool : # 逐一判断输入参数 if agr_ok(ip, name, password, ports, keyt, http, https) : # 逐一连接服务器 if connect_ok(ip:UserId, name, password, ports, keyt, http, https) : return True return False def connect_ok(ip:UserId, name:str, password:UserPassword, ports:int, keyt:int, http:Protocol, https:Protocol) -> bool : ''' 逐一连接服务器''' if connect_1(ip, name, password, http) : return True if connect_2(ip, name, password, https) : return True if connect_3(ip, keyt, http) : return True if connect_4(ip, keyt, https) : return True if connect_5(ip, ports, name, password, http): return True if connect_6(ip, ports, name, password, https): return True if connect_7(ip, ports, keyt, http): return True if connect_8(ip, ports, keyt, https): return True return False def agr_ok(ip:UserId, name:str, password:UserPassword, ports:int, keyt:int, http:Protocol, https:Protocol) -> bool : ''' 逐一判断输入参数的格式''' if is_ip(ip) and \ is_name(name) and \ is_password(password) and \ is_ports(ports) and \ is_keyt(keyt) and \ is_https(https) and \ is_https(http) : return True return False
展开
2