#NEWLINE# @ staticmethod #NEWLINE# def _parse_json( doc , exactly_one = True ) : #NEWLINE# #INDENT# '\n        Parse a location name, latitude, and longitude from an JSON response.\n        ' #NEWLINE# status_code = doc . get ( 'statusCode' , 200 ) #NEWLINE# if ( status_code != 200 ) : #NEWLINE# #INDENT# err = doc . get ( 'errorDetails' , '' ) #NEWLINE# if ( status_code == 401 ) : #NEWLINE# #INDENT# raise GeocoderAuthenticationFailure ( err ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status_code == 403 ) : #NEWLINE# #INDENT# raise GeocoderInsufficientPrivileges ( err ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status_code == 429 ) : #NEWLINE# #INDENT# raise GeocoderQuotaExceeded ( err ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( status_code == 503 ) : #NEWLINE# #INDENT# raise GeocoderUnavailable ( err ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise GeocoderServiceError ( err ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# resources = doc [ 'resourceSets' ] [ 0 ] [ 'resources' ] #NEWLINE# if ( ( resources is None ) or ( not len ( resources ) ) ) : #NEWLINE# #INDENT# return None #NEWLINE# #UNINDENT# def parse_resource( resource ) : #NEWLINE# #INDENT# '\n            Parse each return object.\n            ' #NEWLINE# stripchars = ', \n' #NEWLINE# addr = resource [ 'address' ] #NEWLINE# address = addr . get ( 'addressLine' , '' ) . strip ( stripchars ) #NEWLINE# city = addr . get ( 'locality' , '' ) . strip ( stripchars ) #NEWLINE# state = addr . get ( 'adminDistrict' , '' ) . strip ( stripchars ) #NEWLINE# zipcode = addr . get ( 'postalCode' , '' ) . strip ( stripchars ) #NEWLINE# country = addr . get ( 'countryRegion' , '' ) . strip ( stripchars ) #NEWLINE# city_state = join_filter ( ', ' , [ city , state ] ) #NEWLINE# place = join_filter ( ' ' , [ city_state , zipcode ] ) #NEWLINE# location = join_filter ( ', ' , [ address , place , country ] ) #NEWLINE# latitude = ( resource [ 'point' ] [ 'coordinates' ] [ 0 ] or None ) #NEWLINE# longitude = ( resource [ 'point' ] [ 'coordinates' ] [ 1 ] or None ) #NEWLINE# if ( latitude and longitude ) : #NEWLINE# #INDENT# latitude = float ( latitude ) #NEWLINE# longitude = float ( longitude ) #NEWLINE# #UNINDENT# return Location ( location , ( latitude , longitude ) , resource ) #NEWLINE# #UNINDENT# if exactly_one : #NEWLINE# #INDENT# return parse_resource ( resources [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return [ parse_resource ( resource ) for resource in resources ]