source: trunk/essentials/dev-lang/python/Lib/functools.py@ 3393

Last change on this file since 3393 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 2.1 KB
Line 
1"""functools.py - Tools for working with functions and callable objects
2"""
3# Python module wrapper for _functools C module
4# to allow utilities written in Python to be added
5# to the functools module.
6# Written by Nick Coghlan <ncoghlan at gmail.com>
7# Copyright (C) 2006 Python Software Foundation.
8# See C source code for _functools credits/copyright
9
10from _functools import partial
11
12# update_wrapper() and wraps() are tools to help write
13# wrapper functions that can handle naive introspection
14
15WRAPPER_ASSIGNMENTS = ('__module__', '__name__', '__doc__')
16WRAPPER_UPDATES = ('__dict__',)
17def update_wrapper(wrapper,
18 wrapped,
19 assigned = WRAPPER_ASSIGNMENTS,
20 updated = WRAPPER_UPDATES):
21 """Update a wrapper function to look like the wrapped function
22
23 wrapper is the function to be updated
24 wrapped is the original function
25 assigned is a tuple naming the attributes assigned directly
26 from the wrapped function to the wrapper function (defaults to
27 functools.WRAPPER_ASSIGNMENTS)
28 updated is a tuple naming the attributes off the wrapper that
29 are updated with the corresponding attribute from the wrapped
30 function (defaults to functools.WRAPPER_UPDATES)
31 """
32 for attr in assigned:
33 setattr(wrapper, attr, getattr(wrapped, attr))