~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/api.py

  • Committer: Robert Collins
  • Date: 2008-10-07 04:51:25 UTC
  • mto: This revision was merged to the branch mainline in revision 3770.
  • Revision ID: robertc@robertcollins.net-20081007045125-4h9com3yii5h6zpx
Add bzrlib.api.require_any_api, fixing bug 279447.

Show diffs side-by-side

added added

removed removed

Lines of Context:
80
80
    minimum = get_minimum_api_version(object_with_api)
81
81
    if wanted_api < minimum or wanted_api > current:
82
82
        raise IncompatibleAPI(object_with_api, wanted_api, minimum, current)
 
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])