本文整理汇总了Python中requests_unixsocket.Session方法的典型用法代码示例。如果您正苦于以下问题:Python requests_unixsocket.Session方法的具体用法?Python requests_unixsocket.Session怎么用?Python requests_unixsocket.Session使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类requests_unixsocket
的用法示例。
在下文中一共展示了requests_unixsocket.Session方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _installer
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def _installer(self):
channel = self.platform_config.get_channel()
self.logger.info('system info')
session = requests_unixsocket.Session()
response = session.get('{0}/v2/system-info'.format(SOCKET))
self.logger.debug("system info response: {0}".format(response.text))
snap_response = json.loads(response.text)
version_response = requests.get('http://apps.syncloud.org/releases/{0}/snapd.version'.format(channel))
return self.to_app(
'installer',
'Installer',
channel,
snap_response['result']['version'],
version_response.text
)
示例2: test_unix_domain_adapter_ok
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_unix_domain_adapter_ok():
with UnixSocketServerThread() as usock_thread:
session = requests_unixsocket.Session('http+unix://')
urlencoded_usock = requests.compat.quote_plus(usock_thread.usock)
url = 'http+unix://%s/path/to/page' % urlencoded_usock
for method in ['get', 'post', 'head', 'patch', 'put', 'delete',
'options']:
logger.debug('Calling session.%s(%r) ...', method, url)
r = getattr(session, method)(url)
logger.debug(
'Received response: %r with text: %r and headers: %r',
r, r.text, r.headers)
assert r.status_code == 200
assert r.headers['server'] == 'waitress'
assert r.headers['X-Transport'] == 'unix domain socket'
assert r.headers['X-Requested-Path'] == '/path/to/page'
assert r.headers['X-Socket-Path'] == usock_thread.usock
assert isinstance(r.connection, requests_unixsocket.UnixAdapter)
assert r.url.lower() == url.lower()
if method == 'head':
assert r.text == ''
else:
assert r.text == 'Hello world!'
示例3: _get_session_and_address
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def _get_session_and_address():
if not CONF.compressor_address:
return None, None
if CONF.compressor_address.startswith("/"):
# unix socket
if os.path.exists(CONF.compressor_address):
mode = os.stat(CONF.compressor_address).st_mode
if stat.S_ISSOCK(mode):
return (requests_unixsocket.Session(),
"http+unix://%s/" % parse.quote_plus(
CONF.compressor_address))
else:
raise exception.CoriolisException(
"compressor_address is not a valid unix socket")
else:
raise exception.CoriolisException(
"compressor_address is not a valid unix socket")
return (requests.Session(), "http://%s/" % CONF.compressor_address)
示例4: purge
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def purge(args, test=False):
urlpath = '/VolumeDriver.Snapshots.Purge'
param = {'Name': args.name[0],
'Pattern': args.pattern[0],
'Dryrun': args.dryrun}
if test:
param['Test'] = True
resp = TestApp(app).post(urlpath, json.dumps(param))
else:
resp = Session().post(
'http+unix://{}{}'
.format(urllib.parse.quote_plus(USOCKET), urlpath),
json.dumps(param))
res = get_from(resp, '')
if res:
print(res)
return res
示例5: __init__
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def __init__(self, api_endpoint, cert=None, verify=True, timeout=None):
self._api_endpoint = api_endpoint
self._timeout = timeout
if self._api_endpoint.startswith('http+unix://'):
self.session = requests_unixsocket.Session()
else:
self.session = requests.Session()
self.session.cert = cert
self.session.verify = verify
示例6: test_session_http
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_session_http(self):
"""HTTP nodes return the default requests session."""
node = client._APINode('http://test.com')
self.assertIsInstance(node.session, requests.Session)
示例7: test_session_unix_socket
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_session_unix_socket(self):
"""HTTP nodes return a requests_unixsocket session."""
node = client._APINode('http+unix://test.com')
self.assertIsInstance(node.session, requests_unixsocket.Session)
示例8: test_get
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_get(self, Session):
"""Perform a session get."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {'type': 'sync'},
})
session = mock.Mock(**{'get.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
node.get()
session.get.assert_called_once_with('http://test.com', timeout=None)
示例9: test_post
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_post(self, Session):
"""Perform a session post."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {'type': 'sync'},
})
session = mock.Mock(**{'post.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
node.post()
session.post.assert_called_once_with('http://test.com', timeout=None)
示例10: test_post_missing_type_200
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_post_missing_type_200(self, Session):
"""A missing response type raises an exception."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {},
})
session = mock.Mock(**{'post.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
self.assertRaises(
exceptions.LXDAPIException,
node.post)
示例11: test_put
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_put(self, Session):
"""Perform a session put."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {'type': 'sync'},
})
session = mock.Mock(**{'put.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
node.put()
session.put.assert_called_once_with('http://test.com', timeout=None)
示例12: test_patch
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_patch(self, Session):
"""Perform a session patch."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {'type': 'sync'},
})
session = mock.Mock(**{'patch.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
node.patch()
session.patch.assert_called_once_with('http://test.com', timeout=None)
示例13: test_delete
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def test_delete(self, Session):
"""Perform a session delete."""
response = mock.Mock(**{
'status_code': 200,
'json.return_value': {'type': 'sync'},
})
session = mock.Mock(**{'delete.return_value': response})
Session.return_value = session
node = client._APINode('http://test.com')
node.delete()
session.delete.assert_called_once_with('http://test.com', timeout=None)
示例14: backend_request
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def backend_request(method, url, data):
session = requests_unixsocket.Session()
return session.request(method, '{0}{1}'.format(socket, url), data=data)
示例15: install
# 需要导入模块: import requests_unixsocket [as 别名]
# 或者: from requests_unixsocket import Session [as 别名]
def install(self, app_id):
self.logger.info('snap install')
session = requests_unixsocket.Session()
response = session.post('{0}/v2/snaps/{1}'.format(SOCKET, app_id), json={'action': 'install'})
self.logger.info("install response: {0}".format(response.text))