def input(self, name, default=False, clean=True): """Get a specific input value. Arguments: name {string} -- Key of the input data Keyword Arguments: default {string} -- Default value if input does not exist (default: {False}) clean {bool} -- Whether or not the return value should be cleaned (default: {True}) Returns: string """ if '.' in name and isinstance( self.request_variables.get(name.split('.')[0]), dict): value = DictDot().dot(name, self.request_variables) if value: return value elif '.' in name: name = dot(name, "{1}[{.}]") return clean_request_input(self.request_variables.get(name, default), clean=clean)
def test_dot(): assert dot('hey.dot', compile_to="{1}[{.}]") == "hey[dot]" assert dot('hey.dot.another', compile_to="{1}[{.}]") == "hey[dot][another]" assert dot('hey.dot.another.and.another', compile_to="{1}[{.}]") == "hey[dot][another][and][another]" assert dot('hey.dot.another.and.another', compile_to="/{1}[{.}]") == "/hey[dot][another][and][another]" assert dot('hey.dot', compile_to="{1}/{.}") == "hey/dot" assert dot('hey.dot.another', compile_to="{1}/{.}") == "hey/dot/another" assert dot('hey.dot.another', compile_to="{1}/{.}") == "hey/dot/another" assert dot('hey.dot.another', compile_to="/{1}/{.}") == "/hey/dot/another" with pytest.raises(ValueError): assert dot('hey.dot.another', compile_to="{1}//{.}") == "hey/dot/another"
def test_dot(self): self.assertEqual(dot('hey.dot', compile_to="{1}[{.}]"), "hey[dot]") self.assertEqual(dot('hey.dot.another', compile_to="{1}[{.}]"), "hey[dot][another]") self.assertEqual( dot('hey.dot.another.and.another', compile_to="{1}[{.}]"), "hey[dot][another][and][another]") self.assertEqual( dot('hey.dot.another.and.another', compile_to="/{1}[{.}]"), "/hey[dot][another][and][another]") self.assertEqual(dot('hey.dot', compile_to="{1}/{.}"), "hey/dot") self.assertEqual(dot('hey.dot.another', compile_to="{1}/{.}"), "hey/dot/another") self.assertEqual(dot('hey.dot.another', compile_to="{1}/{.}"), "hey/dot/another") self.assertEqual(dot('hey.dot.another', compile_to="/{1}/{.}"), "/hey/dot/another") with self.assertRaises(ValueError): self.assertEqual(dot('hey.dot.another', compile_to="{1}//{.}"), "hey/dot/another")
def input(self, name, default=False): """Get a specific input value. Arguments: name {string} -- Key of the input data Keyword Arguments: default {string} -- Default value if input does not exist (default: {False}) Returns: string """ if '.' in name: name = dot(name, "{1}[{.}]") return self.request_variables.get(name, default)