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

Mon, 08 Jun 2020 08:17:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Mon, 08 Jun 2020 08:17:14 +0200
changeset 7612
ca1ce1e0fcff
child 7613
382f89c11e27
permissions
-rw-r--r--

Code Style Checker: started to implement checker for security related issues.

# -*- 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