Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@command
def _get_attribute(self, attribute):
return getattr(self, attribute)
@command(output_type='JSON')
@parameter(key="message", description="The Message to be Echoed", optional=True, type="String",
default='{"str": "value", "nums": [1, 2, 17], "obj": {"nested": "awesome"}}')
def say_json(self, message=DEFAULT_MESSAGE):
"""Echos with JSON output_type"""
return message
@command(command_type="INFO")
@parameter(key="message", type="String", optional=False, nullable=False)
def echo_message_info(self, message):
if message is None:
raise ValueError("Message cannot be None.")
self.logger.info(message)
return message
@command(form='./resources/say_form.json')
@parameter(key="message", type="String", optional=False, nullable=False)
@parameter(key="loud", type="Boolean")
def echo_message_custom_form_from_file(self, message='Hello world!', loud=False):
"""form='./resources/say_form.json'"""
return message + '!!!!!!!!!' if loud else message
@command(form={"type": "fieldset", "items": [{"key": "parameters.message", "readonly": True}]})
@parameter(key="message", type="String", optional=False, nullable=False)
def echo_message_custom_form_as_dict(self, message="Can't change me! Hahaha!"):
"""form={"type": "fieldset", "items": [{"key": "parameters.message", "readonly": True}]}"""
return message
@command(output_type="JSON")
def echo_message_huge_json(self):
d = {n: True for n in range(2000)}
return json.dumps(d)
@command
def prove_env(self):
"""Prints out the DB_NAME and DB_PASS from the environment, just to prove it works"""
self.logger.info("Proving the Environment Variables are there.")
self.logger.info("DB Name : %s" % os.getenv('DB_NAME'))
self.logger.info("DB Password: %s" % os.getenv('DB_PASS'))
self.logger.info("Told you they were here!")
return json.dumps({'DB_NAME': os.getenv('DB_NAME'), 'DB_PASS': os.getenv('DB_PASS')})
@command(command_type='INFO', output_type="JSON")
def get_choices_renamed(self):
return self.STATIC_CHOICES_RENAMED
@command(template='./resources/minimalist.html')
def echo_minimalist(self, message):
return message
@command
def get_choices_dictionary(self):
return self.STATIC_CHOICES_DICTIONARY