當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。