If you have control over the GoogleV3Place code (i.e. the code you wrote and which is not in the library), I would refactor parse_json to accept the parse_place_fn argument and move parse_place to the top- (if accessibility is a problem, you can always prefix it double underlined):
def parse_place(place): """This returns an object how we want it returned.""" location.formatted_address = place.get('formatted_address') location.latitude = place['geometry']['location']['lat'] location.longitude = place['geometry']['location']['lng'] latitude = place['geometry']['location']['lat'] longitude = place['geometry']['location']['lng'] return (location, (latitude, longitude)) class GoogleV3Place(GoogleV3): """Simply extends the GoogleV3 to bucket the object into a place""" def parse_json(self, page, exactly_one=True, parse_place_fn = parse_place): """Returns location, (latitude, longitude) from json feed.""" if not isinstance(page, basestring): page = util.decode_page(page) self.doc = json.loads(page) places = self.doc.get('results', []) if not places: check_status(self.doc.get('status')) return None elif exactly_one and len(places) != 1: raise ValueError( "Didn't find exactly one placemark! (Found %d)" % len(places)) if exactly_one: return parse_place_fn(places[0]) else: return [parse_place_fn(place) for place in places]
Now, any function that you create that takes up space and returns a tuple of the form (location, (latitude, latitude)) can be passed to parse_json, and if no function is specified, it uses the default parse_place value.
source share