Skip to content

Commit

Permalink
PEP8 (#57)
Browse files Browse the repository at this point in the history
* PEP8

* Fixed all the observations according to the agreements pep8.
* Added automatic tests (Travis CI) for compliance with pep8

* fix .travis.yml

* fix formating
  • Loading branch information
maksim77 authored Jun 30, 2016
1 parent a0f3f19 commit 8cbe539
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,17 @@ before_install:
- popd

install:
- pip install coveralls
- pip install coveralls pep8

script:
- while ! nc -z 127.0.0.1 10051; do sleep 1; done
- pep8 pyzabbix/
- pep8 tests/*.py
- coverage run setup.py test

after_success:
coveralls

notifications:
- email:
- [email protected]
email:
- [email protected]
10 changes: 6 additions & 4 deletions pyzabbix/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def fn(*args, **kwargs):

return fn


def ssl_context_compat(func):
def inner(req):
# We shoul explicitly disable cert verification to support
Expand Down Expand Up @@ -111,10 +112,12 @@ def inner(req):

return inner


@ssl_context_compat
def urlopen(*args, **kwargs):
return urllib2.urlopen(*args, **kwargs)


class ZabbixAPI(object):
"""ZabbixAPI class, implement interface to zabbix api.
Expand Down Expand Up @@ -213,8 +216,7 @@ def do_request(self, method, params=None):
}

# apiinfo.version and user.login doesn't require auth token
if (self.auth
and (method not in ('apiinfo.version', 'user.login'))):
if self.auth and (method not in ('apiinfo.version', 'user.login')):
request_json['auth'] = self.auth

logger.debug(
Expand Down Expand Up @@ -336,8 +338,8 @@ def get_id(self, item_type, item=None, with_id=False, hostid=None, **args):
for obj in response:
# Check if object not belong current template
if args.get('templateids'):
if (not obj.get('templateid') in ("0", None)
or not len(obj.get('templateids', [])) == 0):
if (not obj.get('templateid') in ("0", None) or
not len(obj.get('templateids', [])) == 0):
continue

if name:
Expand Down
1 change: 1 addition & 0 deletions pyzabbix/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import logging


class NullHandler(logging.Handler):
"""Null logger handler.
Expand Down
16 changes: 11 additions & 5 deletions pyzabbix/sender.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ def __init__(self):
self._total = 0
self._time = 0
self._chunk = 0

self._regex = re.compile(r'processed: (\d*); failed: (\d*); total: (\d*); seconds spent: (\d*\.\d*)')
pattern = (r'processed: (\d*); failed: (\d*); total: (\d*); '
'seconds spent: (\d*\.\d*)')
self._regex = re.compile(pattern)

def __repr__(self):
"""Represent detailed ZabbixResponse view."""
Expand Down Expand Up @@ -286,7 +287,12 @@ def _create_packet(self, request):
data_len = struct.pack('<Q', len(request))
packet = b'ZBXD\x01' + data_len + request

ord23 = lambda x: ord(x) if not isinstance(x, int) else x
def ord23(x):
if not isinstance(x, int):
return ord(x)
else:
return x

logger.debug('Packet [str]: %s', packet)
logger.debug('Packet [hex]: %s',
':'.join(hex(ord23(x))[2:] for x in packet))
Expand All @@ -305,8 +311,8 @@ def _get_response(self, connection):
response_header = self._receive(connection, 13)
logger.debug('Response header: %s', response_header)

if (not response_header.startswith(b'ZBXD\x01')
or len(response_header) != 13):
if (not response_header.startswith(b'ZBXD\x01') or
len(response_header) != 13):
logger.debug('Zabbix return not valid response.')
result = False
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ def response(*args, **kwargs):
arg, context = test_decorator(True)
self.assertIs(arg[0], True)
self.assertIn('context', context, msg='SSL context is missing.')
self.assertIsNotNone(context.get('context'), msg='SSL context is None.')
self.assertIsNotNone(context.get('context'),
msg='SSL context is None.')

def test_api_version(self):
ret = {'result': '2.2.5'}
Expand Down

0 comments on commit 8cbe539

Please sign in to comment.