'Returns a generator of every (start, stop) IP ranges for a country
given its ISO-3166-1 "alpha-2" code or its name.'

def ipranges_bycountry(self, code):

    if (len(code) != 2):
        return self.db.execute(select([Location_Range.start, Location_Range.stop]).select_from(join(join(Location, Location_Range), Country)).where((Country.name == code)))
    return self.db.execute(select([Location_Range.start, Location_Range.stop]).select_from(join(Location, Location_Range)).where((Location.country_code == code)))
