blob: 9804e0b5127cfc84a539989ba06dbc7ae92e9fbf [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#
Brad Bishopc342db32019-05-15 21:57:59 -04006# SPDX-License-Identifier: LGPL-2.1-or-later OR BSD-3-Clause-Clear
7#
Patrick Williamsc0f7c042017-02-23 20:41:17 -06008# This library is free software; you can redistribute it and/or
9# modify it under the terms of the GNU Lesser General Public
10# License as published by the Free Software Foundation; either
11# version 2.1 of the License, or (at your option) any later version.
12#
13# This library is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16# Lesser General Public License for more details.
17#
18# You should have received a copy of the GNU Lesser General Public
19# License along with this library; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21
22"""Compatibility methods and classes for the progressbar module."""
23
24
25# Python 3.x (and backports) use a modified iterator syntax
26# This will allow 2.x to behave with 3.x iterators
27try:
28 next
29except NameError:
30 def next(iter):
31 try:
32 # Try new style iterators
33 return iter.__next__()
34 except AttributeError:
35 # Fallback in case of a "native" iterator
36 return iter.next()
37
38
39# Python < 2.5 does not have "any"
40try:
41 any
42except NameError:
43 def any(iterator):
44 for item in iterator:
45 if item: return True
46 return False