~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: John Arbash Meinel
  • Author(s): Mark Hammond
  • Date: 2008-09-09 17:02:21 UTC
  • mto: This revision was merged to the branch mainline in revision 3697.
  • Revision ID: john@arbash-meinel.com-20080909170221-svim3jw2mrz0amp3
An updated transparent icon for bzr.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007, 2008, 2009, 2011 Canonical Ltd
 
1
# Copyright (C) 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
"""Library API versioning support.
18
18
 
21
21
examples.
22
22
"""
23
23
 
24
 
from __future__ import absolute_import
25
 
 
26
24
import bzrlib
 
25
from bzrlib.lazy_import import lazy_import
 
26
lazy_import(globals(), """
27
27
from bzrlib.errors import IncompatibleAPI
 
28
""")
28
29
 
29
30
 
30
31
def get_current_api_version(object_with_api):
69
70
        version. See get_minimum_api_version and get_current_api_version for
70
71
        details.
71
72
    :param wanted_api: The API version for which support is required.
72
 
    :return: None
 
73
    :return None:
73
74
    :raises IncompatibleAPI: When the wanted_api is not supported by
74
75
        object_with_api.
75
76
 
79
80
    minimum = get_minimum_api_version(object_with_api)
80
81
    if wanted_api < minimum or wanted_api > current:
81
82
        raise IncompatibleAPI(object_with_api, wanted_api, minimum, current)
82
 
 
83
 
 
84
 
def require_any_api(object_with_api, wanted_api_list):
85
 
    """Check if object_with_api supports the api version wanted_api.
86
 
 
87
 
    :param object_with_api: An object which exports an API minimum and current
88
 
        version. See get_minimum_api_version and get_current_api_version for
89
 
        details.
90
 
    :param wanted_api: A list of API versions, any of which being available is
91
 
        sufficent.
92
 
    :return: None
93
 
    :raises IncompatibleAPI: When the wanted_api is not supported by
94
 
        object_with_api.
95
 
 
96
 
    Added in bzrlib 1.9.
97
 
    """
98
 
    for api in wanted_api_list[:-1]:
99
 
        try:
100
 
            return require_api(object_with_api, api)
101
 
        except IncompatibleAPI:
102
 
            pass
103
 
    require_api(object_with_api, wanted_api_list[-1])