def geocode(self, query):
        """
        Geocode from a query (query being free-text), "around" and "distance"
        parameters can be specified to limit search results to an area.
        Uses version 2 of Cloudmade's Geocoding API.
        """

        if not query:
            return []

        query = query.strip()
        if query.split(' ')[0][0].isdigit():
            query = '+'.join(query.split(' ')[1:])

        params = {
            'api_key': settings.API_KEYS['cloudmade'],
            'query': urllib.quote_plus(query),
            'object_type': 'road',
        }

        if self.search_around and self.search_distance:
            params['around'] = '{0},{1}'.format(self.search_around[1],
                    self.search_around[0])
            params['distance'] = self.search_distance

        try:
            if self.search_around and self.search_distance:
                request_url = self.GEOCODE_URL % params
            else:
                request_url = params % self.GEOCODE_URL_SIMPLE
            response = urllib2.urlopen(request_url)
            logger.debug("Geocode request: %s" % request_url)
            if response.code != 200:
                logger.error("Request to %s returned response code %d"
                        % (request_url, response.code))
                return []
            json = simplejson.loads(response.read().replace('&apos;', "'"),
                    'utf8')
        except urllib2.HTTPError, e:
            logger.error("Cloudmade returned a non-OK response code %d", e.code)
            return []
        except urllib2.URLError, e:
            logger.error("Encountered an error reaching Cloudmade: %s", str(e))
            return []

        if not json:
            return []

        results = []

        features = sorted(json['features'], key=lambda f:
                len(f['properties'].get('name', 'x' * 1000)))

        for i, feature in enumerate(features):
            try:
                # Cloudmade returns a lat-long (and we use long-lats internally)
                bounds_a, bounds_b = [Point(p[1], p[0]) for p in feature['bounds']]
            except OGRException:
                # The point wasn't transformable into the co-ordinate
                # scheme desired - it's probably a long way away.
                continue

            centroid = tuple(feature['centroid']['coordinates'])
            centroid = centroid[1], centroid[0]
            accuracy = bounds_a.distance(bounds_b) / 1.414

            try:
                name = feature['properties']['name']

                if self.get_area:
                    try:
                        if i > 0:
                            raise ValueError
                        params.update({
                            'type': 'area',
                            'lat': centroid[1],
                            'lon': centroid[0],
                        })
                        # TODO this should use the "cache" instead of doing a call
                        data = simplejson.load(urllib2.urlopen(self.REVERSE_GEOCODE_URL % params))
                        logger.debug("Reverse geocode request: %s" % (self.REVERSE_GEOCODE_URL % params))
                        if name != data['features'][0]['properties']['name']:
                            name = '%s, %s' % (name, data['features'][0]['properties']['name'])
                    except Exception:
                        pass

                results.append({
                    'name': name,
                    'location': centroid,
                    'accuracy': accuracy,
                })

            except KeyError:
                results += self.reverse_geocode(*centroid)

        return results
dataset/ETHPy150Open mollyproject/mollyproject/molly/geolocation/providers/cloudmade.py/CloudmadeGeolocationProvider.geocode/swapped operands of `%`