Search
Code Directory
 ASP
 ASP.NET
 C/C++
 CFML
 CGI/PERL
 Delphi
 Development
 Flash
 HTML
 Java
 JavaScript
 Pascal
 PHP
 Python
 SQL
 Tools
 Visual Basic & VB.NET
 XML
New Code
phpEnter 5.1.
Udemy Clone script 2.01
VisualNEO Web 19.11.7
VisualNEO for Windows 19.4.29.0
SentiVeillance SDK Trial 7.3
Devart ODBC Driver for PostgreSQL 3.2
SecureBridge 9.2
dotConnect for QuickBooks 1.9
dotConnect for Magento 1.9
dotConnect for Zoho CRM 1.10
dotConnect for FreshBooks 1.10
IP2Location Geolocation Database January.2020
dotConnect for BigCommerce 1.10
HTMLPad 2020 16.0
WeBuilder 2020 16.0
Top Code
Birthday 3.50
EveLottery for Game Script 1.1.3
Top Rated
phpEnter 5.1.
Single Leg MLM 1.2.1
Azizi search engine script PHP 4.1.10
Paste phpSoftPro 1.4.1
Extreme Injector 3.7
Deals and Discounts Website Script 1.0.2
ADO.NET Provider for ExactTarget 1.0
Solid File System OS edition 5.1
Classified Ad Lister 1.0
Aglowsoft SQL Query Tools 8.2
Invoice Manager by PHPJabbers 3.0
ICPennyBid Penny Auction Script 4.0
PHP Review Script 1.0
ATN Resume Finder 2.0
ATN Site Builder 3.0
Decorator and context manager from a single API 
File ID: 64683






Decorator and context manager from a single API 
Download Decorator and context manager from a single API http://code.activestate.com/recipes/576529-total-ordering-class-decorator-for-filling-in-rich/?in=lang-pythonReport Error Link
License: Freeware
Downloads: 2
Submit Rating:
Decorator and context manager from a single API  Description
Description: Create objects that act as both context managers and as decorators, and behave the same in both cases.

Works with Python 2.4 - 2.7 and Python 3. The tests require unittest2 or Python 3.2 to run. (And because the tests use the with statement they won't work with Python 2.4.)

Example:

from contextdecorator import ContextDecorator

class mycontext(ContextDecorator):

def __init__(self, *args):
"""Normal initialiser"""

def before(self):
"""
Called on entering the with block or starting the decorated function.

If used in a with statement whatever this method returns will be the
context manager.
"""

def after(self, *exc):
"""
Called on exit. Arguments and return value of this method have
the same meaning as the __exit__ method of a normal context
manager.
"""

Both before and after methods are optional (but providing neither is somewhat pointless). See the tests for more usage examples.

License: Freeware

Related: contextmanager, context manager, decorator, decorators, With, with statement

O/S:Windows

Downloads: 2



More Similar Code

An Web IDE that enables you to edit, compile, cvs in/out, do file release and produce documentation from a single friendly user web page or out of a Makefile!



This context manager provides a convenient, Pythonic way to temporarily replace the file descriptors of stdout and stderr, redirecting to either os.devnull or files of your choosing. Swapping the C-level file descriptors is required when...



Open and Read content from a text file is a simple ASP article where you will learn the procedures involved in file management. You can learn how to handle files of your website, to open the files and to read the content of the files line by line....



Context manager for a pid (process id) file used to tell whether a daemon process is still running.

On entry, it writes the pid of the current process to the path. On exit, it removes the file.

Designed to work with...



sel_and_del Interactively select and delete points from a line object using mouse input. Left-click selects the point closest to the click and Right-click unselects it. The selected points are highlighted with a black square. The selection process...



PHP libraries which create an XML-based API for storing data in (and retrieving it from) a database. API allows for one or multiple nodes to push/pull data from one or multiple stores, each with one or multiple items allowed.



Visual Network Manager (VNM) software manages your critical network assets across your entire infrastructure, integrating disparate data from multiple vendors, protocols, and legacy systems into a single web portal.



Gigya provides a single API that aggregates authentication and social APIs from Facebook Connect, MySpace ID, Twitter, and OpenID webmail providers including Google, Yahoo, and AOL. The Gigya module for Drupal is fully configurable, requiring...



Use this module when you are running multiple Drupal sites from a single code base (multisite) and you need a different robots.txt file for each one. This module generates the robots.txt file dynamically and gives you the chance to edit it, on a...



Sure, WordPress has a widget for displaying your most recent posts, but what if you want to only display the posts from a single category in a widget, and not everything? This plugin Widget lets you set the title, category, and quantity of posts...

User Review for Decorator and context manager from a single API
- required fields
     

Please enter text on the image