# Overwrite Channel
self.channel = pycares.Channel(sock_state_cb=self._sock_state_cb, **kwargs)
- @tornado.gen.coroutine
- def query(self, name, type=pycares.QUERY_TYPE_A):
+ async def query(self, name, type=pycares.QUERY_TYPE_A):
# Create a new Future
fut = tornado.gen.Future()
self.channel.query(name, type, lambda result, error: fut.set_result((result, error)))
# Wait for the response
- result, error = yield fut
+ result, error = await fut
# Handle any errors
if error:
def get_country_name(self, code):
return countries.get_name(code)
- @tornado.gen.coroutine
- def test_blacklist(self, address):
+ async def test_blacklist(self, address):
address = self.lookup(address)
# Determne blacklist status
- status = yield address.is_blacklisted()
+ status = await address.is_blacklisted()
print("Blacklist status for %s: %s" % (address, status))
return ".".join(octets)
- @tornado.gen.coroutine
- def _resolve_blacklist(self, blacklist):
+ async def _resolve_blacklist(self, blacklist):
return_code = None
# Get resource record name
# Run query
try:
- res = yield self.backend.geoip.resolver.query(rr, type=type)
+ res = await self.backend.geoip.resolver.query(rr, type=type)
except IOError as e:
logging.warning(e)
break
# If the IP address is on a blacklist, we will try to fetch the TXT record
- reason = yield self.backend.geoip.resolver.query(rr, type=pycares.QUERY_TYPE_TXT)
+ reason = await self.backend.geoip.resolver.query(rr, type=pycares.QUERY_TYPE_TXT)
# Log result
logging.debug("%s is blacklisted on %s: %s" % (self, blacklist, reason or "N/A"))
# Blocked, but no reason
return return_code, None
- @tornado.gen.coroutine
- def get_blacklists(self):
- blacklists = yield { bl : self._resolve_blacklist(bl) for bl in BLACKLISTS }
+ async def get_blacklists(self):
+ blacklists = { bl : self._resolve_blacklist(bl) for bl in BLACKLISTS }
return blacklists
- @tornado.gen.coroutine
- def is_blacklisted(self):
+ async def is_blacklisted(self):
logging.debug("Checking if %s is blacklisted..." % self)
# Perform checks
- blacklists = yield { bl : self._resolve_blacklist(bl) for bl in BLOCKLISTS }
+ blacklists = { bl : self._resolve_blacklist(bl) for bl in BLOCKLISTS }
# If we are blacklisted on one list, this one is screwed
for bl in blacklists:
- code, message = blacklists[bl]
+ code, message = await blacklists[bl]
logging.debug("Response from %s is: %s (%s)" % (bl, code, message))