本文整理汇总了Python中helpers.Helpers.formatToValidUrl方法的典型用法代码示例。如果您正苦于以下问题:Python Helpers.formatToValidUrl方法的具体用法?Python Helpers.formatToValidUrl怎么用?Python Helpers.formatToValidUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helpers.Helpers
的用法示例。
在下文中一共展示了Helpers.formatToValidUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from helpers import Helpers [as 别名]
# 或者: from helpers.Helpers import formatToValidUrl [as 别名]
class Services:
oHelpers = ""
servicesChecksFunc = {}
listDebugResultOk = []
listDebugResultError = []
listTextResultOk = []
listTextResultError = []
sErrorFlag = 'error'
def __init__(self):
""" Constructor """
self.oHelpers = Helpers()
self.servicesChecksFunc = {'tcp': self.checkTcpService, \
'http': self.checkHttpService, \
'ftp': self.checkFtpService \
}
def check(self, info):
""" General check services """
self.servicesChecksFunc[info[1]](info)
def checkTcpService(self, info):
""" Check TCP services """
sIp = info[2]
nPort = info[3]
try:
sock = socket()
#if isinstance(sock, SocketTest):
sock.connect((sIp, nPort))
sock.close
self.saveExecuteResult(info)
except Exception as e:
self.saveExecuteResult(info, self.sErrorFlag, e)
def checkHttpService(self, info):
""" Check HTTP services """
sUrl = self.oHelpers.formatToValidUrl(info[2])
try:
urlopen(sUrl, None, 5).read()
self.saveExecuteResult(info)
except (HTTPError, URLError) as e:
self.saveExecuteResult(info, self.sErrorFlag, e)
def checkFtpService(self, info):
""" Check FTP services """
sServer = info[2]
sPort = info[3]
sUser = info[4]
sPassw = info[5]
try:
ftp = FTP()
ftp.connect(sServer, sPort)
ftp.login(sUser, sPassw)
ftp.quit()
self.saveExecuteResult(info)
except Exception as e:
self.saveExecuteResult(info, self.sErrorFlag, e)
def saveExecuteResult(self, info, status="ok", error=""):
""" Save in diferents list results, Error List and Ok List """
sResultDebug = self.oHelpers.printOutput(info, status, error)
sResultText = self.oHelpers.printOutput(info, status, error, 'text')
if status == 'ok':
self.listDebugResultOk.append(sResultDebug)
self.listTextResultOk.append(sResultText)
elif status == self.sErrorFlag:
self.listDebugResultError.append(sResultDebug)
self.listTextResultError.append(sResultText)