示例#1
0
class W_WindowsError(W_OSError):
    """MS-Windows OS system call failed."""
    def __init__(self, space):
        self.w_winerror = space.w_None
        W_OSError.__init__(self, space)

    def descr_init(self, space, args_w):
        # Set errno to the POSIX errno, and winerror to the Win32
        # error code.
        W_OSError.descr_init(self, space, args_w)
        try:
            errno = space.int_w(self.w_errno)
        except OperationError:
            errno = self._default_errno
        else:
            errno = self._winerror_to_errno.get(errno, self._default_errno)
        self.w_winerror = self.w_errno
        self.w_errno = space.newint(errno)

    def descr_str(self, space):
        if (not space.is_w(self.w_winerror, space.w_None)
                and not space.is_w(self.w_strerror, space.w_None)):
            if not space.is_w(self.w_filename, space.w_None):
                return space.newtext(
                    "[Error %d] %s: %s" %
                    (space.int_w(self.w_winerror), space.text_w(
                        self.w_strerror), space.text_w(self.w_filename)))
            return space.newtext(
                "[Error %d] %s" %
                (space.int_w(self.w_winerror), space.text_w(self.w_strerror)))
        return W_BaseException.descr_str(self, space)

    if hasattr(rwin32, 'build_winerror_to_errno'):
        _winerror_to_errno, _default_errno = rwin32.build_winerror_to_errno()
        # Python 2 doesn't map ERROR_DIRECTORY (267) to ENOTDIR but
        # Python 3 (CPython issue #12802) and build_winerror_to_errno do
        del _winerror_to_errno[267]
    else:
        _winerror_to_errno, _default_errno = {}, 22  # EINVAL
示例#2
0
                (errno, strerror, space.utf8_w(space.repr(self.w_filename))))
        if self.w_errno and self.w_strerror:
            return space.newtext(b"[Errno %s] %s" % (errno, strerror))
        return W_BaseException.descr_str(self, space)

    def descr_get_written(self, space):
        if self.written == -1:
            raise oefmt(space.w_AttributeError, "characters_written")
        return space.newint(self.written)

    def descr_set_written(self, space, w_written):
        self.written = space.int_w(w_written)


if hasattr(rwin32, 'build_winerror_to_errno'):
    WINERROR_TO_ERRNO, DEFAULT_WIN32_ERRNO = rwin32.build_winerror_to_errno()
else:
    WINERROR_TO_ERRNO, DEFAULT_WIN32_ERRNO = {}, 22  # EINVAL

if rwin32.WIN32:
    _winerror_property = dict(winerror=readwrite_attrproperty_w(
        'w_winerror', W_OSError), )
else:
    _winerror_property = dict()

W_OSError.typedef = TypeDef(
    'OSError',
    W_Exception.typedef,
    __doc__=W_OSError.__doc__,
    __new__=interp2app(W_OSError.descr_new),
    __reduce__=interp2app(W_OSError.descr_reduce),