本文整理汇总了Python中twisted.web.client.HTTPConnectionPool.cachedConnectionTimeout方法的典型用法代码示例。如果您正苦于以下问题:Python HTTPConnectionPool.cachedConnectionTimeout方法的具体用法?Python HTTPConnectionPool.cachedConnectionTimeout怎么用?Python HTTPConnectionPool.cachedConnectionTimeout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.HTTPConnectionPool
的用法示例。
在下文中一共展示了HTTPConnectionPool.cachedConnectionTimeout方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: requestAvatarId
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def requestAvatarId(self, c):
creds = credentials.IUsernamePassword(c, None)
if creds is not None:
locks = []
pool = HTTPConnectionPool(reactor, persistent=False)
pool.cachedConnectionTimeout = self.timeout
if self.max_concurrency:
pool.persistent = True
pool.maxPersistentPerHost = self.max_concurrency
locks.append(
defer.DeferredSemaphore(self.max_concurrency))
if self.global_max_concurrency:
locks.append(
defer.DeferredSemaphore(self.global_max_concurrency))
conn = ThrottledSwiftConnection(
locks, self.auth_url, creds.username, creds.password,
pool=pool,
extra_headers=self.extra_headers,
verbose=self.verbose,
ceph_compatible=self.ceph_compatible
)
conn.user_agent = USER_AGENT
d = conn.authenticate()
d.addCallback(self._after_auth, conn)
d.addErrback(eb_failed_auth)
return d
return defer.fail(error.UnauthorizedLogin())
示例2: makeService
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def makeService(options):
"""
Makes a new swftp-ftp service. The only option is the config file
location. The config file has the following options:
- host
- port
- auth_url
- num_persistent_connections
- connection_timeout
- welcome_message
"""
from twisted.protocols.ftp import FTPFactory
from twisted.web.client import HTTPConnectionPool
from twisted.cred.portal import Portal
from swftp.ftp.server import SwiftFTPRealm
from swftp.auth import SwiftBasedAuthDB
from swftp.utils import print_runtime_info
print('Starting SwFTP-ftp %s' % VERSION)
c = get_config(options['config_file'], options)
ftp_service = service.MultiService()
# Add statsd service
if c.get('ftp', 'log_statsd_host'):
try:
from swftp.statsd import makeService as makeStatsdService
makeStatsdService(
c.get('ftp', 'log_statsd_host'),
c.getint('ftp', 'log_statsd_port'),
sample_rate=c.getfloat('ftp', 'log_statsd_sample_rate'),
prefix=c.get('ftp', 'log_statsd_metric_prefix')
).setServiceParent(ftp_service)
except ImportError:
log.err('Missing Statsd Module. Requires "txstatsd"')
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = c.getint('ftp', 'num_persistent_connections')
pool.cachedConnectionTimeout = c.getint('ftp', 'connection_timeout')
authdb = SwiftBasedAuthDB(auth_url=c.get('ftp', 'auth_url'),
verbose=c.getboolean('ftp', 'verbose'))
ftpportal = Portal(SwiftFTPRealm())
ftpportal.registerChecker(authdb)
ftpfactory = FTPFactory(ftpportal)
ftpfactory.welcomeMessage = c.get('ftp', 'welcome_message')
ftpfactory.allowAnonymous = False
signal.signal(signal.SIGUSR1, print_runtime_info)
signal.signal(signal.SIGUSR2, print_runtime_info)
internet.TCPServer(
c.getint('ftp', 'port'),
ftpfactory,
interface=c.get('ftp', 'host')).setServiceParent(ftp_service)
return ftp_service
示例3: _getConnectionPool
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def _getConnectionPool(self):
pool = HTTPConnectionPool(reactor, self._persistent)
if self._persistent:
pool.maxPersistentPerHost = self._maxPersistentPerHost
pool.cachedConnectionTimeout = self._cachedConnectionTimeout
pool.retryAutomatically = self._retryAutomatically
return pool
示例4: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def __init__(self, debug=False):
self.gpg = gnupg.GPG()
self.mpex_url = 'http://polimedia.us/bitcoin/mpex.php'
self.mpex_fingerprint = 'F1B69921'
self.passphrase = None
self.debug = debug
if(self.debug) :
self.df = open("mpex_%d.txt" % time.time(),'w')
pool = HTTPConnectionPool(reactor)
#close connections at same time as server to prevent ResponseNeverReceived error
#timeout can be determined automatically from Keep-Alive header
pool.cachedConnectionTimeout = 4
self.agent = Agent(reactor, pool=pool)
示例5: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def __init__(self, hs):
self.hs = hs
self.signing_key = hs.config.signing_key[0]
self.server_name = hs.hostname
pool = HTTPConnectionPool(reactor)
pool.maxPersistentPerHost = 5
pool.cachedConnectionTimeout = 2 * 60
self.agent = Agent.usingEndpointFactory(
reactor, MatrixFederationEndpointFactory(hs), pool=pool
)
self.clock = hs.get_clock()
self._store = hs.get_datastore()
self.version_string = hs.version_string
self._next_id = 1
示例6: _get_agent
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def _get_agent():
context_factory = MyWebClientContextFactory()
try:
# HTTPConnectionPool has been present since Twisted version 12.1
from twisted.web.client import HTTPConnectionPool
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = _MAX_PERSISTENT_PER_HOST
pool.cachedConnectionTimeout = _CACHED_CONNECTION_TIMEOUT
agent = Agent(reactor, context_factory,
connectTimeout=_CONNECT_TIMEOUT, pool=pool)
except ImportError:
from _zenclient import ZenAgent
agent = ZenAgent(reactor, context_factory, persistent=True, maxConnectionsPerHostName=1)
return agent
示例7: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def __init__(self, reactor):
self.reactor = reactor
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = 1
pool.cachedConnectionTimeout = 600
self.agent = RedirectAgent(Agent(reactor, pool=pool))
self.reqQ = HttpReqQ(self.agent, self.reactor)
self.clientPlaylist = HlsPlaylist()
self.verbose = False
self.download = False
self.outDir = ""
self.encryptionHandled=False
# required for the dump durations functionality
self.dur_dump_file = None
self.dur_avproble_acc = 0
self.dur_vt_acc = 0
self.dur_playlist_acc = 0
示例8: _get_agent
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def _get_agent():
global _AGENT
if _AGENT is None:
try:
# HTTPConnectionPool has been present since Twisted version 12.1
from twisted.web.client import HTTPConnectionPool
pool = HTTPConnectionPool(reactor, persistent=True)
pool.maxPersistentPerHost = _MAX_PERSISTENT_PER_HOST
pool.cachedConnectionTimeout = _CACHED_CONNECTION_TIMEOUT
_AGENT = Agent(
reactor, connectTimeout=_CONNECT_TIMEOUT, pool=pool)
except ImportError:
try:
# connectTimeout first showed up in Twisted version 11.1
_AGENT = Agent(reactor, connectTimeout=_CONNECT_TIMEOUT)
except TypeError:
_AGENT = Agent(reactor)
return _AGENT
示例9: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def __init__(self, hs):
self.hs = hs
self.signing_key = hs.config.signing_key[0]
self.server_name = hs.hostname
reactor = hs.get_reactor()
pool = HTTPConnectionPool(reactor)
pool.retryAutomatically = False
pool.maxPersistentPerHost = 5
pool.cachedConnectionTimeout = 2 * 60
self.agent = Agent.usingEndpointFactory(
reactor, MatrixFederationEndpointFactory(hs), pool=pool
)
self.clock = hs.get_clock()
self._store = hs.get_datastore()
self.version_string_bytes = hs.version_string.encode('ascii')
self.default_timeout = 60
def schedule(x):
reactor.callLater(_EPSILON, x)
self._cooperator = Cooperator(scheduler=schedule)
示例10: agent
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def agent(self, scheme='http'):
if not self._agents:
pool = HTTPConnectionPool(reactor)
pool.maxPersistentPerHost = 10
pool.cachedConnectionTimeout = 15
contextFactory = PermissiveBrowserLikePolicyForHTTPS()
proxies = getproxies()
if 'http' in proxies or 'https' in proxies:
# I've noticed some intermittent failures (ResponseNeverReceived) to
# POST request through a proxy when persistent connections are enabled.
pool.persistent = False
if 'https' in proxies:
proxy = urlparse(proxies.get('https'))
if proxy:
# Note- this isn't going to work completely. It's not being
# passed the modified contextFactory, and in fact it doesn't
# even work properly for other reasons (ZPS-2061)
log.info("Creating https proxy (%s:%s)" % (proxy.hostname, proxy.port))
endpoint = TCP4ClientEndpoint(reactor, proxy.hostname, proxy.port, timeout=CONNECT_TIMEOUT)
SessionManager._agents['https'] = \
ProxyAgent(endpoint, reactor, pool=pool)
else:
SessionManager._agents['https'] = \
Agent(reactor, pool=pool, connectTimeout=CONNECT_TIMEOUT, contextFactory=contextFactory)
if 'http' in proxies:
proxy = urlparse(proxies.get('http'))
if proxy:
log.info("Creating http proxy (%s:%s)" % (proxy.hostname, proxy.port))
endpoint = TCP4ClientEndpoint(reactor, proxy.hostname, proxy.port, timeout=CONNECT_TIMEOUT)
SessionManager._agents['http'] = \
ProxyAgent(endpoint, reactor, pool=pool)
else:
SessionManager._agents['http'] = \
Agent(reactor, pool=pool, connectTimeout=CONNECT_TIMEOUT)
return SessionManager._agents[scheme]
示例11: HTTPConnectionPool
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
from twisted.web.client import getPage
from twisted.internet import reactor
from twisted.internet.defer import Deferred
from twisted.internet.protocol import Protocol
from twisted.web.client import Agent, ContentDecoderAgent, RedirectAgent, GzipDecoder
from twisted.web.client import HTTPConnectionPool
from twisted.web.http_headers import Headers
from twisted.internet.ssl import ClientContextFactory
from twisted.internet.task import LoopingCall
pnconn_pool = HTTPConnectionPool(reactor, persistent=True)
pnconn_pool.maxPersistentPerHost = 100
pnconn_pool.cachedConnectionTimeout = 310
class Pubnub(PubnubCoreAsync):
def start(self): reactor.run()
def stop(self): reactor.stop()
def timeout( self, delay, callback ):
reactor.callLater( delay, callback )
def __init__(
self,
publish_key,
subscribe_key,
secret_key = False,
cipher_key = False,
ssl_on = False,
origin = 'pubsub.pubnub.com'
) :
super(Pubnub, self).__init__(
示例12: __init__
# 需要导入模块: from twisted.web.client import HTTPConnectionPool [as 别名]
# 或者: from twisted.web.client.HTTPConnectionPool import cachedConnectionTimeout [as 别名]
def __init__(self, hs, treq_args={}, ip_whitelist=None, ip_blacklist=None):
"""
Args:
hs (synapse.server.HomeServer)
treq_args (dict): Extra keyword arguments to be given to treq.request.
ip_blacklist (netaddr.IPSet): The IP addresses that are blacklisted that
we may not request.
ip_whitelist (netaddr.IPSet): The whitelisted IP addresses, that we can
request if it were otherwise caught in a blacklist.
"""
self.hs = hs
self._ip_whitelist = ip_whitelist
self._ip_blacklist = ip_blacklist
self._extra_treq_args = treq_args
self.user_agent = hs.version_string
self.clock = hs.get_clock()
if hs.config.user_agent_suffix:
self.user_agent = "%s %s" % (self.user_agent, hs.config.user_agent_suffix)
self.user_agent = self.user_agent.encode('ascii')
if self._ip_blacklist:
real_reactor = hs.get_reactor()
# If we have an IP blacklist, we need to use a DNS resolver which
# filters out blacklisted IP addresses, to prevent DNS rebinding.
nameResolver = IPBlacklistingResolver(
real_reactor, self._ip_whitelist, self._ip_blacklist
)
@implementer(IReactorPluggableNameResolver)
class Reactor(object):
def __getattr__(_self, attr):
if attr == "nameResolver":
return nameResolver
else:
return getattr(real_reactor, attr)
self.reactor = Reactor()
else:
self.reactor = hs.get_reactor()
# the pusher makes lots of concurrent SSL connections to sygnal, and
# tends to do so in batches, so we need to allow the pool to keep
# lots of idle connections around.
pool = HTTPConnectionPool(self.reactor)
pool.maxPersistentPerHost = max((100 * CACHE_SIZE_FACTOR, 5))
pool.cachedConnectionTimeout = 2 * 60
# The default context factory in Twisted 14.0.0 (which we require) is
# BrowserLikePolicyForHTTPS which will do regular cert validation
# 'like a browser'
self.agent = Agent(
self.reactor,
connectTimeout=15,
contextFactory=self.hs.get_http_client_context_factory(),
pool=pool,
)
if self._ip_blacklist:
# If we have an IP blacklist, we then install the blacklisting Agent
# which prevents direct access to IP addresses, that are not caught
# by the DNS resolution.
self.agent = BlacklistingAgentWrapper(
self.agent,
self.reactor,
ip_whitelist=self._ip_whitelist,
ip_blacklist=self._ip_blacklist,
)