Skip to content

Commit 73807b4

Browse files
wesleybowmankeszybz
authored andcommitted
Fix styling to match PEP8 in most places (#45)
Backwards compatibility for mapPriority is retained.
1 parent e121ae4 commit 73807b4

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

systemd/journal.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,24 @@
4444
else:
4545
Monotonic = tuple
4646

47+
4748
def _convert_monotonic(m):
4849
return Monotonic((_datetime.timedelta(microseconds=m[0]),
4950
_uuid.UUID(bytes=m[1])))
5051

52+
5153
def _convert_source_monotonic(s):
5254
return _datetime.timedelta(microseconds=int(s))
5355

56+
5457
def _convert_realtime(t):
5558
return _datetime.datetime.fromtimestamp(t / 1000000)
5659

60+
5761
def _convert_timestamp(s):
5862
return _datetime.datetime.fromtimestamp(int(s) / 1000000)
5963

64+
6065
def _convert_trivial(x):
6166
return x
6267

@@ -104,9 +109,11 @@ def _convert_uuid(s):
104109

105110
_IDENT_CHARACTER = set('ABCDEFGHIJKLMNOPQRTSUVWXYZ_0123456789')
106111

112+
107113
def _valid_field_name(s):
108114
return not (set(s) - _IDENT_CHARACTER)
109115

116+
110117
class Reader(_Reader):
111118
"""Access systemd journal entries.
112119
@@ -165,7 +172,7 @@ def __init__(self, flags=None, path=None, files=None, converters=None):
165172
flags = 0
166173

167174
super(Reader, self).__init__(flags, path, files)
168-
if _sys.version_info >= (3,3):
175+
if _sys.version_info >= (3, 3):
169176
self.converters = _ChainMap()
170177
if converters is not None:
171178
self.converters.maps.append(converters)
@@ -392,6 +399,7 @@ def get_catalog(mid):
392399
mid = mid.hex
393400
return _get_catalog(mid)
394401

402+
395403
def _make_line(field, value):
396404
if isinstance(value, bytes):
397405
return field.encode('utf-8') + b'=' + value
@@ -400,6 +408,7 @@ def _make_line(field, value):
400408
else:
401409
return field + '=' + str(value)
402410

411+
403412
def send(MESSAGE, MESSAGE_ID=None,
404413
CODE_FILE=None, CODE_LINE=None, CODE_FUNC=None,
405414
**kwargs):
@@ -435,7 +444,7 @@ def send(MESSAGE, MESSAGE_ID=None,
435444
id = getattr(MESSAGE_ID, 'hex', MESSAGE_ID)
436445
args.append('MESSAGE_ID=' + id)
437446

438-
if CODE_LINE == CODE_FILE == CODE_FUNC == None:
447+
if CODE_LINE is CODE_FILE is CODE_FUNC is None:
439448
CODE_FILE, CODE_LINE, CODE_FUNC = _traceback.extract_stack(limit=2)[0][:3]
440449
if CODE_FILE is not None:
441450
args.append('CODE_FILE=' + CODE_FILE)
@@ -447,6 +456,7 @@ def send(MESSAGE, MESSAGE_ID=None,
447456
args.extend(_make_line(key, val) for key, val in kwargs.items())
448457
return sendv(*args)
449458

459+
450460
def stream(identifier=None, priority=LOG_INFO, level_prefix=False):
451461
r"""Return a file object wrapping a stream to journal.
452462
@@ -490,6 +500,7 @@ def stream(identifier=None, priority=LOG_INFO, level_prefix=False):
490500
fd = stream_fd(identifier, priority, level_prefix)
491501
return _os.fdopen(fd, 'w', 1)
492502

503+
493504
class JournalHandler(_logging.Handler):
494505
"""Journal handler class for the Python logging framework.
495506
@@ -560,11 +571,11 @@ def emit(self, record):
560571
"""
561572
try:
562573
msg = self.format(record)
563-
pri = self.mapPriority(record.levelno)
574+
pri = self.map_priority(record.levelno)
564575
mid = getattr(record, 'MESSAGE_ID', None)
565-
extras = {k:str(v) for k,v in self._extra.items()}
576+
extras = {k: str(v) for k, v in self._extra.items()}
566577
extras.update({
567-
k:str(v) for k,v in record.__dict__.items()
578+
k: str(v) for k, v in record.__dict__.items()
568579
})
569580

570581
if record.exc_text:
@@ -590,7 +601,7 @@ def emit(self, record):
590601
self.handleError(record)
591602

592603
@staticmethod
593-
def mapPriority(levelno):
604+
def map_priority(levelno):
594605
"""Map logging levels to journald priorities.
595606
596607
Since Python log level numbers are "sparse", we have to map numbers in
@@ -608,3 +619,5 @@ def mapPriority(levelno):
608619
return LOG_CRIT
609620
else:
610621
return LOG_ALERT
622+
623+
mapPriority = map_priority

systemd/test/test_journal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def skip_valueerror():
5757
pytest.skip()
5858

5959
def test_priorities():
60-
p = journal.JournalHandler.mapPriority
60+
p = journal.JournalHandler.map_priority
6161

6262
assert p(logging.NOTSET) == journal.LOG_DEBUG
6363
assert p(logging.DEBUG) == journal.LOG_DEBUG

0 commit comments

Comments
 (0)