RAPP Platform  v0.6.0
RAPP Platform is a collection of ROS nodes and back-end processes that aim to deliver ready-to-use generic services to robots
 All Classes Namespaces Files Functions Variables Macros
rapp_http_json_parser.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # -*- encode: utf-8 -*-
3 
4 #Copyright 2015 RAPP
5 
6 #Licensed under the Apache License, Version 2.0 (the "License");
7 #you may not use this file except in compliance with the License.
8 #You may obtain a copy of the License at
9 
10  #http://www.apache.org/licenses/LICENSE-2.0
11 
12 #Unless required by applicable law or agreed to in writing, software
13 #distributed under the License is distributed on an "AS IS" BASIS,
14 #WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 #See the License for the specific language governing permissions and
16 #limitations under the License.
17 
18 # Authors: Aris Thallas
19 # contact: aris.thallas@{iti.gr, gmail.com}
20 
21 from rapp_html_parser import RappHTMLParser
22 
23 
24 ## @class RappHttpJSONParser
25 # @brief Retrieves key:value pairs from JSON responses
26 class RappHttpJSONParser(object):
27 
28  ## @brief Constructor
29  def __init__(self):
30  self._html_parser = RappHTMLParser()
31 
32  ## @brief Creates key:value pairs from JSON responses
33  #
34  # Accepts a json_key:final_key dictionary and returns a dictionary with
35  # values final_key[i]:value[i] where json_key[i]:final_key[i] and
36  # json_key[i]:value[i]
37  #
38  # @param key_dict [dictionary] The keys dictionary
39  # @param json_data [dictionary] The JSON data dictionary
40  #
41  # @return result [dictionary] The final dictionary
42  def find_values(self, key_dict, json_data):
43  result = {}
44 
45  for key in key_dict:
46  if isinstance(json_data[key], str):
47  self._html_parser.feed(json_data[key])
48  result[key_dict[key]] = self._html_parser.get_data()
49  else:
50  result[key_dict[key]] = json_data[key]
51 
52  return result
def find_values
Creates key:value pairs from JSON responses.
Retrieves key:value pairs from JSON responses.