'call a function and raise an errno-exception if applicable.'

def checked_call(self, func, *args, **kwargs):

    __tracebackhide__ = True
    try:
        return func(*args, **kwargs)
    except self.Error:
        raise
    except (OSError, EnvironmentError):
        (cls, value, tb) = sys.exc_info()
        if (not hasattr(value, 'errno')):
            raise
        __tracebackhide__ = False
        errno = value.errno
        try:
            if (not isinstance(value, WindowsError)):
                raise NameError
        except NameError:
            cls = self._geterrnoclass(errno)
        else:
            try:
                cls = self._geterrnoclass(_winerrnomap[errno])
            except KeyError:
                raise value
        raise cls(('%s%r' % (func.__name__, args)))
        __tracebackhide__ = True
