本文整理汇总了Python中twisted.internet.ssl.ClientContextFactory类的典型用法代码示例。如果您正苦于以下问题:Python ClientContextFactory类的具体用法?Python ClientContextFactory怎么用?Python ClientContextFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClientContextFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: sendmail
def sendmail(authenticationUsername, authenticationSecret, fromAddress, toAddress, messageFile, smtpHost, smtpPort=25):
"""
Sends an email using SSLv3 over SMTP
@param authenticationUsername: account username
@param authenticationSecret: account password
@param fromAddress: the from address field of the email
@param toAddress: the to address field of the email
@param messageFile: the message content
@param smtpHost: the smtp host
@param smtpPort: the smtp port
"""
contextFactory = ClientContextFactory()
# evilaliv3:
# in order to understand and before change this settings please
# read the comment inside tor2web.utils.ssl
contextFactory.method = SSL.SSLv23_METHOD
resultDeferred = defer.Deferred()
senderFactory = ESMTPSenderFactory(
authenticationUsername,
authenticationSecret,
fromAddress,
toAddress,
messageFile,
resultDeferred,
contextFactory=contextFactory)
reactor.connectTCP(smtpHost, smtpPort, senderFactory)
return resultDeferred
示例2: sendmail
def sendmail(username, password, fromAddress, toAddress, message, smtpHost,
smtpPort=25):
"""
@param username: The username with which to authenticate.
@param password: The password with which to authenticate.
@param fromAddress: The SMTP reverse path (ie, MAIL FROM)
@param toAddress: The SMTP forward path (ie, RCPT TO)
@param message: text containing the headers and body of the message to send.
@param smtpHost: The MX host to which to connect.
@param smtpPort: The port number to which to connect.
@return: A Deferred which will be called back when the message has been
sent or which will errback if it cannot be sent.
"""
# Create a context factory which only allows SSLv3 and does not verify
# the peer's certificate.
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
d = Deferred()
senderFactory = ESMTPSenderFactory(
username,
password,
fromAddress,
toAddress,
StringIO(message),
d,
contextFactory=contextFactory)
reactor.connectTCP(smtpHost, smtpPort, senderFactory)
return d
示例3: sendmail
def sendmail(authenticationUsername, authenticationSecret, fromAddress, toAddress, messageFile, smtpHost, smtpPort=25):
"""
Sends an email using SSLv3 over SMTP
@param authenticationUsername: account username
@param authenticationSecret: account password
@param fromAddress: the from address field of the email
@param toAddress: the to address field of the email
@param messageFile: the message content
@param smtpHost: the smtp host
@param smtpPort: the smtp port
"""
contextFactory = ClientContextFactory()
contextFactory.method = SSL.SSLv3_METHOD
resultDeferred = defer.Deferred()
senderFactory = ESMTPSenderFactory(
authenticationUsername,
authenticationSecret,
fromAddress,
toAddress,
messageFile,
resultDeferred,
contextFactory=contextFactory)
reactor.connectTCP(smtpHost, smtpPort, senderFactory)
return resultDeferred
示例4: _sendmail
def _sendmail(self, to_addrs, email_msg_file):
from sshg import config
deferred = defer.Deferred()
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
if config.notification.smtp_user and config.notification.smtp_pass:
requireAuthentication = True
else:
requireAuthentication = False
sender_factory = ESMTPSenderFactory(
config.notification.smtp_user,
config.notification.smtp_pass,
config.notification.smtp_from,
to_addrs,
email_msg_file,
deferred,
retries=5,
timeout=30,
contextFactory=contextFactory,
heloFallback=False,
requireAuthentication=requireAuthentication,
requireTransportSecurity=config.notification.use_tls
)
reactor.connectTCP(config.notification.smtp_server,
config.notification.smtp_port, sender_factory)
return deferred
示例5: sendmail
def sendmail(mailconf, message):
"""Takes a regular dictionary as mailconf, as follows.
Example::
mailconf = dict(
host="smtp.gmail.com", # required
port=25, # optional, default 25 or 587 for SSL/TLS
username=foo, # optional, no default
password=bar, # optional, no default
tls=True, # optional, default False
)
d = mail.sendmail(mailconf, msg)
d.addCallback(on_response)
"""
if not isinstance(mailconf, types.DictType):
raise TypeError("mailconf must be a regular python dictionary")
if not isinstance(message, Message):
raise TypeError("message must be an instance of cyclone.mail.Message")
host = mailconf.get("host")
if isinstance(host, unicode):
host = str(unicode)
if not isinstance(host, types.StringType):
raise ValueError("mailconf requires a 'host' configuration")
use_tls = mailconf.get("tls")
if use_tls:
port = mailconf.get("port", 587)
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
else:
port = mailconf.get("port", 25)
contextFactory = None
if not isinstance(port, types.IntType):
raise ValueError("mailconf requires a proper 'port' configuration")
result = Deferred()
u = mailconf.get("username")
p = mailconf.get("password")
factory = ESMTPSenderFactory(u, p,
quoteaddr(message.from_addr),
message.to_addrs,
message.render(),
result,
contextFactory=contextFactory,
requireAuthentication=(u and p),
requireTransportSecurity=use_tls)
reactor.connectTCP(host, port, factory)
return result
示例6: send
def send(self):
ctx=ClientContextFactory()
ctx.method=SSLv3_METHOD
result=Deferred()
message=StringIO.StringIO(self._message.as_string())
sender=ESMTPSenderFactory(self._username, self._password, self._from, self._to, message, result, contextFactory=ctx)
from twisted.internet import reactor
reactor.connectTCP(self._smtphost, self._port, sender)
return result
示例7: _get_noverify_context
def _get_noverify_context(self):
"""
Use ClientContextFactory directly and set the method if necessary.
This will perform no host verification at all.
"""
from twisted.internet.ssl import ClientContextFactory
context_factory = ClientContextFactory()
if self.ssl_method is not None:
context_factory.method = self.ssl_method
return context_factory.getContext()
示例8: sendmail
def sendmail(mailconf, message):
"""Takes a regular dictionary as mailconf, as follows:
mailconf["host"] = "your.smtp.com" (required)
mailconf["port"] = 25 (optional, default 25 or 587 for TLS)
mailconf["username"] = "username" (optional)
mailconf["password"] = "password" (optional)
mailconf["ssl"] = True | False (optional, default False)
mailconf["tls"] = True | False (optional, default False)
mailconf["retries"] = 0 (optional, default 0)
mailconf["timeout"] = 30 (optional, default 30)
"""
if not isinstance(mailconf, types.DictType):
raise TypeError("mailconf must be a regular python dictionary")
if not isinstance(message, Message):
raise TypeError("message must be an instance of nuswit.mail.Message")
host = mailconf.get("host")
if not isinstance(host, types.StringType):
raise ValueError("mailconf requires a 'host' configuration")
ssl = mailconf.get("ssl", True)
tls = mailconf.get("tls", True)
if ssl is True:
port = mailconf.get("port", 587)
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
else:
port = mailconf.get("port", 25)
contextFactory = None
retries = mailconf.get("retries", 0)
timeout = mailconf.get("timeout", 30)
if not isinstance(port, types.IntType):
raise ValueError("mailconf requires a proper 'port' configuration")
deferred = Deferred()
username, password = mailconf.get("username"), mailconf.get("password")
factory = ESMTPSenderFactory(
username, password,
message.from_addr, message.to_addrs, message.render(),
deferred, contextFactory=contextFactory,
requireAuthentication=(username and password),
requireTransportSecurity=tls,
retries=retries, timeout=timeout)
if not ssl:
connector = reactor.connectTCP(host, port, factory, timeout=timeout)
else:
connector = reactor.connectSSL(host, port, factory, contextFactory, timeout=timeout)
return deferred, connector
示例9: buildProtocol
def buildProtocol(self, addr):
cf = ClientContextFactory()
cf.method = SSLv3_METHOD
p = self.protocol(self.account, self.src_doc, self.out_doc,
self.account.details.get("username", ""),
self.account.details.get("password", ""),
cf,
None, # identify???
logsize=30,
)
p.deferred = self.deferred # ???????????
p.factory = self
return p
示例10: sendmail
def sendmail(self, fromAddress, toAddress, message):
"""
@param fromAddress: The SMTP reverse path (ie, MAIL FROM)
@param toAddress: The SMTP forward path (ie, RCPT TO)
@param message: A file-like object containing the headers and body of
the message to send.
@return: A Deferred which will be called back when the message has been
sent or which will errback if it cannot be sent.
"""
if not hasattr(message, 'read'):
# It's not a file
message = StringIO(str(message))
def cancel(d):
"""
Cancel the L{mandrill.sendmail} call, tell the factory not to
retry and disconnect the connection.
@param d: The L{defer.Deferred} to be cancelled.
"""
senderFactory.sendFinished = True
if senderFactory.currentProtocol:
senderFactory.currentProtocol.transport.abortConnection()
else:
# Connection hasn't been made yet
connector.disconnect()
# Create a context factory which only allows SSLv3 and does not verify
# the peer's certificate.
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
resultDeferred = Deferred()
senderFactory = ESMTPSenderFactory(
self.username,
self.secret,
fromAddress,
toAddress,
message,
resultDeferred,
contextFactory=contextFactory)
connector = reactor.connectTCP(self.smtpHost, self.smtpPort, senderFactory)
return resultDeferred
示例11: getContext
def getContext(self, hostname, port):
ctx = ClientContextFactory.getContext(self)
ctx.set_options(SSL.OP_NO_SSLv2)
if self._verify:
ctx.load_verify_locations(None, self._verify_location)
ctx.set_verify(SSL.VERIFY_PEER|SSL.VERIFY_FAIL_IF_NO_PEER_CERT, self._verifyCert)
return ctx
示例12: MyWebClientContextFactory
class MyWebClientContextFactory(object):
def __init__(self):
self._options = ClientContextFactory()
def getContext(self, hostname, port):
return self._options.getContext()
示例13: getContext
def getContext(self):
ctx = ClientContextFactory.getContext(self)
# Enable all workarounds to SSL bugs as documented by
# http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
ctx.set_options(OP_ALL)
if self.hostname:
ScrapyClientTLSOptions(self.hostname, ctx)
return ctx
示例14: getContext
def getContext(self, hostname=None, port=None):
ctx = ClientContextFactory.getContext(self)
# Enable all workarounds to SSL bugs as documented by
# http://www.openssl.org/docs/ssl/SSL_CTX_set_options.html
ctx.set_options(SSL.OP_ALL)
if hostname:
ClientTLSOptions(hostname, ctx)
return ctx
示例15: sendmail
def sendmail(username, password, smtpHost, smtpPort, fromEmail, toEmail, subject, body):
resultDeferred = Deferred()
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
msg = createMessage(fromEmail, toEmail, subject, body)
senderFactory = ESMTPSenderFactory(
username,
password,
fromEmail,
toEmail,
StringIO(msg),
resultDeferred,
contextFactory=contextFactory)
reactor.connectTCP(smtpHost, smtpPort, senderFactory)
return resultDeferred