def search_by_ip(self, ipaddr, radius=None, query=None, category=None):
        """
        Search for places near an IP address, within a radius (in
        kilometers).

        The server uses guesses the latitude and longitude from the
        ipaddr and then does the same thing as search(), using that
        guessed latitude and longitude.
        """
        precondition(is_valid_ip(ipaddr), ipaddr)
        precondition(radius is None or is_numeric(radius), radius)
        precondition(query is None or isinstance(query, basestring), query)
        precondition(category is None or isinstance(category, basestring), category)

        if isinstance(query, unicode):
            query = query.encode('utf-8')
        if isinstance(category, unicode):
            category = category.encode('utf-8')

        kwargs = { }
        if radius:
            kwargs['radius'] = radius
        if query:
            kwargs['q'] = query
        if category:
            kwargs['category'] = category
        quargs = urllib.urlencode(kwargs)
        if quargs:
            quargs = '?'+quargs
        endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr, quargs=quargs)

        result = self._request(endpoint, 'GET')[1]

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
 def get_context_by_ip(self, ipaddr):
     """ The server uses guesses the latitude and longitude from
     the ipaddr and then does the same thing as get_context(),
     using that guessed latitude and longitude."""
     precondition(is_valid_ip(ipaddr), ipaddr)
     endpoint = self._endpoint('context_by_ip', ip=ipaddr)
     return json_decode(self._request(endpoint, "GET")[1])
 def test_is_valid_ip(self):
     self.failUnless(is_valid_ip('192.0.32.10'))
     self.failIf(is_valid_ip('i am not an ip address at all'))