def read_string(self, json_string, description=None, section=None, **kwargs): '''Parse a complete or partial configuration. Parameters ---------- json_string : string Input to parse. description : Description, optional Where to put the parsed configuration. If None a new one is created. section : string, optional Where to put the parsed configuration within the description. Returns ------- Description The input description with parsed configuration added. Section is only specified for "bare" objects that are to be added to a section array. ''' if description is None: description = Description() data = JsonComments.read_string(json_string) description.unpack(data, section) return description
def read_string(self, json_string, description=None, section=None, **kwargs): """Parse a complete or partial configuration. Parameters ---------- json_string : string Input to parse. description : Description, optional Where to put the parsed configuration. If None a new one is created. section : string, optional Where to put the parsed configuration within the description. Returns ------- Description The input description with parsed configuration added. Section is only specified for "bare" objects that are to be added to a section array. """ if description == None: description = Description() data = JsonComments.read_string(json_string) description.unpack(data, section) return description
def testTwoMultiLineComments(two_multi_line_json): parsed_json = JsonComments.read_string(two_multi_line_json) assert ('colors' in parsed_json) assert (len(parsed_json['colors']) == 4) assert ('blue' in parsed_json['colors']) assert ('orange' in parsed_json['colors']) assert ('purple' in parsed_json['colors']) assert ('violet' in parsed_json['colors'])
def testTwoMultiLineComments(self): parsed_json = JsonComments.read_string(JsonCommentsTest.two_multi_line_json) self.assertTrue("colors" in parsed_json) self.assertTrue(len(parsed_json["colors"]) == 4) self.assertTrue("blue" in parsed_json["colors"]) self.assertTrue("orange" in parsed_json["colors"]) self.assertTrue("purple" in parsed_json["colors"]) self.assertTrue("violet" in parsed_json["colors"])
def testTwoMultiLineComments(two_multi_line_json): parsed_json = JsonComments.read_string( two_multi_line_json) assert('colors' in parsed_json) assert(len(parsed_json['colors']) == 4) assert('blue' in parsed_json['colors']) assert('orange' in parsed_json['colors']) assert('purple' in parsed_json['colors']) assert('violet' in parsed_json['colors'])
def from_json_string(self, json_string): '''Read a configuration from a JSON format string. Parameters ---------- json_string : string A JSON-formatted string containing an application configuration. Returns ------- string An application configuration in INI format ''' description = JsonComments.read_string(json_string) return self.to_config_string(description)
def from_json_string(self, json_string): """Read a configuration from a JSON format string. Parameters ---------- json_string : string A JSON-formatted string containing an application configuration. Returns ------- string An application configuration in INI format """ description = JsonComments.read_string(json_string) return self.to_config_string(description)
def testMultiLineComment(multi_line_json): parsed_json = JsonComments.read_string( multi_line_json) assert('color' in parsed_json and parsed_json['color'] == 'blue')
def testBlankLines(blank_line_json): parsed_json = JsonComments.read_string( blank_line_json) assert('color' in parsed_json and parsed_json['color'] == 'blue')
def testSingleLineComment(commented_json): parsed_json = JsonComments.read_string( commented_json) assert('color' in parsed_json and parsed_json['color'] == 'blue')
def testBlankLines(blank_line_json): parsed_json = JsonComments.read_string(blank_line_json) assert ('color' in parsed_json and parsed_json['color'] == 'blue')
def testSingleLineComment(commented_json): parsed_json = JsonComments.read_string(commented_json) assert ('color' in parsed_json and parsed_json['color'] == 'blue')
def testMultiLineComment(multi_line_json): parsed_json = JsonComments.read_string(multi_line_json) assert ('color' in parsed_json and parsed_json['color'] == 'blue')
def testMultiLineComment(self): parsed_json = JsonComments.read_string(JsonCommentsTest.multi_line_json) self.assertTrue("color" in parsed_json and parsed_json["color"] == "blue")
def testBlankLines(self): parsed_json = JsonComments.read_string(JsonCommentsTest.blank_line_json) self.assertTrue("color" in parsed_json and parsed_json["color"] == "blue")
def testSingleLineComment(self): parsed_json = JsonComments.read_string(JsonCommentsTest.commented_json) self.assertTrue("color" in parsed_json and parsed_json["color"] == "blue")