def query(self, host, qtype): try: qtype = query_type_map[qtype] except KeyError: raise error.DNSError('invalid query type: {}'.format(qtype)) fut = Future() def cb(result, errorno): if errorno is not None: fut.set_exception(error.DNSError(errorno, pycares.errno.strerror(errorno))) else: fut.set_result(result) self._channel.query(host, qtype, cb) return fut.get()
def spawn(self, func, *args, **kwargs): fut = Future() work = _Work(func, *args, **kwargs) def after(error): if error is not None: assert error == pyuv.errno.UV_ECANCELLED return if work.exc is not None: fut.set_exception(work.exc) else: fut.set_result(work.result) fut.set_running_or_notify_cancel() self.loop._loop.queue_work(work, after) return fut