blob: a39f4a1f4ed0f84d70d7c9843e0096d7c4dfacba [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001# -*- coding: utf-8 -*-
2#
3# progressbar - Text progress bar library for Python.
4# Copyright (c) 2005 Nilton Volpato
5#
6# This library is free software; you can redistribute it and/or
7# modify it under the terms of the GNU Lesser General Public
8# License as published by the Free Software Foundation; either
9# version 2.1 of the License, or (at your option) any later version.
10#
11# This library is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# Lesser General Public License for more details.
15#
16# You should have received a copy of the GNU Lesser General Public
17# License along with this library; if not, write to the Free Software
18# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19
20"""Compatibility methods and classes for the progressbar module."""
21
22
23# Python 3.x (and backports) use a modified iterator syntax
24# This will allow 2.x to behave with 3.x iterators
25try:
26 next
27except NameError:
28 def next(iter):
29 try:
30 # Try new style iterators
31 return iter.__next__()
32 except AttributeError:
33 # Fallback in case of a "native" iterator
34 return iter.next()
35
36
37# Python < 2.5 does not have "any"
38try:
39 any
40except NameError:
41 def any(iterator):
42 for item in iterator:
43 if item: return True
44 return False