def _call_geocoder(self, url, raw=False): """ For a generated query URL, get the results. """ try: page = self.urlopen(url) except HTTPError as error: raise GeocoderServiceError(error.getcode(), getattr(error, 'msg', None)) if raw: return page return json.loads(decode_page(page))
def _call_geocoder(self, url, timeout=None, raw=False): """ For a generated query URL, get the results. """ try: page = self.urlopen(url, timeout=timeout or self.timeout) except HTTPError as error: if hasattr(self, '_geocoder_exception_handler'): self._geocoder_exception_handler(error) # pylint: disable=E1101 raise GeocoderServiceError(error.getcode(), getattr(error, 'msg', None)) if raw: return page return json.loads(decode_page(page))
def _parse_response(self, response): """ Returns the parsed result of a PlaceFinder API call. """ try: placefinder = json.loads(response)['bossresponse']['placefinder'] if not len(placefinder): return None results = [(place, (float(place['latitude']), float(place['longitude']))) for place in placefinder.get('results', [])] except (KeyError, ValueError): raise GeocoderError('Error parsing PlaceFinder result') return results
def _parse_response(self, response): """ Returns the parsed result of a PlaceFinder API call. """ try: placefinder = json.loads(response)['bossresponse']['placefinder'] if not len(placefinder): return None results = [ (place, (float(place['latitude']), float(place['longitude']))) for place in placefinder.get('results', []) ] except (KeyError, ValueError): raise GeocoderError('Error parsing PlaceFinder result') return results
def _call_geocoder(self, url, timeout=None, raw=False): """ For a generated query URL, get the results. """ try: page = self.urlopen(url, timeout=timeout or self.timeout) except Exception as error: # pylint: disable=W0703 if hasattr(self, '_geocoder_exception_handler'): self._geocoder_exception_handler(error) # pylint: disable=E1101 if isinstance(error, HTTPError): raise GeocoderServiceError(error.getcode(), error.msg) elif isinstance(error, SSLError): if error.message == 'The read operation timed out': raise GeocoderTimedOut( 'Service timed out while using SSL connection') raise elif isinstance(error, SocketTimeout): raise GeocoderTimedOut('Service timed out') else: raise if raw: return page return json.loads(decode_page(page))
def _call_geocoder(self, url, timeout=None, raw=False): """ For a generated query URL, get the results. """ try: page = self.urlopen(url, timeout=timeout or self.timeout) except Exception as error: # pylint: disable=W0703 if hasattr(self, '_geocoder_exception_handler'): self._geocoder_exception_handler(error) # pylint: disable=E1101 if isinstance(error, HTTPError): raise GeocoderServiceError(error.getcode(), error.msg) elif isinstance(error, SSLError): if error.message == 'The read operation timed out': raise GeocoderTimedOut( 'Service timed out while using SSL connection' ) raise elif isinstance(error, SocketTimeout): raise GeocoderTimedOut('Service timed out') else: raise if raw: return page return json.loads(decode_page(page))