4.7. foundations.exceptions

exceptions.py

Platform:
Windows, Linux, Mac Os X.
Description:
Defines Foundations package exceptions and others exception handling related objects.

Others:

4.7.1. Module Attributes

foundations.exceptions.LOGGER
foundations.exceptions.EXCEPTIONS_FRAME_SYMBOL

4.7.2. Functions

foundations.exceptions.getInnerMostFrame(trcback)[source]

Returns the inner most frame of given traceback.

Parameters:trcback (Traceback) – Traceback.
Returns:Frame.
Return type:Frame
foundations.exceptions.extractStack(frame, context=10, exceptionsFrameSymbol=u'_exceptions__frame__')[source]

Extracts the stack from given frame while excluded any symbolized frame.

Parameters:
  • frame (Frame) – Frame.
  • context (int) – Context to extract.
  • exceptionsFrameSymbol (unicode) – Stack trace frame tag.
Returns:

Stack.

Return type:

list

foundations.exceptions.extractArguments(frame)[source]

Extracts the arguments from given frame.

Parameters:frame (object) – Frame.
Returns:Arguments.
Return type:tuple
foundations.exceptions.extractLocals(trcback)[source]

Extracts the frames locals of given traceback.

Parameters:trcback (Traceback) – Traceback.
Returns:Frames locals.
Return type:list
foundations.exceptions.extractException(*args)[source]

Extracts the exception from given arguments or from sys.exc_info().

Parameters:*args (*) – Arguments.
Returns:Extracted exception.
Return type:tuple
foundations.exceptions.formatException(cls, instance, trcback, context=1)[source]
Formats given exception.
The code produce a similar output to traceback.format_exception() except that it allows frames to be excluded from the stack if the given stack trace frame tag is found in the frame locals and set True.
Parameters:
  • cls (object) – Exception class.
  • instance (object) – Exception instance.
  • trcback (Traceback) – Traceback.
  • context (int) – Context being included.
Returns:

Formated exception.

Return type:

list

foundations.exceptions.formatReport(cls, instance, trcback, context=1)[source]

Formats a report using given exception.

Parameters:
  • cls (object) – Exception class.
  • instance (object) – Exception instance.
  • trcback (Traceback) – Traceback.
  • context (int) – Context being included.
Returns:

Formated report.

Return type:

tuple

foundations.exceptions.baseExceptionHandler(*args)[source]

Provides the base exception handler.

Parameters:*args (*) – Arguments.
Returns:Definition success.
Return type:bool
foundations.exceptions.installExceptionHandler(handler=None)[source]

Installs the given exceptions handler.

Parameters:handler (object) – Exception handler.
Returns:Definition success.
Return type:bool
foundations.exceptions.uninstallExceptionHandler()[source]

Uninstalls the exceptions handler.

Returns:Definition success.
Return type:bool
foundations.exceptions.handleExceptions(*args)[source]
Handles exceptions.
It’s possible to specify an user defined exception handler, if not, baseExceptionHandler() handler will be used.
The decorator uses given exceptions objects or the default Python Exception class.

Usage:

@handleExceptions(ZeroDivisionError)
def raiseAnException(value):
        '''
        Raises a 'ZeroDivisionError' exception.
        '''

        return value / 0

        :param \*args: Arguments.
        :type \*args: \*
Returns:Object.
Return type:object

4.7.3. Classes

class foundations.exceptions.AbstractError(value)[source]

Bases: exceptions.Exception

Defines the abstract base class for all Foundations package exceptions.

Initializes the class.

Parameters:value (unicode) – Error value or message.
value[source]

Property for self.__value attribute.

Returns:self.__value.
Return type:object
class foundations.exceptions.ExecutionError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines execution exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.BreakIteration(value)[source]

Bases: foundations.exceptions.AbstractError

Breaks nested loop iteration.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractParsingError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for parsing related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.FileStructureParsingError(value)[source]

Bases: foundations.exceptions.AbstractParsingError

Defines exception raised while parsing file structure.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AttributeStructureParsingError(value, line=None)[source]

Bases: foundations.exceptions.AbstractParsingError

Defines exception raised while parsing attribute structure.

Initializes the class.

Parameters:
  • value (unicode) – Error value or message.
  • line (int) – Line number where exception occured.
line[source]

Property for self.__line attribute.

Returns:self.__line.
Return type:int
class foundations.exceptions.AbstractIOError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for io related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.FileReadError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines file read exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.FileWriteError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines file write exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.UrlReadError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines url read exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.UrlWriteError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines file write exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.DirectoryCreationError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines directory creation exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.PathCopyError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines path copy exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.PathRemoveError(value)[source]

Bases: foundations.exceptions.AbstractIOError

Defines path remove exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractOsError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for os related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.PathExistsError(value)[source]

Bases: foundations.exceptions.AbstractOsError

Defines non existing path exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.DirectoryExistsError(value)[source]

Bases: foundations.exceptions.PathExistsError

Defines non existing directory exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.FileExistsError(value)[source]

Bases: foundations.exceptions.PathExistsError

Defines non existing file exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractObjectError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for object related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.ObjectTypeError(value)[source]

Bases: foundations.exceptions.AbstractObjectError

Defines invalid object type exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.ObjectExistsError(value)[source]

Bases: foundations.exceptions.AbstractObjectError

Defines non existing object exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractUserError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for user related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.ProgrammingError(value)[source]

Bases: foundations.exceptions.AbstractUserError

Defines programming exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.UserError(value)[source]

Bases: foundations.exceptions.AbstractUserError

Defines user exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractNodeError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for Node related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.NodeAttributeTypeError(value)[source]

Bases: foundations.exceptions.AbstractNodeError, foundations.exceptions.ObjectTypeError

Defines the abstract base class for Node attributes type related exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.NodeAttributeExistsError(value)[source]

Bases: foundations.exceptions.AbstractNodeError, foundations.exceptions.ObjectExistsError

Defines non existing Node attribute exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractLibraryError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for library module exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.LibraryInstantiationError(value)[source]

Bases: foundations.exceptions.AbstractLibraryError

Defines library module library.Library class instantiation exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.LibraryInitializationError(value)[source]

Bases: foundations.exceptions.AbstractLibraryError

Defines library module library.Library class initialization exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.LibraryExecutionError(value)[source]

Bases: foundations.exceptions.AbstractLibraryError

Defines library module library.Library class execution exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AbstractServerError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines the abstract base class for tcpServer module exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.ServerOperationError(value)[source]

Bases: foundations.exceptions.AbstractServerError

Defines tcpServer module tcpServer.TCPServer class operations exception.

Initializes the class.

Parameters:value (unicode) – Error value or message.
class foundations.exceptions.AnsiEscapeCodeExistsError(value)[source]

Bases: foundations.exceptions.AbstractError

Defines exception used for non existing ANSI escape codes.

Initializes the class.

Parameters:value (unicode) – Error value or message.