本文整理汇总了Python中twisted.internet.ssl.ClientContextFactory类的典型用法代码示例。如果您正苦于以下问题:Python ClientContextFactory类的具体用法?Python ClientContextFactory怎么用?Python ClientContextFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ClientContextFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:DaveDaCoda,项目名称:Tor2web,代码行数:33,代码来源:mail.py
示例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
开发者ID:Darkpaw95,项目名称:pymon,代码行数:29,代码来源:email.py
示例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
开发者ID:VasyaRogow,项目名称:Tor2web-3.0,代码行数:29,代码来源:mail.py
示例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
开发者ID:UfSoft,项目名称:SSHg,代码行数:27,代码来源:notification.py
示例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
开发者ID:flaviogrossi,项目名称:cyclone,代码行数:57,代码来源:mail.py
示例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
开发者ID:DamnWidget,项目名称:goliat,代码行数:9,代码来源:__init__.py
示例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()
开发者ID:praekelt,项目名称:vumi,代码行数:11,代码来源:sandbox.py
示例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
开发者ID:Blacksens,项目名称:enigma2-plugins,代码行数:53,代码来源:mail.py
示例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
开发者ID:LeonardoXavier,项目名称:raindrop,代码行数:13,代码来源:smtp.py
示例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
开发者ID:claytondaley,项目名称:TxMandrill,代码行数:48,代码来源:sender.py
示例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
开发者ID:leenmie,项目名称:twilio-twisted,代码行数:7,代码来源:SSLVerifiedClientContextFactory.py
示例12: MyWebClientContextFactory
class MyWebClientContextFactory(object):
def __init__(self):
self._options = ClientContextFactory()
def getContext(self, hostname, port):
return self._options.getContext()
开发者ID:aseques,项目名称:txwinrm,代码行数:7,代码来源:util.py
示例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
开发者ID:mayson,项目名称:wikimedia-pybal,代码行数:8,代码来源:proxyfetch.py
示例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
开发者ID:01-,项目名称:scrapy-cluster,代码行数:8,代码来源:contextfactory.py
示例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
开发者ID:paulvstheworld,项目名称:hsmail,代码行数:17,代码来源:mailclient.py
示例16: 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["tls"] = True | False (optional, default False)
"""
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 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,
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
开发者ID:chauncey,项目名称:cyclone,代码行数:46,代码来源:mail.py
示例17: sendmail
def sendmail(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('smtp.gmail.com', 587, senderFactory)
return resultDeferred
开发者ID:paulvstheworld,项目名称:twisted-smtp-client,代码行数:17,代码来源:client.py
示例18: sendTwistedMailAuth
def sendTwistedMailAuth(host, port, login, password, ssl_flag, need_login, addr, to, subject, filename):
dhnio.Dprint(14, 'transport_email.sendTwistedMailAuth to:%s ssl:%s auth:%s ' % (str(to),str(ssl_flag), str(need_login)))
fin = file(filename, 'rb')
bin_data = fin.read()
fin.close()
msg = email.MIMEMultipart.MIMEMultipart()
msg["Subject"] = subject
msg["From"] = addr
msg["To"] = to
part = email.MIMEBase.MIMEBase('application', "octet-stream")
part.set_payload( bin_data+'end' )
email.Encoders.encode_base64(part)
part.add_header('Content-Disposition', 'attachment; filename="%s"' % os.path.basename(filename))
msg.attach(part)
try:
port_ = int(port)
except:
port_ = 25
messageText = msg.as_string()
cf = ClientContextFactory()
cf.method = SSLv3_METHOD
result = Deferred()
factory = MySenderFactory(
login,
password,
addr,
to,
StringIO(messageText),
result,
contextFactory=cf,
requireTransportSecurity=ssl_flag,
requireAuthentication=need_login,)
if ssl_flag:
conn = reactor.connectSSL(host, port_, factory, cf)
else:
conn = reactor.connectTCP(host, port_, factory)
return result
开发者ID:vesellov,项目名称:datahaven,代码行数:42,代码来源:transport_email.py
示例19: __init__
def __init__(self, id, request, deferred):
# Create a context factory which only allows SSLv3 and does not verify
# the peer's certificate.
contextFactory = ClientContextFactory()
contextFactory.method = SSLv3_METHOD
self.id = id
self.request = request
self.deferred = deferred
self.sentDeferred = Deferred()
self.sentDeferred.addErrback(self.deferred.errback)
username = request.args.get("username", [request.getUser()])[0]
password = request.args.get("password", [request.getPassword()])[0]
fromEmail = request.args.get("from", username)[0]
toEmail = request.args.get("to")[0]
subject = request.args.get("subject")[0]
message = StringIO.StringIO(
"""\
Date: Fri, 6 Feb 2004 10:14:39 -0800
From: %s
To: %s
Subject: %s
%s
"""
% (fromEmail, toEmail, subject, request.args.get("body", [""])[0])
)
ESMTPSenderFactory.__init__(
self,
username,
password,
fromEmail,
toEmail,
message,
self.sentDeferred,
retries=0,
contextFactory=contextFactory,
requireAuthentication=False,
requireTransportSecurity=False,
)
开发者ID:progrium,项目名称:protocol-droid,代码行数:42,代码来源:smtp.py
示例20: sendmail
def sendmail(config, messageFile):
"""
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(
config.smtpuser.encode("utf-8"),
config.smtppass.encode("utf-8"),
config.smtpmail,
config.smtpmailto_exceptions,
messageFile,
resultDeferred,
contextFactory=contextFactory,
requireAuthentication=True,
requireTransportSecurity=(config.smtpsecurity != "SSL"),
retries=0,
timeout=15,
)
if config.security == "SSL":
senderFactory = tls.TLSMemoryBIOFactory(contextFactory, True, senderFactory)
reactor.connectTCP(config.smtpdomain, config.smtpport, senderFactory)
return resultDeferred
开发者ID:globaleaks,项目名称:Tor2web,代码行数:41,代码来源:mail.py
注:本文中的twisted.internet.ssl.ClientContextFactory类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论