Skip to content
This repository was archived by the owner on Apr 15, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ python:
- pypy-5.3.1
- 3.5
- 3.6
- 3.7

install:
- pip install tox
Expand Down
21 changes: 11 additions & 10 deletions consul/std.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,43 @@
import requests
import urllib3

from consul import base


__all__ = ['Consul']
JSON_HEADER = {'Content-Type': 'application/json'}


class HTTPClient(base.HTTPClient):
def __init__(self, *args, **kwargs):
super(HTTPClient, self).__init__(*args, **kwargs)
self.session = requests.session()
cert_file = kwargs.get('cert', None)
cert_reqs = 'CERT_REQUIRED' if kwargs.get('verify', False) else None
self.session = urllib3.PoolManager(cert_file=cert_file,
cert_reqs=cert_reqs)

def response(self, response):
response.encoding = 'utf-8'
return base.Response(
response.status_code, response.headers, response.text)
response.status, response.headers, response.data.decode('utf-8'))

def get(self, callback, path, params=None):
uri = self.uri(path, params)
return callback(self.response(
self.session.get(uri, verify=self.verify, cert=self.cert)))
self.session.request('GET', uri)))

def put(self, callback, path, params=None, data=''):
uri = self.uri(path, params)
return callback(self.response(
self.session.put(uri, data=data, verify=self.verify,
cert=self.cert)))
self.session.request('PUT', uri, body=data, headers=JSON_HEADER)))

def delete(self, callback, path, params=None):
uri = self.uri(path, params)
return callback(self.response(
self.session.delete(uri, verify=self.verify, cert=self.cert)))
self.session.request('DELETE', uri)))

def post(self, callback, path, params=None, data=''):
uri = self.uri(path, params)
return callback(self.response(
self.session.post(uri, data=data, verify=self.verify,
cert=self.cert)))
self.session.request('POST', uri, body=data, headers=JSON_HEADER)))


class Consul(base.Consul):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
requests>=2.0
urllib3>=1.25
six>=1.4
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def run_tests(self):
url='https://github.com/cablehead/python-consul',
license='MIT',
description=description,
long_description=open('README.rst').read() + '\n\n' +
long_description=open('README.rst').read() + '\n\n' + # noqa: W504
open('CHANGELOG.rst').read(),
py_modules=py_modules,
install_requires=requirements,
Expand Down
12 changes: 8 additions & 4 deletions tests/test_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@


Check = consul.Check
if hasattr(asyncio, 'ensure_future'):
ensure_future = asyncio.ensure_future
else: # Deprecated since Python 3.4.4
ensure_future = getattr(asyncio, "async")


@pytest.fixture
Expand Down Expand Up @@ -74,7 +78,7 @@ def test_kv_missing(self, loop, consul_port):

@asyncio.coroutine
def main():
fut = asyncio.async(put(), loop=loop)
fut = ensure_future(put(), loop=loop)
yield from c.kv.put('index', 'bump')
index, data = yield from c.kv.get('foo')
assert data is None
Expand Down Expand Up @@ -133,7 +137,7 @@ def test_kv_subscribe(self, loop, consul_port):

@asyncio.coroutine
def get():
fut = asyncio.async(put(), loop=loop)
fut = ensure_future(put(), loop=loop)
index, data = yield from c.kv.get('foo')
assert data is None
index, data = yield from c.kv.get('foo', index=index)
Expand Down Expand Up @@ -197,7 +201,7 @@ def test_catalog(self, loop, consul_port):

@asyncio.coroutine
def nodes():
fut = asyncio.async(register(), loop=loop)
fut = ensure_future(register(), loop=loop)
index, nodes = yield from c.catalog.nodes()
assert len(nodes) == 1
current = nodes[0]
Expand Down Expand Up @@ -228,7 +232,7 @@ def test_session(self, loop, consul_port):

@asyncio.coroutine
def monitor():
fut = asyncio.async(register(), loop=loop)
fut = ensure_future(register(), loop=loop)
index, services = yield from c.session.list()
assert services == []
yield from asyncio.sleep(20/1000.0, loop=loop)
Expand Down
21 changes: 20 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = flake8, py26, py27, pypy, py35, py36
envlist = flake8, py26, py27, pypy, py35, py36, py37

[flake8]
ignore = F811,E226
Expand All @@ -21,6 +21,7 @@ commands =
deps =
pytest
pytest-rerunfailures
requests
commands =
py.test --reruns=3 {posargs:consul tests}

Expand All @@ -35,6 +36,7 @@ deps =
tornado
aiohttp
flake8
requests
commands =
py.test --reruns=3 {posargs:consul tests}
flake8 --exclude=".tox/*,xx/*,__*,docs/*"
Expand All @@ -50,6 +52,23 @@ deps =
tornado
aiohttp
flake8
requests
commands =
py.test --reruns=3 {posargs:consul tests}
flake8 --exclude=".tox/*,xx/*,__*,docs/*"

[testenv:py37]
deps =
pytest
pytest-rerunfailures
pytest-twisted
twisted
treq
pyOpenSSL
tornado
aiohttp
flake8
requests
commands =
py.test --reruns=3 {posargs:consul tests}
flake8 --exclude=".tox/*,xx/*,__*,docs/*"
Expand Down