"""Utility method. XOR the two strings s1 and s2 (must have same length).
"""
return "".join(map(lambda x, y: chr(ord(x) ^ ord(y)), s1, s2))
-
+
class HMAC:
"""RFC2104 HMAC class.
This (mostly) supports the API for Cryptographic Hash Functions (PEP 247).
- """
+ """
def __init__(self, key, msg = None, digestmod = None):
"""Create a new HMAC object.
key: The starting key for the hash.
msg: if available, will immediately be hashed into the object's starting
- state.
+ state.
You can now feed arbitrary strings into the object using its update()
method, and can ask for the hash value at any time by calling its digest()
class SSLFakeSocket:
"""A fake socket object that really wraps a SSLObject.
-
+
It only supports what is needed in smtplib.
"""
def __init__(self, realsock, sslobj):
class SSLFakeFile:
"""A fake file like object that really wraps a SSLObject.
-
+
It only supports what is needed in smtplib.
"""
def __init__( self, sslobj):
authmethod = method
break
if self.debuglevel > 0: print "AuthMethod:", authmethod
-
+
if authmethod == AUTH_CRAM_MD5:
(code, resp) = self.docmd("AUTH", AUTH_CRAM_MD5)
if code == 503:
return (code, resp)
(code, resp) = self.docmd(encode_cram_md5(resp, user, password))
elif authmethod == AUTH_PLAIN:
- (code, resp) = self.docmd("AUTH",
+ (code, resp) = self.docmd("AUTH",
AUTH_PLAIN + " " + encode_plain(user, password))
elif authmethod == None:
raise SMTPError("No suitable authentication method found.")
def starttls(self, keyfile = None, certfile = None):
"""Puts the connection to the SMTP server into TLS mode.
-
+
If the server supports TLS, this will encrypt the rest of the SMTP
session. If you provide the keyfile and certfile parameters,
the identity of the SMTP server and client can be checked. This,
however, depends on whether the socket module really checks the
certificates.
"""
- (resp, reply) = self.docmd("STARTTLS")
+ (resp, reply) = self.docmd("STARTTLS")
if resp == 220:
sslobj = socket.ssl(self.sock, keyfile, certfile)
self.sock = SSLFakeSocket(self.sock, sslobj)
self.file = SSLFakeFile(sslobj)
return (resp, reply)
-
+
def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
rcpt_options=[]):
"""This command performs an entire mail transaction.
class _Timer(Thread):
"""Call a function after a specified number of seconds:
-
+
t = Timer(30.0, f, args=[], kwargs={})
t.start()
t.cancel() # stop the timer's action if it's still waiting
"""
-
+
def __init__(self, interval, function, args=[], kwargs={}):
Thread.__init__(self)
self.interval = interval
self.args = args
self.kwargs = kwargs
self.finished = Event()
-
+
def cancel(self):
"""Stop the timer if it hasn't finished yet"""
self.finished.set()
-
+
def run(self):
self.finished.wait(self.interval)
if not self.finished.isSet():
zinfo.CRC = CRC
zinfo.file_size = file_size
# Seek backwards and write CRC and file sizes
- position = self.fp.tell() # Preserve current position in file
+ position = self.fp.tell() # Preserve current position in file
self.fp.seek(zinfo.header_offset + 14, 0)
self.fp.write(struct.pack("<lll", zinfo.CRC, zinfo.compress_size,
zinfo.file_size))