• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python http.HttpClient类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中pulsar.apps.http.HttpClient的典型用法代码示例。如果您正苦于以下问题:Python HttpClient类的具体用法?Python HttpClient怎么用?Python HttpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了HttpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_graph

 def test_graph(self):
     c = HttpClient()
     handler = Echo(c._loop)
     ws = yield c.get(self.ws_uri, websocket_handler=handler)
     self.assertEqual(ws.event('post_request').fired(), 0)
     message = yield handler.get()
     self.assertTrue(message)
开发者ID:axisofentropy,项目名称:pulsar,代码行数:7,代码来源:tests.py


示例2: test_login

 def test_login(self):
     http = HttpClient()
     url = self.url + self.app.config['LOGIN_URL']
     response = yield from http.get(url)
     cookie = response.cookies.get('luxtest')
     self.assertTrue(cookie)
     self.assertEqual(response.status_code, 200)
     doc = self.bs(response)
     token = self.authenticity_token(doc)
     self.assertEqual(len(token), 1)
     # try to login
     data = {'username': 'pippo', 'password': 'pluto'}
     response2 = yield from http.post(url, data=data)
     self.assertEqual(response2.status_code, 403)
     #
     # Add csrf token
     data.update(token)
     response2 = yield from http.post(url, data=data)
     self.assertEqual(response2.status_code, 200)
     cookie2 = response2.cookies.get('luxtest')
     self.assertTrue(cookie2)
     self.assertNotEqual(cookie2.value, cookie.value)
     self.assertEqual(response2.headers['content-type'],
                      'application/json; charset=utf-8')
     data = response2.json()
     self.assertTrue('redirect' in data)
     self.assertEqual(data['success'], True)
     #
     # Login again should cause MethodNotAllowed
     response3 = yield from http.post(url, data=data)
     self.assertEqual(response3.status_code, 405)
开发者ID:SirZazu,项目名称:lux,代码行数:31,代码来源:all.py


示例3: setup

 def setup(self, http=None, timeout=None, **kw):
     if not http:
         timeout = timeout if timeout is not None else self.default_timeout
         http = HttpClient(timeout=timeout, **kw)
     http.headers['accept'] = 'application/json, text/*; q=0.5'
     http.headers['content-type'] = 'application/json'
     self.local.http = http
开发者ID:BazookaShao,项目名称:pulsar,代码行数:7,代码来源:jsonrpc.py


示例4: __init__

 def __init__(
     self,
     url,
     version=None,
     data=None,
     full_response=False,
     http=None,
     timeout=None,
     sync=False,
     loop=None,
     encoding="ascii",
     **kw
 ):
     self.sync = sync
     self._url = url
     self._version = version or self.__class__.default_version
     self._full_response = full_response
     self._data = data if data is not None else {}
     if not http:
         timeout = timeout if timeout is not None else self.default_timeout
         if sync and not loop:
             loop = new_event_loop()
         http = HttpClient(timeout=timeout, loop=loop, **kw)
     http.headers["accept"] = "application/json, text/*; q=0.5"
     http.headers["content-type"] = "application/json"
     self._http = http
     self._encoding = encoding
开发者ID:quantmind,项目名称:pulsar,代码行数:27,代码来源:jsonrpc.py


示例5: test_pong

 def test_pong(self):
     c = HttpClient()
     handler = Echo()
     ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
     #
     ws.ping('TESTING CLIENT PING')
     message = yield handler.get()
     self.assertEqual(message, 'PONG: TESTING CLIENT PING')
开发者ID:xmnlab,项目名称:minilab,代码行数:8,代码来源:tests.py


示例6: test_verify

 def test_verify(self):
     c = HttpClient()
     yield from self.async.assertRaises(SSLError, c.get, self.httpbin())
     response = yield from c.get(self.httpbin(), verify=False)
     self.assertEqual(response.status_code, 200)
     response = yield from c.get(self.httpbin(), verify=crt)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.request.verify, crt)
开发者ID:arhik,项目名称:pulsar,代码行数:8,代码来源:tls.py


示例7: test_ping

 def test_ping(self):
     c = HttpClient()
     handler = Echo()
     ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
     #
     # ASK THE SERVER TO SEND A PING FRAME
     ws.write('send ping TESTING PING')
     message = yield handler.get()
     self.assertEqual(message, 'PING: TESTING PING')
开发者ID:xmnlab,项目名称:minilab,代码行数:9,代码来源:tests.py


示例8: coveralls

def coveralls(http=None, url=None, data_file=None, repo_token=None,
              git=None, service_name=None, service_job_id=None,
              strip_dirs=None, ignore_errors=False, stream=None):
    '''Send a coverage report to coveralls.io.

    :param http: optional http client
    :param url: optional url to send data to. It defaults to ``coveralls``
        api url.
    :param data_file: optional data file to load coverage data from. By
        default, coverage uses ``.coverage``.
    :param repo_token: required when not submitting from travis.

    https://coveralls.io/docs/api
    '''
    stream = stream or sys.stdout
    coverage = Coverage(data_file=data_file)
    coverage.load()
    if http is None:
        http = HttpClient(loop=new_event_loop())

    if not git:
        try:
            git = gitrepo()
        except Exception:   # pragma    nocover
            pass

    data = {'source_files': coverage.coveralls(strip_dirs=strip_dirs,
                                               ignore_errors=ignore_errors)}

    if git:
        data['git'] = git

    if os.environ.get('TRAVIS'):
        data['service_name'] = service_name or 'travis-ci'
        data['service_job_id'] = os.environ.get('TRAVIS_JOB_ID')
    else:
        assert repo_token, 'Requires repo_token if not submitting from travis'

    if repo_token:
        data['repo_token'] = repo_token
    url = url or COVERALLS_URL
    stream.write('Submitting coverage report to %s\n' % url)
    response = http.post(url, files={'json_file': json.dumps(data)})
    stream.write('Response code: %s\n' % response.status_code)
    try:
        info = response.json()
        code = 0
        if 'error' in info:
            stream.write('An error occured while sending coverage'
                         ' report to coverall.io')
            code = 1
        stream.write('\n%s\n' % info['message'])
    except Exception:
        code = 1
        stream.write('Critical error %s\n' % response.status_code)
    return code
开发者ID:Danzeer,项目名称:pulsar,代码行数:56,代码来源:cov.py


示例9: minify

 def minify(self, options, data):
     b = convert_bytes(len(data))
     self.write('Minimise %s css file via http://cssminifier.com' % b)
     http = HttpClient(loop=new_event_loop())
     response = http.post('http://cssminifier.com/raw',
                          data={'input': data})
     if response.status_code == 200:
         return native_str(response.get_content())
     else:
         response.raise_for_status()
开发者ID:pombredanne,项目名称:lux,代码行数:10,代码来源:style.py


示例10: test_dodgy_on_header_event

 def test_dodgy_on_header_event(self):
     client = HttpClient()
     hook = partial(dodgyhook, self)
     response = client.get(self.httpbin(), on_headers=hook)
     try:
         yield response.on_finished
     except ValueError:
         pass
     self.assertTrue(response.headers)
     self.assertIsInstance(response.on_headers.result, Failure)
开发者ID:elimisteve,项目名称:pulsar,代码行数:10,代码来源:client.py


示例11: test_close

 def test_close(self):
     c = HttpClient()
     handler = Echo()
     ws = yield c.get(self.ws_echo, websocket_handler=handler)
     self.assertEqual(ws.event('post_request').fired(), 0)
     ws.write('send close 1001')
     message = yield handler.get()
     self.assertEqual(message, 'CLOSE')
     self.assertTrue(ws.close_reason)
     self.assertEqual(ws.close_reason[0], 1001)
     self.assertTrue(ws._connection.closed)
开发者ID:LoganTK,项目名称:pulsar,代码行数:11,代码来源:tests.py


示例12: __init__

 def __init__(self, url, version=None, data=None,
              full_response=False, http=None, timeout=None, **kw):
     self._url = url
     self._version = version or self.__class__.default_version
     self._full_response = full_response
     self._data = data if data is not None else {}
     if not http:
         timeout = timeout if timeout is not None else self.default_timeout
         http = HttpClient(timeout=timeout, **kw)
     http.headers['accept'] = 'application/json, text/*; q=0.5'
     http.headers['content-type'] = 'application/json'
     self._http = http
开发者ID:axisofentropy,项目名称:pulsar,代码行数:12,代码来源:jsonrpc.py


示例13: test_home

 def test_home(self):
     http = HttpClient()
     response = yield from http.get(self.url)
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.headers['content-type'],
                      'text/html; charset=utf-8')
     cookie = response.cookies.get('luxtest')
     self.assertTrue(cookie)
     self.assertTrue(cookie.value)
     response = yield from http.get(self.url)
     cookie2 = response.cookies.get('luxtest')
     self.assertFalse(cookie2)
开发者ID:SirZazu,项目名称:lux,代码行数:12,代码来源:all.py


示例14: test_close_sync

 def test_close_sync(self):
     loop = new_event_loop()
     c = HttpClient(loop=loop)
     handler = Echo(loop)
     ws = c.get(self.ws_echo, websocket_handler=handler)
     self.assertEqual(ws.event('post_request').fired(), 0)
     self.assertEqual(ws._loop, loop)
     self.assertFalse(ws._loop.is_running())
     ws.write('send close 1001')
     message = ws._loop.run_until_complete(handler.get())
     self.assertEqual(message, 'CLOSE')
     self.assertTrue(ws.close_reason)
     self.assertEqual(ws.close_reason[0], 1001)
     self.assertTrue(ws._connection.closed)
开发者ID:LoganTK,项目名称:pulsar,代码行数:14,代码来源:tests.py


示例15: testBadRequests

 def testBadRequests(self):
     c = HttpClient()
     response = yield c.post(self.ws_uri)
     self.assertEqual(response.status_code, 405)
     #
     response = yield c.get(self.ws_uri,
                            headers=[('Sec-Websocket-Key', 'x')])
     self.assertEqual(response.status_code, 400)
     #
     response = yield c.get(self.ws_uri,
                            headers=[('Sec-Websocket-Key', 'bla')])
     self.assertEqual(response.status_code, 400)
     #
     response = yield c.get(self.ws_uri,
                            headers=[('Sec-Websocket-version', 'xxx')])
     self.assertEqual(response.status_code, 400)
开发者ID:LoganTK,项目名称:pulsar,代码行数:16,代码来源:tests.py


示例16: test_upgrade

 def test_upgrade(self):
     c = HttpClient()
     handler = Echo()
     ws = yield c.get(self.ws_echo, websocket_handler=handler).on_headers
     response = ws.handshake
     self.assertEqual(response.status_code, 101)
     self.assertEqual(response.headers['upgrade'], 'websocket')
     self.assertEqual(ws.connection, response.connection)
     self.assertEqual(ws.handler, handler)
     #
     # on_finished
     self.assertFalse(response.on_finished.done())
     self.assertFalse(ws.on_finished.done())
     # Send a message to the websocket
     ws.write('Hi there!')
     message = yield handler.get()
     self.assertEqual(message, 'Hi there!')
开发者ID:xmnlab,项目名称:minilab,代码行数:17,代码来源:tests.py


示例17: coveralls

def coveralls(http=None, url=None, data_file=None, repo_token=None, git=None,
              service_name=None, service_job_id=None, strip_dirs=None,
              ignore_errors=False, stream=None):
    '''Send a coverage report to coveralls.io.

    :param http: optional http client
    :param url: optional url to send data to. It defaults to ``coveralls``
        api url.
    :param data_file: optional data file to load coverage data from. By
        default, coverage uses ``.coverage``.
    :param repo_token: required when not submitting from travis.

    https://coveralls.io/docs/api
    '''
    stream = stream or sys.stdout
    coverage = Coverage(data_file=data_file)
    coverage.load()
    if http is None:
        from pulsar.apps.http import HttpClient
        http = HttpClient(force_sync=True)
    if not service_job_id:
        service_job_id = os.environ.get('TRAVIS_JOB_ID', '')
        if service_job_id:
            service_name = 'travis-ci'
    if not git:
        git = gitrepo()
    data = {
        'service_job_id': service_job_id,
        'service_name': service_name or 'pulsar',
        'git': git,
        'source_files': coverage.coveralls(strip_dirs, ignore_errors),
    }
    if repo_token:
        data['repo_token'] = repo_token
    url = url or COVERALLS_URL
    stream.write('Submitting coverage report to %s\n' % url)
    response = http.post(url, files={'json_file': json.dumps(data)})
    stream.write('Response code: %s\n' % response.status_code)
    info = response.json()
    if 'error' in info:
        stream.write('An error occured while sending coverage'
                     ' report to coverall.io')
    stream.write('\n%s' % info['message'])
开发者ID:BazookaShao,项目名称:pulsar,代码行数:43,代码来源:cov.py


示例18: media_libraries

def media_libraries():
    global _media_libraries
    if _media_libraries is None:
        if os.path.isfile('libs.json'):     # pragma    nocover
            with open('libs.json') as f:
                data = f.read()
            _media_libraries = json.loads(data)
        else:
            from pulsar import new_event_loop
            from pulsar.apps.http import HttpClient
            http = HttpClient(loop=new_event_loop())
            try:
                response = http.get(_libs_url)
                _media_libraries = response.json()
            except Exception:   # pragma    nocover
                http.logger.error('Could not import media library',
                                  exc_info=True)
                _media_libraries = {'libs': {}, 'deps': {}}
    return _media_libraries
开发者ID:axisofentropy,项目名称:pulsar,代码行数:19,代码来源:content.py


示例19: monitor_start

 def monitor_start(self, monitor):
     # this application has no workers
     self.cfg.set('workers', 0)
     api_key = self.get_param('twitter_api_key')
     client_secret = self.get_param('twitter_api_secret')
     access_token = self.get_param('twitter_access_token')
     access_secret = self.get_param('twitter_access_secret')
     self._http = HttpClient(encode_multipart=False)
     oauth2 = OAuth1(api_key,
                     client_secret=client_secret,
                     resource_owner_key=access_token,
                     resource_owner_secret=access_secret)
     self._http.bind_event('pre_request', oauth2)
     self.buffer = []
     self.connect()
开发者ID:JinsongBian,项目名称:pulsar,代码行数:15,代码来源:manage.py


示例20: worker_start

 def worker_start(self, worker, exc=None):
     '''When the worker starts :meth:`connect` to twitter spreaming
     endpoint
     '''
     api_key = self.get_param('twitter_api_key')
     client_secret = self.get_param('twitter_api_secret')
     access_token = self.get_param('twitter_access_token')
     access_secret = self.get_param('twitter_access_secret')
     self._http = HttpClient(encode_multipart=False)
     oauth1 = OAuth1(api_key,
                     client_secret=client_secret,
                     resource_owner_key=access_token,
                     resource_owner_secret=access_secret)
     self._http.bind_event('pre_request', oauth1)
     self.buffer = []
     self.connect()
开发者ID:Danzeer,项目名称:pulsar,代码行数:16,代码来源:twitter.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python wsgi.Route类代码示例发布时间:2022-05-25
下一篇:
Python data.create_store函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap