diff sat/tools/common/regex.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 85b8a899f407
children
line wrap: on
line diff
--- a/sat/tools/common/regex.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/tools/common/regex.py	Sat Apr 08 13:54:42 2023 +0200
@@ -33,12 +33,12 @@
 TEXT_WORD_MIN_LENGHT = 0
 
 
-def reJoin(exps):
+def re_join(exps):
     """Join (OR) various regexes"""
     return re.compile("|".join(exps))
 
 
-def reSubDict(pattern, repl_dict, string):
+def re_sub_dict(pattern, repl_dict, string):
     """Replace key, value found in dict according to pattern
 
     @param pattern(basestr): pattern using keys found in repl_dict
@@ -49,29 +49,29 @@
     return pattern.sub(lambda m: repl_dict[re.escape(m.group(0))], string)
 
 
-path_escape_re = reJoin(list(path_escape.keys()))
-path_escape_rev_re = reJoin(list(path_escape_rev.keys()))
+path_escape_re = re_join(list(path_escape.keys()))
+path_escape_rev_re = re_join(list(path_escape_rev.keys()))
 
 
-def pathEscape(string):
+def path_escape(string):
     """Escape string so it can be use in a file path
 
     @param string(basestr): string to escape
     @return (str, unicode): escaped string, usable in a file path
     """
-    return reSubDict(path_escape_re, path_escape, string)
+    return re_sub_dict(path_escape_re, path_escape, string)
 
 
-def pathUnescape(string):
+def path_unescape(string):
     """Unescape string from value found in file path
 
     @param string(basestr): string found in file path
     @return (str, unicode): unescaped string
     """
-    return reSubDict(path_escape_rev_re, path_escape_rev, string)
+    return re_sub_dict(path_escape_rev_re, path_escape_rev, string)
 
 
-def ansiRemove(string):
+def ansi_remove(string):
     """Remove ANSI escape codes from string
 
     @param string(basestr): string to filter
@@ -80,7 +80,7 @@
     return RE_ANSI_REMOVE.sub("", string)
 
 
-def urlFriendlyText(text):
+def url_friendly_text(text):
     """Convert text to url-friendly one"""
     # we change special chars to ascii one,
     # trick found at https://stackoverflow.com/a/3194567