mscerts.net
 
Adaptive Technologies
Adobe AIR Apps
Artistic Software
Communications
Database
Desktop Environment
Documentation
Education
Games
Home Automation
Information Management
Internet
Multimedia
Office
Printing
Programming
Religion
Science
Science and Engineering
Security
System
Terminals
Text Editing&Processing
Utilities
 
 
myGengo 1.2.0
corejet.jira 1.0 Alpha 1
jsoncmd 0.0
correct_pycountry 0.12.2
Monsters 1.0
corejet.core 1.0 Alpha 1
Scope::Container::DBI 0.04
DBIx::DataModel 1.27
Word Golf 0.2.1
Plack::Middleware::LogWarn 0.001002
 
 
 

failureaction 1.0 Alpha 1

Decorators for actions executed in case of an exception

failureaction is a package intended to provide decorators which execute custom actions in case of exceptions. Let's see an example:

First we need an object with some methods. These methods we decorate with the PrintOnFailure-decorator. This simple example decorator prints a given message in case of an exception.

 >>> from failureaction import ConflictError
 >>> from failureaction import PrintOnFailure
 >>> class TestOb(object):
 ...
 ... @PrintOnFailure(msg='Some numeric calculation went wrong!')
 ... def divide(self, a, b):
 ... return a/b
 ...
 ... @PrintOnFailure()
 ... def doraise(self):
 ... raise ConflictError


We have two methods. One (divide) does numerical division of two numbers and another raises a custom defined ConflictError. Now let's see the methods in action:

 >>> ob = TestOb()
 >>> ob.divide(4, 2)
 2

 >>> ob.divide(42, 0)
 Some numeric calculation went wrong!

 >>> ob.doraise()
 Traceback (most recent call last):
 ...
 ConflictError


The ActionOnFailure decorator provided by the module is intended to be overriden by a custom class. Like this:

 >>> from failureaction import ActionOnFailure
 >>> class MailOnFailure(ActionOnFailure):
 ...
 ... def __init__(self, subject):
 ... self.subject = subject
 ...
 ... def _doaction(self, context, e):
 ... """ send a mail, if an exception was raised """
 ... print "Subject:", self.subject
 ... print e

 >>> class TestOb2(object):
 ...
 ... @MailOnFailure(subject='An error occured')
 ... def critical(self):
 ... import _not_existent_hopefully_

 >>> ob2 = TestOb2()
 >>> ob2.critical()
 Subject: An error occured
 No module named _not_existent_hopefully_

Requirements:

· Python

  Other
-   python-icecc 0.1
-   gtt-python-client 0.1
-   djextdirect 0.3
-   alacarte 0.6.2
-   PySide 0.4.0
-   fluncrunner 0.0
-   PydapSearch 0.1.1.a
-   htmlentitiesdecode 0.1.1
-   SVN::Class 0.16
-   PerlIO::via::EscStatus 7
-   POEx::Role::SessionInstantiation 1.101040
-   eGenix mxODBC 3.1.0
-   Fixtures 0.1
-   TestManager 1.1.0
-   IO::Pty::HalfDuplex 0.02
-   Geo::Coder::Bing::Bulk 0.02
-   Data::Stream::Bulk 0.07
-   Text::CSV::BulkData 0.06
-   App::USBKeyCopyCon 1.02
-   srep 1.09
 
 
                mscerts.net