source: CONFIG_DEVT/IPSLCM6.5_work_ENSEMBLES/oasis3-mct/pyoasis/src/checktypes.py @ 5863

Last change on this file since 5863 was 5725, checked in by aclsce, 3 years ago

Added new oasis3-MCT version to be used to handle ensembles simulations with XIOS.

File size: 2.2 KB
Line 
1# pyOASIS - A Python wrapper for OASIS
2# Authors: Philippe Gambron, Rupert Ford
3# Copyright (C) 2019 UKRI - STFC
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU Lesser General Public License as
7# published by the Free Software Foundation, either version 3 of the
8# License, or any later version.
9
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU Lesser General Public License for more details.
14
15# A copy of the GNU Lesser General Public License, version 3, is supplied
16# with this program, in the file lgpl-3.0.txt. It is also available at
17# <https://www.gnu.org/licenses/lgpl-3.0.html>.
18
19
20import pyoasis.exception
21
22
23def check_types(types, arguments):
24    """Checks the arguments of a function."""
25    if len(arguments) != len(types):
26        raise pyoasis.PyOasisException("The function requires "
27                                       + str(len(types)) + " arguments.")
28    i = 0
29    for (t, a) in zip(types, arguments):
30        if t == list:
31            if a is not None and not isinstance(a, t):
32                raise pyoasis.PyOasisException("Argument " + str(i)
33                                               + " must be of type "
34                                               + str(t) + ".")
35            try:
36                ty_list = type(a[0])
37            except IndexError:
38                raise pyoasis.PyOasisException("The function requires a list but got "+str(a))
39            for element in a:
40                if (type(element) != int and type(element) != str) or \
41                    type(element) != ty_list:
42                    raise pyoasis.PyOasisException(
43                        "The elements of the list in argument "
44                        + str(i) + " must be all integers or strings.")
45        else:
46            if a is not None and not isinstance(a, t):
47                raise pyoasis.PyOasisException("Argument " + str(i)
48                                               + " must be of type "
49                                               + str(t) + ".")
50
51        i = i + 1
Note: See TracBrowser for help on using the repository browser.