Пример #1
0
 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])
Пример #2
0
    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

        endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr)

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

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
Пример #3
0
 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])
Пример #4
0
    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

        endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr)

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

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
Пример #5
0
    def get_context_by_ip(self, ipaddr, filter=None, context_args=None):
        """ 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."""

        if not is_valid_ip(ipaddr):
            raise ValueError("Address %s is not a valid IP" % ipaddr)
        if filter and not isinstance(filter, basestring):
            raise ValueError("Query must be a string.")

        kwargs = self._prepare_kwargs(filter=filter, context_args=context_args)

        endpoint = self._endpoint("context_by_ip", ip=ipaddr)
        result = self._request(endpoint, "GET", data=kwargs)[1]
        return json_decode(result)
Пример #6
0
    def search_by_ip(self, ipaddr, radius=None, query=None,
                     category=None, limit=None, start=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.
        """
        if not is_valid_ip(ipaddr):
            raise ValueError("Address %s is not a valid IP" % ipaddr)
        if (radius and not is_numeric(radius)):
            raise ValueError("Radius must be numeric.")
        if (query and not isinstance(query, basestring)):
            raise ValueError("Query must be a string.")
        if (category and not isinstance(category, basestring)):
            raise ValueError("Category must be a string.")
        if (limit and not is_numeric(limit)):
            raise ValueError("Limit parameter must be numeric.")
        if (start and not is_numeric(start)):
            raise ValueError("Start parameter must be numeric.")

        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
        if limit:
            kwargs['limit'] = limit
        if start:
            kwargs['start'] = start

        return self._respond(*self._request(self._endpoint(
                    'search_by_ip', ipaddr=ipaddr), 'GET', data=kwargs))
Пример #7
0
    def search_by_ip(self, ipaddr, radius=None, query=None, category=None, num=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.
        """
        if not is_valid_ip(ipaddr):
            raise ValueError("Address %s is not a valid IP" % ipaddr)
        if (radius and not is_numeric(radius)):
            raise ValueError("Radius must be numeric.")
        if (query and not isinstance(query, basestring)):
            raise ValueError("Query must be a string.")
        if (category and not isinstance(category, basestring)):
            raise ValueError("Category must be a string.")
        if (num and not is_numeric(num)):
            raise ValueError("Num parameter must be numeric.")

        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
        if num:
            kwargs['num'] = num

        endpoint = self._endpoint('search_by_ip', ipaddr=ipaddr)

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

        fc = json_decode(result)
        return [Feature.from_dict(f) for f in fc['features']]
Пример #8
0
 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'))
Пример #9
0
 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'))