Skip to content

Commit 9d0d1ad

Browse files
committed
Fix styling to match PEP8 in most places
1 parent 8921c79 commit 9d0d1ad

File tree

2 files changed

+19
-7
lines changed

2 files changed

+19
-7
lines changed

systemd/journal.py

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

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

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

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

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

63+
5964
def _convert_trivial(x):
6065
return x
6166

@@ -103,9 +108,11 @@ def _convert_uuid(s):
103108

104109
_IDENT_CHARACTER = set('ABCDEFGHIJKLMNOPQRTSUVWXYZ_0123456789')
105110

111+
106112
def _valid_field_name(s):
107113
return not (set(s) - _IDENT_CHARACTER)
108114

115+
109116
class Reader(_Reader):
110117
"""Access systemd journal entries.
111118
@@ -164,7 +171,7 @@ def __init__(self, flags=None, path=None, files=None, converters=None):
164171
flags = 0
165172

166173
super(Reader, self).__init__(flags, path, files)
167-
if _sys.version_info >= (3,3):
174+
if _sys.version_info >= (3, 3):
168175
self.converters = _ChainMap()
169176
if converters is not None:
170177
self.converters.maps.append(converters)
@@ -391,6 +398,7 @@ def get_catalog(mid):
391398
mid = mid.hex
392399
return _get_catalog(mid)
393400

401+
394402
def _make_line(field, value):
395403
if isinstance(value, bytes):
396404
return field.encode('utf-8') + b'=' + value
@@ -399,6 +407,7 @@ def _make_line(field, value):
399407
else:
400408
return field + '=' + str(value)
401409

410+
402411
def send(MESSAGE, MESSAGE_ID=None,
403412
CODE_FILE=None, CODE_LINE=None, CODE_FUNC=None,
404413
**kwargs):
@@ -434,7 +443,7 @@ def send(MESSAGE, MESSAGE_ID=None,
434443
id = getattr(MESSAGE_ID, 'hex', MESSAGE_ID)
435444
args.append('MESSAGE_ID=' + id)
436445

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

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

502+
492503
class JournalHandler(_logging.Handler):
493504
"""Journal handler class for the Python logging framework.
494505
@@ -549,6 +560,7 @@ def __init__(self, level=_logging.NOTSET, **kwargs):
549560

550561
self.send = kwargs.pop('SENDER_FUNCTION', send)
551562
self._extra = kwargs
563+
self.mapPriority = self.map_priority
552564

553565
def emit(self, record):
554566
"""Write `record` as a journal event.
@@ -559,11 +571,11 @@ def emit(self, record):
559571
"""
560572
try:
561573
msg = self.format(record)
562-
pri = self.mapPriority(record.levelno)
574+
pri = self.map_priority(record.levelno)
563575
mid = getattr(record, 'MESSAGE_ID', None)
564-
extras = { k:str(v) for k,v in self._extra.items() }
576+
extras = {k: str(v) for k, v in self._extra.items()}
565577
extras.update({
566-
k:str(v) for k,v in record.__dict__.items()
578+
k: str(v) for k, v in record.__dict__.items()
567579
})
568580

569581
if record.exc_text:
@@ -589,7 +601,7 @@ def emit(self, record):
589601
self.handleError(record)
590602

591603
@staticmethod
592-
def mapPriority(levelno):
604+
def map_priority(levelno):
593605
"""Map logging levels to journald priorities.
594606
595607
Since Python log level numbers are "sparse", we have to map numbers in

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)