eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/translations.py

changeset 7612
ca1ce1e0fcff
child 7613
382f89c11e27
diff -r d546c4e72f52 -r ca1ce1e0fcff eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/translations.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric6/Plugins/CheckerPlugins/CodeStyleChecker/Security/translations.py	Mon Jun 08 08:17:14 2020 +0200
@@ -0,0 +1,57 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+
+"""
+Module implementing message translations for the code style plugin messages.
+"""
+
+
+from PyQt5.QtCore import QCoreApplication
+
+
+__all__ = ["getTranslatedMessage"]
+
+_messages = {
+    "S301": QCoreApplication.translate(
+        "Security",
+        "Pickle and modules that wrap it can be unsafe when used to "
+        "deserialize untrusted data, possible security issue."),
+    "S302": QCoreApplication.translate(
+        "Security",
+        "Deserialization with the marshal module is possibly dangerous."),
+    "S303": QCoreApplication.translate(
+        "Security",
+        "Use of insecure MD2, MD4, MD5, or SHA1 hash function."),
+}
+
+
+_messages_sample_args = {
+}
+
+
+def getTranslatedMessage(messageCode, messageArgs):
+    """
+    Module function to get a translated and formatted message for a
+    given message ID.
+    
+    @param messageCode the message code
+    @type str
+    @param messageArgs list of arguments or a single integer value to format
+        the message
+    @type list or int
+    @return translated and formatted message
+    @rtype str
+    """
+    if messageCode in _messages:
+        if isinstance(messageArgs, int):
+            # Retranslate with correct plural form
+            return _messages[messageCode](messageArgs)
+        else:
+            return _messages[messageCode].format(*messageArgs)
+    else:
+        return QCoreApplication.translate(
+            "CodeStyleFixer", " no message defined for code '{0}'"
+        ).format(messageCode)

eric ide

mercurial