parted.excpt module
Parted library exceptions control module.
This modules contains the mechanism to control exceptions raised by parted library, and to threat them on a pythonic way.
- author:
Adolfo Gómez, dkmaster at dkmon dot com
- class parted.excpt.PedException(exception: cffi.FFI.CData | None = None)[source]
Bases:
objectThis class represents a parted library exception
Also, provides the mechanism to control exceptions raised by parted library using a callback.
- Parameters:
exception (cffi.FFI.CData) – PedException to wrap
- ExceptionHandler
alias of
Callable[[PedException],PedException.Option]
- class Option(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnumPedException.Option enum
Possible options available to handle exceptions raised by parted library.
They are used as parameter (as a list of possible return values) for the exception handler callback, but also as return value for the exception handler callback.
We can always, even if not passed as parameter, return PedException.Option.UNHANDLED, to notify parted library that we didn’t handle the exception.
- CANCEL = 64
- FIX = 1
- IGNORE = 32
- NO = 4
- OK = 8
- RETRY = 16
- UNHANDLED = 0
- YES = 2
- class Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
IntEnumPedException.Type enum
Possible types of exceptions raised by parted library
- BUG = 5
- ERROR = 3
- FATAL = 4
- FEATURE = 6
- INFORMATION = 1
- WARNING = 2
- static last_message() str[source]
Returns the last exception message
- Returns:
Last exception message
- Return type:
str
- property message: str
Exception message
- property obj: cffi.FFI.CData
wrapped
PedException*object
- static register_handler(handler: Callable[[PedException], Option]) None[source]
Register an exception handler
Registers an exception handler, that will be called when a parted exception is raised. Note that exception handlers MUST return always a value in PedException.Option, or Option.UNHANDLED
- Parameters:
handler (Callable[['PedException'], 'PedException.Option']) – _description_
- static throw(type: Type, option: Option, message: str) None[source]
Throws a
PedException- Parameters:
type (PedException.Type) – Exception type
option (PedException.Option) – Exception option
message (str) – Exception message
Note
This is a wrapper around the
ped_exception_throwfunction. See the parted documentation for more information.
- static with_handler(handler: Callable[[PedException], Option]) Iterator[None][source]
Context manager to set a handler for exceptions, and restore it when exit.
- Parameters:
handler (Callable[[PedException], PedException.Option]) – Exception handler to set
- Yields:
None
Note
This is a context manager, so it can be used with the
withstatement
- parted.excpt.exception_handler(exc: cffi.FFI.CData) int[source]
Overriden default exception handler
Warning
This function is called by parted library, and should not be called directly.
- Parameters:
exc (cffi.FFI.CData) – The exception raised by parted library (PedException)
- Returns:
The option to use to handle the exception
- Return type:
int