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

changeset 7612
ca1ce1e0fcff
child 7613
382f89c11e27
equal deleted inserted replaced
7611:d546c4e72f52 7612:ca1ce1e0fcff
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2020 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6
7 """
8 Module implementing message translations for the code style plugin messages.
9 """
10
11
12 from PyQt5.QtCore import QCoreApplication
13
14
15 __all__ = ["getTranslatedMessage"]
16
17 _messages = {
18 "S301": QCoreApplication.translate(
19 "Security",
20 "Pickle and modules that wrap it can be unsafe when used to "
21 "deserialize untrusted data, possible security issue."),
22 "S302": QCoreApplication.translate(
23 "Security",
24 "Deserialization with the marshal module is possibly dangerous."),
25 "S303": QCoreApplication.translate(
26 "Security",
27 "Use of insecure MD2, MD4, MD5, or SHA1 hash function."),
28 }
29
30
31 _messages_sample_args = {
32 }
33
34
35 def getTranslatedMessage(messageCode, messageArgs):
36 """
37 Module function to get a translated and formatted message for a
38 given message ID.
39
40 @param messageCode the message code
41 @type str
42 @param messageArgs list of arguments or a single integer value to format
43 the message
44 @type list or int
45 @return translated and formatted message
46 @rtype str
47 """
48 if messageCode in _messages:
49 if isinstance(messageArgs, int):
50 # Retranslate with correct plural form
51 return _messages[messageCode](messageArgs)
52 else:
53 return _messages[messageCode].format(*messageArgs)
54 else:
55 return QCoreApplication.translate(
56 "CodeStyleFixer", " no message defined for code '{0}'"
57 ).format(messageCode)

eric ide

mercurial