You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ponymail.apache.org by hu...@apache.org on 2020/08/24 10:44:38 UTC

[incubator-ponymail-foal] branch master updated: linting, fold lines that are >79 chars, consistency in quotes

This is an automated email from the ASF dual-hosted git repository.

humbedooh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-ponymail-foal.git


The following commit(s) were added to refs/heads/master by this push:
     new 40b437e  linting, fold lines that are >79 chars, consistency in quotes
40b437e is described below

commit 40b437e9ec9b58098dc9b7d08c97dd3805a06d82
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Mon Aug 24 12:44:25 2020 +0200

    linting, fold lines that are >79 chars, consistency in quotes
---
 tools/archiver.py | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/tools/archiver.py b/tools/archiver.py
index 1caf72b..c422108 100755
--- a/tools/archiver.py
+++ b/tools/archiver.py
@@ -84,6 +84,7 @@ def encode_base64(buff: bytes) -> str:
     """ Convert bytes to base64 as text string (no newlines) """
     return base64.standard_b64encode(buff).decode("ascii", "ignore")
 
+
 def mbox_source(b: bytes) -> str:
     # Common method shared with import-mbox
     try:
@@ -94,7 +95,6 @@ def mbox_source(b: bytes) -> str:
         return encode_base64(b)
 
 
-
 def parse_attachment(
     part: email.message.Message,
 ) -> typing.Tuple[typing.Optional[dict], typing.Optional[str]]:
@@ -168,7 +168,9 @@ class Body:
     def __init__(self, part: email.message.Message):
         self.content_type = part.get_content_type()
         self.charsets = set([part.get_content_charset()])  # Part's charset
-        self.charsets.update([part.get_charsets()[0]])  # Parent charset as fallback if any/different
+        self.charsets.update(
+            [part.get_charsets()[0]]
+        )  # Parent charset as fallback if any/different
         self.character_set = "us-ascii"
         self.string: typing.Optional[str] = None
         self.flowed = "format=flowed" in part.get("content-type", "")
@@ -206,7 +208,9 @@ class Body:
             if self.flowed:
                 # Convert lone LF to CRLF if found
                 if convert_lf:
-                    fixed_string = "\r\n".join([x.rstrip("\r") for x in self.string.split("\n")])
+                    fixed_string = "\r\n".join(
+                        [x.rstrip("\r") for x in self.string.split("\n")]
+                    )
                     conversion_was_needed = fixed_string != self.string
                 else:
                     fixed_string = self.string
@@ -217,7 +221,9 @@ class Body:
                 )
                 # If we "upconverted" from LF to CRLF, convert back after flow decoding
                 if convert_lf and conversion_was_needed:
-                    flow_fixed = "\n".join([x.rstrip("\r") for x in self.string.split("\n")])
+                    flow_fixed = "\n".join(
+                        [x.rstrip("\r") for x in self.string.split("\n")]
+                    )
                 return flow_fixed
         return self.string
 
@@ -247,11 +253,15 @@ class Archiver(object):  # N.B. Also used by import-mbox.py
         "x-mailman-rule-misses",
     ]
 
-    def __init__(self, generator=None, parse_html=False, ignore_body=None, verbose=False):
+    def __init__(
+        self, generator=None, parse_html=False, ignore_body=None, verbose=False
+    ):
         """ Just initialize ES. """
         self.html = parse_html
         # Fall back to full hashing if nothing is set.
-        self.generator = generator or config.get("archiver", "generator", fallback="full")
+        self.generator = generator or config.get(
+            "archiver", "generator", fallback="full"
+        )
         self.cropout = config.get("debug", "cropout")
         self.verbose = verbose
         self.ignore_body = ignore_body
@@ -260,9 +270,7 @@ class Archiver(object):  # N.B. Also used by import-mbox.py
 
             self.html2text = html2text.html2text
 
-    def message_body(
-        self, msg: email.message.Message
-    ) -> typing.Optional[Body]:
+    def message_body(self, msg: email.message.Message) -> typing.Optional[Body]:
         """
             Fetches the proper text body from an email as an archiver.Body object
         :param msg: The email or part of it to examine for proper body
@@ -303,7 +311,6 @@ class Archiver(object):  # N.B. Also used by import-mbox.py
             body.assign(self.html2text(str(body)))
         return body
 
-
     # N.B. this is also called by import-mbox.py
     def compute_updates(
         self,
@@ -428,7 +435,7 @@ class Archiver(object):  # N.B. Also used by import-mbox.py
                 "private": private,
                 "references": msg_metadata["references"],
                 "in-reply-to": irt,
-                "body": body.unflow() if body else '',
+                "body": body.unflow() if body else "",
                 "attachments": attachments,
             }
 
@@ -492,9 +499,7 @@ class Archiver(object):  # N.B. Also used by import-mbox.py
                     )
 
             elastic.index(
-                index=elastic.db_mbox,
-                id=ojson["mid"],
-                body=ojson,
+                index=elastic.db_mbox, id=ojson["mid"], body=ojson,
             )
 
             elastic.index(
@@ -727,7 +732,10 @@ def main():
         logging.basicConfig(stream=sys.stdout, level=logging.INFO)
 
     archie = Archiver(
-        generator=args.generator, parse_html=args.html2text, ignore_body=args.ibody, verbose=args.verbose
+        generator=args.generator,
+        parse_html=args.html2text,
+        ignore_body=args.ibody,
+        verbose=args.verbose,
     )
     # use binary input so parser can use appropriate charset
     input_stream = sys.stdin.buffer