diff cutils/util/__init__.py @ 379:6d7659a709f2

FIX: treesum: str.translate() behaves differently in Python3: make it PY3-compatible
author Franz Glasner <fzglas.hg@dom66.de>
date Mon, 12 May 2025 12:12:44 +0200
parents 54a6d4534ef4
children
line wrap: on
line diff
--- a/cutils/util/__init__.py	Mon May 12 09:48:23 2025 +0200
+++ b/cutils/util/__init__.py	Mon May 12 12:12:44 2025 +0200
@@ -13,6 +13,7 @@
 __all__ = ["PY2",
            "PY35",
            "n", "b", "u",
+           "parse_grouped_decimal_number",
            "normalize_filename",
            "escape_for_output",
            "argv2algo",
@@ -57,6 +58,9 @@
             return s.decode(encoding)
         return s
 
+    def parse_grouped_decimal_number(s):
+        return int(n(s).translate(None, "., '_"), 10)
+
 else:
 
     def n(s, encoding="ascii"):
@@ -73,6 +77,17 @@
 
     u = n
 
+    def parse_grouped_decimal_number(s):
+        return int(n(s).translate(NORMALIZATION_DELETE_CHARS), 10)
+
+    NORMALIZATION_DELETE_CHARS = {
+        ord('.'): None,
+        ord(','): None,
+        ord(' '): None,
+        ord("'"): None,
+        ord('_'): None
+    }
+
 
 def escape_for_output(what):
     """Escape `what` in such a way that the output can be safely written into