mirror of
https://github.com/ansible-collections/community.docker.git
synced 2026-07-29 11:55:04 +00:00
Python code modernization, 4/n (#1162)
* Address attribute-defined-outside-init. * Address broad-exception-raised. * Address broad-exception-caught. * Address consider-iterating-dictionary. * Address consider-using-dict-comprehension. * Address consider-using-f-string. * Address consider-using-in. * Address consider-using-max-builtin. * Address some consider-using-with. * Address invalid-name. * Address keyword-arg-before-vararg. * Address line-too-long. * Address no-else-continue. * Address no-else-raise. * Address no-else-return. * Remove broken dead code. * Make consider-using-f-string changes compatible with older Python versions. * Python 3.11 and earlier apparently do not like multi-line f-strings.
This commit is contained in:
@@ -133,38 +133,35 @@ def parse_line(line, logrus_mode=False):
|
||||
key.append(cur)
|
||||
parser.next()
|
||||
return _Mode.KEY
|
||||
elif cur == "=":
|
||||
if cur == "=":
|
||||
parser.next()
|
||||
return _Mode.EQUAL
|
||||
else:
|
||||
if logrus_mode:
|
||||
raise InvalidLogFmt('Key must always be followed by "=" in logrus mode')
|
||||
handle_kv(has_no_value=True)
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
if logrus_mode:
|
||||
raise InvalidLogFmt('Key must always be followed by "=" in logrus mode')
|
||||
handle_kv(has_no_value=True)
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
|
||||
def parse_equal(cur):
|
||||
if _is_ident(cur):
|
||||
value.append(cur)
|
||||
parser.next()
|
||||
return _Mode.IDENT_VALUE
|
||||
elif cur == '"':
|
||||
if cur == '"':
|
||||
parser.next()
|
||||
return _Mode.QUOTED_VALUE
|
||||
else:
|
||||
handle_kv()
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
handle_kv()
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
|
||||
def parse_ident_value(cur):
|
||||
if _is_ident(cur):
|
||||
value.append(cur)
|
||||
parser.next()
|
||||
return _Mode.IDENT_VALUE
|
||||
else:
|
||||
handle_kv()
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
handle_kv()
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
|
||||
def parse_quoted_value(cur):
|
||||
if cur == "\\":
|
||||
@@ -182,16 +179,15 @@ def parse_line(line, logrus_mode=False):
|
||||
value.append(parser.parse_unicode_sequence())
|
||||
parser.next()
|
||||
return _Mode.QUOTED_VALUE
|
||||
elif cur == '"':
|
||||
if cur == '"':
|
||||
handle_kv()
|
||||
parser.next()
|
||||
return _Mode.GARBAGE
|
||||
elif cur < " ":
|
||||
if cur < " ":
|
||||
raise InvalidLogFmt("Control characters in quoted string are not allowed")
|
||||
else:
|
||||
value.append(cur)
|
||||
parser.next()
|
||||
return _Mode.QUOTED_VALUE
|
||||
value.append(cur)
|
||||
parser.next()
|
||||
return _Mode.QUOTED_VALUE
|
||||
|
||||
parsers = {
|
||||
_Mode.GARBAGE: parse_garbage,
|
||||
@@ -204,7 +200,7 @@ def parse_line(line, logrus_mode=False):
|
||||
mode = parsers[mode](parser.cur())
|
||||
if mode == _Mode.KEY and logrus_mode:
|
||||
raise InvalidLogFmt('Key must always be followed by "=" in logrus mode')
|
||||
if mode == _Mode.KEY or mode == _Mode.EQUAL:
|
||||
if mode in (_Mode.KEY, _Mode.EQUAL):
|
||||
handle_kv(has_no_value=True)
|
||||
elif mode == _Mode.IDENT_VALUE:
|
||||
handle_kv()
|
||||
|
||||
Reference in New Issue
Block a user