root/masterdriverz/snakeoil/snakeoil/compatibility.py @ ferringb%2540gmail.com-20070429202721-8mqijyr56t6ntz7w

Revision ferringb%2540gmail.com-20070429202721-8mqijyr56t6ntz7w, 0.7 kB (checked in by Brian Harring <ferringb@…>, 21 months ago)

set of changes; move _functoolmodules to _compatibility, pull in py2.5's any/all, slave compatibility to that, tweak test_compatibility a bit so it's slightly saner in terms of not doing repeated/wasteful tests

Line 
1# Copyright: 2006 Brian Harring <ferringb@gmail.com>
2# License: GPL2
3
4"""
5Compatibility module providing native reimplementations of python2.5 functionality.
6
7Uses the native implementation from C{__builtins__} if available.
8"""
9
10def native_any(iterable):
11    for x in iterable:
12        if x:
13            return True
14    return False
15
16def native_all(iterable):
17    for x in iterable:
18        if not x:
19            return False
20    return True
21
22# using variable before assignment
23# pylint: disable-msg=E0601
24
25if "any" in __builtins__:
26    any = any
27    all = all
28else:
29    try:
30        from snakeoil._compatibility import any, all
31    except ImportError:
32        any, all = native_any, native_all
Note: See TracBrowser for help on using the browser.