admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 1 | #/usr/bin/env python |
| 2 | ''' |
| 3 | Created on 07-Jan-2013 |
| 4 | |
| 5 | @author: Raghav Kashyap(raghavkashyap@paxterrasolutions.com) |
| 6 | |
| 7 | TestON is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | TestON is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | |
| 21 | |
| 22 | ''' |
| 23 | |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 24 | import json |
| 25 | class JsonParser: |
| 26 | ''' |
| 27 | Module that parses the response Json to Dictionary and Vice versa. |
| 28 | ''' |
| 29 | def __init__(self) : |
| 30 | self.default = '' |
| 31 | |
| 32 | def response_parse(self,json_response): |
| 33 | ''' |
| 34 | This will parse the json formatted string and return content as Dictionary |
| 35 | ''' |
| 36 | response_dict = {} |
| 37 | try : |
| 38 | response_dict = json.loads(json_response) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame^] | 39 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 40 | main.log.error("Json Parser is unable to parse the string") |
| 41 | return response_dict |
| 42 | |
| 43 | ''' |
| 44 | |
| 45 | def dict_json(self,response_dict): |
| 46 | |
| 47 | # This will parse the Python Dictionary and return content as Json string. |
| 48 | |
| 49 | json_response = {} |
| 50 | try : |
| 51 | json_response = json.dumps(response_dict) |
Jon Hall | febb1c7 | 2015-03-05 13:30:09 -0800 | [diff] [blame^] | 52 | except Exception: |
admin | bae64d8 | 2013-08-01 10:50:15 -0700 | [diff] [blame] | 53 | main.log.error("Json Parser is unable to parse the string") |
| 54 | return json_response |
| 55 | ''' |