Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install ook

How to install ook

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install ook
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
Windows (64-bit)
Mac OS X (10.5+)
1.0.0a2Never BuiltWhy not?
0.12.08a2 Failed View build log
Linux (32-bit)
0.12.08a2
1.0.0a2Never BuiltWhy not?
0.12.08a2 Available View build log
1.0.0a2Never BuiltWhy not?
0.12.08a2 Failed View build log
Linux (64-bit)
0.12.08a2
1.0.0a2 Failed View build log
0.12.08a2 Available View build log
1.0.0a2Never BuiltWhy not?
0.12.08a2 Failed View build log
1.0.0a2 Available View build log
0.12.08a2 Available View build log
 
Author
License
GPLv3
Dependencies
Imports
Lastest release
version 1.0.0a2 on Sep 20th, 2013

ook is a simple library to assist with monkeypatching Python methods and functions on a per-Python-version basis. It provides one decorator, patch, which conditionally patches callables depending on which version of Python is running.

Example

Adding the compress() function to Python 2.6's itertools module:

import itertools
from ook import patch

# http://docs.python.org/2.7/library/itertools.html#itertools.compress

@patch(itertools, 2.6)
def compress(data, selectors):
    # compress('ABCDEF', [1,0,1,0,1,1]) --> A C E F
    return (d for d, s in itertools.izip(data, selectors) if s)

Usage

patch accepts an arbitrary number of version arguments, in a variety of formats:

@patch(some.module.or.class, 2.7, "2.6.8", (3, 2, 5), 3)
def method_or_function(signature):
    """Do something."""
    pass

... as well as min and max keyword arguments:

@patch(some.module.or.class, min="2.6.5", max=2.7)
def method_or_function(signature):
    """Do something."""
    pass

... which can be combined:

@patch(some.module.or.class, "3.2.5", max=3.2)
def method_or_function(signature):
    """Do something."""
    pass

Note: If you specify both keyword and non-keyword version arguments, the patch will only take effect if both the explicitly specified versions and the implied version ranges are satisfied.

With no arguments other than the module or class to be patched, patch applies the patch regardless of Python version:

@patch(some.module.or.class)
def method_or_function(signature):
    """Do something, no matter what."""
    pass

Installation

This should do the trick:

pip install ook

Subscribe to package updates

Last updated Sep 20th, 2013

Download Stats

Last month:1

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.