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 2021/09/12 13:52:28 UTC

[incubator-ponymail-foal] branch master updated: Create textlib.py

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 7ac64ae  Create textlib.py
7ac64ae is described below

commit 7ac64ae407ddef430377dc53a45c73ca42de5ee9
Author: Daniel Gruno <hu...@apache.org>
AuthorDate: Sun Sep 12 08:52:26 2021 -0500

    Create textlib.py
---
 tools/plugins/textlib.py | 42 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/tools/plugins/textlib.py b/tools/plugins/textlib.py
new file mode 100644
index 0000000..0c55d6a
--- /dev/null
+++ b/tools/plugins/textlib.py
@@ -0,0 +1,42 @@
+#!/usr/bin/env python3
+# -*- coding: utf-8 -*-
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+"""Auxiliary text modding library for Apache Pony Mail (Foal)"""
+
+import re
+import typing
+
+def normalize_lid(lid: str, strict: bool = False) -> str:
+    """ Ensures that a List ID is in standard form, i.e. <a.b.c.d> """
+    # If of format "list name" <foo.bar.baz>
+    # we crop away the description (#511)
+    m = re.match(r'".*"\s+(.+)', lid)
+    if m:
+        lid = m.group(1)
+    # Drop <> and anything before/after, if found
+    m = re.search(r"<(.+)>", lid)
+    if m:
+        lid = m.group(1)
+    # Belt-and-braces: remove possible extraneous chars, ensure @s are converted to dots
+    lid = "<%s>" % lid.strip(" <>").replace("@", ".")
+    # Replace invalid characters with underscores so as to not invalidate doc IDs.
+    lid = re.sub(r"[^-+~_<>.a-zA-Z0-9@]", "_", lid)
+    # Finally, ensure we have a loosely valid list ID value
+    if strict and not re.match(r"^<.+\..+>$", lid):
+        print("Invalid list-id %s" % lid)
+        return None
+    return lid