def strerror(space, errno): """Translate an error code to a message string.""" try: return space.wrap(_strerror(errno)) except ValueError: raise OperationError(space.w_ValueError, space.wrap("strerror() argument out of range"))
def PyErr_SetFromErrnoWithFilenameObject(space, w_type, w_value): """Similar to PyErr_SetFromErrno(), with the additional behavior that if w_value is not NULL, it is passed to the constructor of type as a third parameter. In the case of exceptions such as IOError and OSError, this is used to define the filename attribute of the exception instance. Return value: always NULL.""" # XXX Doesn't actually do anything with PyErr_CheckSignals. errno = rffi.cast(lltype.Signed, rposix._get_errno()) msg, lgt = _strerror(errno) if w_value: w_error = space.call_function(w_type, space.newint(errno), space.newtext(msg, lgt), w_value) else: w_error = space.call_function(w_type, space.newint(errno), space.newtext(msg, lgt)) raise OperationError(w_type, w_error)
def PyErr_SetFromErrnoWithFilenameObject(space, w_type, w_value): """Similar to PyErr_SetFromErrno(), with the additional behavior that if w_value is not NULL, it is passed to the constructor of type as a third parameter. In the case of exceptions such as IOError and OSError, this is used to define the filename attribute of the exception instance. Return value: always NULL.""" # XXX Doesn't actually do anything with PyErr_CheckSignals. errno = rffi.cast(lltype.Signed, rposix._get_errno()) msg = _strerror(errno) if w_value: w_error = space.call_function(w_type, space.wrap(errno), space.wrap(msg), w_value) else: w_error = space.call_function(w_type, space.wrap(errno), space.wrap(msg)) raise OperationError(w_type, w_error)
def _get_error_msg(): errno = rposix.get_saved_errno() return _strerror(errno)
def _errmsg(what): from rpython.rlib import rposix errmsg = _strerror(rposix.get_errno()) return u"%s failed" % what if errmsg is None else errmsg