我尝试编写OO Python代码的方式与我在Java中学习的方式相同,这可能是我向南走的地方。我有一个主要的脚本和一个别人写的我改编的课程。我在主脚本中调用了类,但是我使用的每种技术[类名]都不可调用。
以下是最近的尝试。这是主要的脚本。为了安全起见,已删除变量directoryPairs。
import yaml
import pysftp
import FingerprintKey
with open('config/config.yaml') as settings:
cfg = yaml.load(settings)
host = cfg['host']
username = cfg['username']
password = cfg['password']
serverkey = cfg['fingerPrint']
x = FingerprintKey(serverkey)
options = pysftp.CnOpts()
options.hostkeys.clear()
options.hostkeys.add('www.example.com', u'ecdsa-sha2-nistp384', x)
with pysftp.Connection(host, username=username, password=password, cnopts=options) as sftp:
#for source, destination in directoryPairs.items():
#sftp.get_d(source, destination, preserve_mtime=True)
#if sftp.exists(source):
#files = sftp.listdir(source)
#for f in files:
#sftp.remove(os.path.join(source, f))
sftp.close()
以下是FingerprintKey.py类
import hashlib as hl
def trim_fingerprint(fingerprint):
if fingerprint.startswith('ecdsa-sha2-nistp384 384 '):
return fingerprint[len('ecdsa-sha2-nistp384 384 '):]
return fingerprint
def clean_fingerprint(fingerprint):
return trim_fingerprint(fingerprint).replace(':', '')
class FingerprintKey:
def __init__(self, fingerprint):
self.fingerprint = clean_fingerprint(fingerprint)
def compare(self, other):
if callable(getattr(other, "get_fingerprint", None)):
return other.get_fingerprint() == self.fingerprint
elif clean_fingerprint(other) == self.get_fingerprint():
return True
elif hl.md5(other).digest().encode('hex') == self.fingerprint:
return True
else:
return False
def __cmp__(self, other):
return self.compare(other)
def __contains__(self, other):
return self.compare(other)
def __eq__(self, other):
return self.compare(other)
def __ne__(self, other):
return not self.compare(other)
def get_fingerprint(self):
return self.fingerprint
def get_name(self):
return u'ecdsa-sha2-nistp384'
def asbytes(self):
# Note: This returns itself.
# That way when comparisons are done to asbytes return value,
# this class can handle the comparison.
return self
这两个文件都在同一目录中。
答案 0 :(得分:0)
感谢mkrieger1我对代码进行了以下添加,但它确实有效。
我将类文件重命名为AuthOnFingerPrint
$('#companiesDDL option[value="/Writeup/Writeups?symbol=tsla&;status=A"]').prop("selected", true);