From 71e632764963e538f06fff9e830e95cf5d0fc1dc Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Wed, 1 Aug 2012 14:10:29 +0900 Subject: Add helper methods for initialisation from json data Added helper methods to initialise model member variables. Now the models' constructors will not throw exception if a value is missing, but instead just initialise the variable to None. Change-Id: I7473ec9bb471f95ea0142067af4750c7e26a0339 --- pygerrit/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'pygerrit/__init__.py') diff --git a/pygerrit/__init__.py b/pygerrit/__init__.py index cb77bdc..100380b 100644 --- a/pygerrit/__init__.py +++ b/pygerrit/__init__.py @@ -1,7 +1,13 @@ """ Module to interface with Gerrit. """ -from pygerrit.error import * -from pygerrit.events import * -from pygerrit.models import * -from pygerrit.stream import * +def from_json(json_data, key): + """ Helper method to extract values from JSON data. + + Return the value of `key` from `json_data`, or None if `json_data` + does not contain `key`. + + """ + if key in json_data: + return json_data[key] + return None -- cgit v1.2.1