本文整理汇总了Python中twisted.web.client.Agent.usingEndpointFactory方法的典型用法代码示例。如果您正苦于以下问题:Python Agent.usingEndpointFactory方法的具体用法?Python Agent.usingEndpointFactory怎么用?Python Agent.usingEndpointFactory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.client.Agent
的用法示例。
在下文中一共展示了Agent.usingEndpointFactory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_agents
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def _make_agents(self, auth_files):
"""
Configure the web clients that:
* perform backchannel CAS ticket validation
* proxy the target site
"""
self.connectionPool = HTTPConnectionPool(self.reactor)
if auth_files is None or len(auth_files) == 0:
agent = Agent(self.reactor, pool=self.connectionPool)
else:
extra_ca_certs = []
for ca_cert in auth_files:
with open(ca_cert, "rb") as f:
data = f.read()
cert = crypto.load_certificate(crypto.FILETYPE_PEM, data)
del data
extra_ca_certs.append(cert)
policy = CustomPolicyForHTTPS(extra_ca_certs)
agent = Agent(self.reactor, contextFactory=policy, pool=self.connectionPool)
if self.proxy_client_endpoint_s is not None:
self.proxyConnectionPool = HTTPConnectionPool(self.reactor)
self.proxy_agent = Agent.usingEndpointFactory(
self.reactor,
WebClientEndpointFactory(self.reactor, self.proxy_client_endpoint_s),
pool=self.proxyConnectionPool)
else:
self.proxy_agent = agent
if self.cas_client_endpoint_s is not None:
self.casConnectionPool = HTTPConnectionPool(self.reactor)
self.cas_agent = Agent.usingEndpointFactory(
self.reactor,
WebClientEndpointFactory(self.reactor, self.cas_client_endpoint_s),
pool=self.casConnectionPool)
else:
self.cas_agent = agent
示例2: run
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def run(self, options, mainoptions, proto):
"ICarmlCommand API"
config = txtorcon.TorConfig(proto)
yield config.post_bootstrap
socks = yield proto.get_info('net/listeners/socks')
socks = socks['net/listeners/socks']
socks_host, socks_port = socks.split(':')
args = options['service'].split(':')
onion = args[1]
cookie = args[2].split('=')[1]
ep = txtorcon.TorClientEndpoint(
onion, 80,
socks_hostname=socks_host, socks_port=int(socks_port)
)
auth = '%s %s' % (onion, cookie)
if auth not in config.HidServAuth:
config.HidServAuth.append(auth)
yield config.save()
agent = Agent.usingEndpointFactory(reactor, EndpointFactory(ep))
res = yield agent.request('GET', 'http://%s/' % onion)
print("Response:", res.code)
print("bytes:", res.length)
data = yield receive(res)
print(data)
示例3: tor_agent
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def tor_agent(reactor, socks_endpoint, circuit=None, pool=None):
"""
This is the low-level method used by
:meth:`txtorcon.Tor.web_agent` and
:meth:`txtorcon.Circuit.web_agent` -- probably you should call one
of those instead.
:returns: a Deferred that fires with an object that implements
:class:`twisted.web.iweb.IAgent` and is thus suitable for passing
to ``treq`` as the ``agent=`` kwarg. Of course can be used
directly; see `using Twisted web cliet
<http://twistedmatrix.com/documents/current/web/howto/client.html>`_.
:param reactor: the reactor to use
:param circuit: If supplied, a particular circuit to use
:param socks_endpoint: Deferred that fires w/
IStreamClientEndpoint (or IStreamClientEndpoint instance)
which points at a SOCKS5 port of our Tor
:param pool: passed on to the Agent (as ``pool=``)
"""
if socks_endpoint is None:
raise ValueError(
"Must provide socks_endpoint as Deferred or IStreamClientEndpoint"
)
if circuit is not None:
factory = _AgentEndpointFactoryForCircuit(reactor, socks_endpoint, circuit)
else:
factory = _AgentEndpointFactoryUsingTor(reactor, socks_endpoint)
return Agent.usingEndpointFactory(reactor, factory, pool=pool)
示例4: test_hpe_activate
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def test_hpe_activate(self):
path = b"/Plugin.Activate"
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path)
d.addCallback(self.checkResponse, json.dumps({u"Implements":
[u"VolumeDriver"]}))
d.addErrback(self.cbFailed)
return d
示例5: agent_for_socks_port
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def agent_for_socks_port(reactor, torconfig, socks_config, pool=None):
"""
This returns a Deferred that fires with an object that implements
:class:`twisted.web.iweb.IAgent` and is thus suitable for passing
to ``treq`` as the ``agent=`` kwarg. Of course can be used
directly; see `using Twisted web cliet
<http://twistedmatrix.com/documents/current/web/howto/client.html>`_. If
you have a :class:`txtorcon.Tor` instance already, the preferred
API is to call :meth:`txtorcon.Tor.web_agent` on it.
:param torconfig: a :class:`txtorcon.TorConfig` instance.
:param socks_config: anything valid for Tor's ``SocksPort``
option. This is generally just a TCP port (e.g. ``9050``), but
can also be a unix path like so ``unix:/path/to/socket`` (Tor
has restrictions on the ownership/permissions of the directory
containing ``socket``). If the given SOCKS option is not
already available in the underlying Tor instance, it is
re-configured to add the SOCKS option.
"""
# :param tls: True (the default) will use Twisted's default options
# with the hostname in the URI -- that is, TLS verification
# similar to a Browser. Otherwise, you can pass whatever Twisted
# returns for `optionsForClientTLS
# <https://twistedmatrix.com/documents/current/api/twisted.internet.ssl.optionsForClientTLS.html>`_
socks_config = str(socks_config) # sadly, all lists are lists-of-strings to Tor :/
if socks_config not in torconfig.SocksPort:
txtorlog.msg("Adding SOCKS port '{}' to Tor".format(socks_config))
torconfig.SocksPort.append(socks_config)
try:
yield torconfig.save()
except Exception as e:
raise RuntimeError(
"Failed to reconfigure Tor with SOCKS port '{}': {}".format(
socks_config, str(e)
)
)
if socks_config.startswith('unix:'):
socks_ep = UNIXClientEndpoint(reactor, socks_config[5:])
else:
if ':' in socks_config:
host, port = socks_config.split(':', 1)
else:
host = '127.0.0.1'
port = int(socks_config)
socks_ep = TCP4ClientEndpoint(reactor, host, port)
returnValue(
Agent.usingEndpointFactory(
reactor,
_AgentEndpointFactoryUsingTor(reactor, socks_ep),
pool=pool,
)
)
示例6: __init__
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [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 = 10
self.agent = Agent.usingEndpointFactory(reactor, MatrixFederationEndpointFactory(hs), pool=pool)
self.clock = hs.get_clock()
self.version_string = hs.version_string
self._next_id = 1
示例7: __init__
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def __init__(self, rootResource):
"""
:param rootResource: The Twisted `IResource` at the root of the
resource tree.
"""
self._memoryReactor = MemoryReactorClock()
self._realAgent = Agent.usingEndpointFactory(
reactor=self._memoryReactor,
endpointFactory=_EndpointFactory(self._memoryReactor))
self._rootResource = rootResource
self._pumps = set()
示例8: __init__
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def __init__(self, hs):
SimpleHttpClient.__init__(self, hs)
# clobber the base class's agent and UA:
self.agent = ContentDecoderAgent(
BrowserLikeRedirectAgent(
Agent.usingEndpointFactory(
reactor,
SpiderEndpointFactory(hs)
)
), [('gzip', GzipDecoder)]
)
示例9: _remove_volume
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def _remove_volume(self, name):
path = b"/VolumeDriver.Remove"
body = {u"Name": name}
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps(body)))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
d.addErrback(self.cbFailed)
return d
示例10: test_hpe_list_volume_no_volumes
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def test_hpe_list_volume_no_volumes(self):
path = b"/VolumeDriver.List"
# Create a volume to be mounted
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps({})))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, json.dumps({u"Err": '',
u"Volumes": []}))
d.addErrback(self.cbFailed)
return d
示例11: _unmount_the_volume
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def _unmount_the_volume(self, body, name):
# NOTE: body arg is the result from last deferred call.
# Python complains about parameter mis-match if you don't include it
path = b"/VolumeDriver.Unmount"
newbody = {u"Name": name}
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps(newbody)))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
d.addErrback(self.cbFailed)
return d
示例12: test_hpe_create_volume_provisioning_option
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def test_hpe_create_volume_provisioning_option(self):
name = 'test-create-volume'
path = b"/VolumeDriver.Create"
body = {u"Name": name,
u"Opts": {u"provisioning": u"full"}}
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps(body)))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, json.dumps({u"Err": ''}))
d.addCallback(self._remove_volume_callback, name)
d.addErrback(self.cbFailed)
return d
示例13: _get_volume_mount_path
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def _get_volume_mount_path(self, body, name):
# NOTE: body arg is the result from last deferred call.
# Python complains about parameter mis-match if you don't include it
# In this test, we need it to compare expected results with Path
# request
# Compare path returned by mount (body) with Get Path request
path = b"/VolumeDriver.Path"
newbody = {u"Name": name}
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps(newbody)))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, body)
d.addErrback(self.cbFailed)
return d
示例14: testTimeout
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def testTimeout(self):
mrc = MemoryReactorClock()
ef = _EndpointFactory(reactor=mrc)
agent = Agent.usingEndpointFactory(reactor=mrc,
endpointFactory=ef)
with patch.object(self.observer, 'reactor', mrc):
with patch.object(self.observer, 'client', HTTPClient(agent=agent)):
with patch.object(self.observer, 'onFailure') as mockOnFailure:
# tcpClients instead of sslClients due to _EndpointFactory simplification
self.assertTrue(len(self.observer.reactor.tcpClients) == 0)
d = self.observer.observe()
self.observer.reactor.advance(self.observer.timeout-0.1)
self.assertTrue(len(self.observer.reactor.tcpClients) == 1)
mockOnFailure.assert_not_called()
self.observer.reactor.advance(0.1) # trigger the timeout
self.failureResultOf(d, ConnectingCancelledError)
示例15: test_hpe_create_volume_invalid_provisioning_option
# 需要导入模块: from twisted.web.client import Agent [as 别名]
# 或者: from twisted.web.client.Agent import usingEndpointFactory [as 别名]
def test_hpe_create_volume_invalid_provisioning_option(self):
name = 'test-create-volume-fake'
path = b"/VolumeDriver.Create"
body = {u"Name": name,
u"Opts": {u"provisioning": u"fake"}}
headers = Headers({b"content-type": [b"application/json"]})
body_producer = FileBodyProducer(BytesIO(dumps(body)))
agent = Agent.usingEndpointFactory(reactor, HPEEndpointFactory())
d = agent.request(b'POST', b"UNIX://localhost" + path, headers,
body_producer)
d.addCallback(self.checkResponse, json.dumps({
u"Err": "Invalid input received: Must specify a valid " +
"provisioning type ['thin', 'full', " +
"'dedup'], value 'fake' is invalid."}))
d.addCallback(self._remove_volume_callback, name)
d.addErrback(self.cbFailed)
return d