mirror of
https://blitiri.com.ar/repos/chasquid
synced 2025-12-23 15:37:01 +00:00
Auto-format the Python scripts
We have a few Python scripts which over the years ended up with a variety of formatting. This patch auto-formats them using `black -l 79` to make them more uniform, and easier to read and write.
This commit is contained in:
@@ -24,11 +24,11 @@ def flexible_eq(expected, got):
|
||||
if posG >= len(got):
|
||||
return False
|
||||
|
||||
if c == '?':
|
||||
if c == "?":
|
||||
posG += 1
|
||||
continue
|
||||
if c == '*':
|
||||
while posG < len(got) and got[posG] != '\t':
|
||||
if c == "*":
|
||||
while posG < len(got) and got[posG] != "\t":
|
||||
posG += 1
|
||||
continue
|
||||
continue
|
||||
@@ -46,58 +46,60 @@ def flexible_eq(expected, got):
|
||||
|
||||
|
||||
def msg_equals(expected, msg):
|
||||
"""Compare two messages recursively, using flexible_eq()."""
|
||||
diff = False
|
||||
for h, val in expected.items():
|
||||
if h not in msg:
|
||||
print("Header missing: %r" % h)
|
||||
diff = True
|
||||
continue
|
||||
"""Compare two messages recursively, using flexible_eq()."""
|
||||
diff = False
|
||||
for h, val in expected.items():
|
||||
if h not in msg:
|
||||
print("Header missing: %r" % h)
|
||||
diff = True
|
||||
continue
|
||||
|
||||
if expected[h] == '*':
|
||||
continue
|
||||
if expected[h] == "*":
|
||||
continue
|
||||
|
||||
if not flexible_eq(val, msg[h]):
|
||||
print("Header %r differs:" % h)
|
||||
print("Exp: %r" % val)
|
||||
print("Got: %r" % msg[h])
|
||||
diff = True
|
||||
if not flexible_eq(val, msg[h]):
|
||||
print("Header %r differs:" % h)
|
||||
print("Exp: %r" % val)
|
||||
print("Got: %r" % msg[h])
|
||||
diff = True
|
||||
|
||||
if diff:
|
||||
return False
|
||||
if diff:
|
||||
return False
|
||||
|
||||
if expected.is_multipart() != msg.is_multipart():
|
||||
print("Multipart differs, expected %s, got %s" % (
|
||||
expected.is_multipart(), msg.is_multipart()))
|
||||
return False
|
||||
if expected.is_multipart() != msg.is_multipart():
|
||||
print(
|
||||
"Multipart differs, expected %s, got %s"
|
||||
% (expected.is_multipart(), msg.is_multipart())
|
||||
)
|
||||
return False
|
||||
|
||||
if expected.is_multipart():
|
||||
for exp, got in itertools.zip_longest(expected.get_payload(), msg.get_payload()):
|
||||
if not msg_equals(exp, got):
|
||||
return False
|
||||
else:
|
||||
if not flexible_eq(expected.get_payload(), msg.get_payload()):
|
||||
exp = expected.get_payload().splitlines()
|
||||
got = msg.get_payload().splitlines()
|
||||
print("Payload differs:")
|
||||
for l in difflib.ndiff(exp, got):
|
||||
print(l)
|
||||
return False
|
||||
if expected.is_multipart():
|
||||
for exp, got in itertools.zip_longest(
|
||||
expected.get_payload(), msg.get_payload()
|
||||
):
|
||||
if not msg_equals(exp, got):
|
||||
return False
|
||||
else:
|
||||
if not flexible_eq(expected.get_payload(), msg.get_payload()):
|
||||
exp = expected.get_payload().splitlines()
|
||||
got = msg.get_payload().splitlines()
|
||||
print("Payload differs:")
|
||||
for l in difflib.ndiff(exp, got):
|
||||
print(l)
|
||||
return False
|
||||
|
||||
return True
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
f1, f2 = sys.argv[1:3]
|
||||
f1, f2 = sys.argv[1:3]
|
||||
|
||||
# We use a custom strict policy to do more strict content validation.
|
||||
policy = email.policy.EmailPolicy(
|
||||
utf8=True,
|
||||
linesep="\r\n",
|
||||
refold_source='none',
|
||||
raise_on_defect=True)
|
||||
# We use a custom strict policy to do more strict content validation.
|
||||
policy = email.policy.EmailPolicy(
|
||||
utf8=True, linesep="\r\n", refold_source="none", raise_on_defect=True
|
||||
)
|
||||
|
||||
expected = email.parser.Parser(policy=policy).parse(open(f1))
|
||||
msg = email.parser.Parser(policy=policy).parse(open(f2))
|
||||
expected = email.parser.Parser(policy=policy).parse(open(f1))
|
||||
msg = email.parser.Parser(policy=policy).parse(open(f2))
|
||||
|
||||
sys.exit(0 if msg_equals(expected, msg) else 1)
|
||||
sys.exit(0 if msg_equals(expected, msg) else 1)
|
||||
|
||||
Reference in New Issue
Block a user