Suppose we have the following code. I want to swap out the inner parse_place
function. How do you do this without replacing the whole method?
class GoogleV3Place(GoogleV3):
"""Simply extends the GoogleV3 to bucket the object into a place"""
def parse_json(self, page, exactly_one=True):
"""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))
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))
if exactly_one:
return parse_place(places[0])
else:
return [parse_place(place) for place in places]