Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
# if we have a colon in the name of a setting then it
# indicates that it has been encoded.
if ":" in name:
if module_name.split(" ")[0] in I3S_MODULE_NAMES + ["general"]:
self.error("Only py3status modules can use obfuscated")
if type(value).__name__ not in ["str", "unicode"]:
self.error("Only strings can be obfuscated")
(name, scheme) = name.split(":")
if scheme == "base64":
value = PrivateBase64(value, module_name)
elif scheme == "hide":
value = PrivateHide(value, module_name)
else:
self.error("Unknown scheme {} for data".format(scheme))
return name, value
# check we are in a module definition etc
if not self.current_module:
self.notify_user("%s(..) used outside of module or section" % function)
return None
module = self.current_module[-1].split()[0]
if module in CONFIG_FILE_SPECIAL_SECTIONS + I3S_MODULE_NAMES:
self.notify_user(
"%s(..) cannot be used outside of py3status module "
"configuration" % function
)
return None
value = self.value_convert(value, value_type)
module_name = self.current_module[-1]
return PrivateHide(value, module_name)
class PrivateHide(Private):
"""
This does not encode the data in any way but it does keep it from being
shown in the log files, i3bar etc
"""
def _decode(self, key):
if self._encoded is None:
return
self._value = self._encoded
self._decoded = True
if __name__ == "__main__":
# This module can read this
x = PrivateHide("test", "__main__")
print(x)
print(x.upper())
print(x.split("e"))
# This module cannot read this
x = PrivateHide("test", "xxx")
print(x)
print(x.upper())
print(x.split("e"))
def _decode(self, key):
if self._encoded is None:
return
self._value = self._encoded
self._decoded = True
if __name__ == "__main__":
# This module can read this
x = PrivateHide("test", "__main__")
print(x)
print(x.upper())
print(x.split("e"))
# This module cannot read this
x = PrivateHide("test", "xxx")
print(x)
print(x.upper())
print(x.split("e"))