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