当前位置: 首页>>代码示例>>Python>>正文


Python requests_unixsocket.Session方法代码示例

本文整理汇总了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
        ) 
开发者ID:syncloud,项目名称:platform,代码行数:19,代码来源:snap.py

示例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!' 
开发者ID:msabramo,项目名称:requests-unixsocket,代码行数:26,代码来源:test_requests_unixsocket.py

示例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) 
开发者ID:cloudbase,项目名称:coriolis,代码行数:21,代码来源:data_transfer.py

示例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 
开发者ID:anybox,项目名称:buttervolume,代码行数:19,代码来源:cli.py

示例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 
开发者ID:lxc,项目名称:pylxd,代码行数:12,代码来源:client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:6,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:6,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:14,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:13,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:14,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:13,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:13,代码来源:test_client.py

示例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) 
开发者ID:lxc,项目名称:pylxd,代码行数:13,代码来源:test_client.py

示例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) 
开发者ID:syncloud,项目名称:platform,代码行数:5,代码来源:backend_proxy.py

示例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)) 
开发者ID:syncloud,项目名称:platform,代码行数:7,代码来源:snap.py


注:本文中的requests_unixsocket.Session方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。