Example #1
0
 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))
Example #2
0
 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))
Example #3
0
 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))
Example #4
0
 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))
Example #5
0
    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
Example #6
0
    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
Example #7
0
 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))
Example #8
0
 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))