parse a single descriptor (array of strings or dicts) into a dict of function descriptor/validators (objects of CephXXX type) :returns: list of ``argdesc``
(sig: Sequence[Union[str, Dict[str, Any]]])
| 924 | |
| 925 | |
| 926 | def parse_funcsig(sig: Sequence[Union[str, Dict[str, Any]]]) -> List[argdesc]: |
| 927 | """ |
| 928 | parse a single descriptor (array of strings or dicts) into a |
| 929 | dict of function descriptor/validators (objects of CephXXX type) |
| 930 | |
| 931 | :returns: list of ``argdesc`` |
| 932 | """ |
| 933 | newsig = [] |
| 934 | argnum = 0 |
| 935 | for desc in sig: |
| 936 | argnum += 1 |
| 937 | if isinstance(desc, basestring): |
| 938 | t = CephPrefix |
| 939 | desc = {'type': t, 'name': 'prefix', 'prefix': desc} |
| 940 | else: |
| 941 | # not a simple string, must be dict |
| 942 | if 'type' not in desc: |
| 943 | s = 'JSON descriptor {0} has no type'.format(sig) |
| 944 | raise JsonFormat(s) |
| 945 | # look up type string in our globals() dict; if it's an |
| 946 | # object of type `type`, it must be a |
| 947 | # locally-defined class. otherwise, we haven't a clue. |
| 948 | if desc['type'] in globals(): |
| 949 | t = globals()[desc['type']] |
| 950 | if not isinstance(t, type): |
| 951 | s = 'unknown type {0}'.format(desc['type']) |
| 952 | raise JsonFormat(s) |
| 953 | else: |
| 954 | s = 'unknown type {0}'.format(desc['type']) |
| 955 | raise JsonFormat(s) |
| 956 | |
| 957 | kwargs = dict() |
| 958 | for key, val in desc.items(): |
| 959 | if key not in ['type', 'name', 'n', 'req', 'positional']: |
| 960 | kwargs[key] = val |
| 961 | newsig.append(argdesc(t, |
| 962 | name=desc.get('name', None), |
| 963 | n=desc.get('n', 1), |
| 964 | req=desc.get('req', True), |
| 965 | positional=desc.get('positional', True), |
| 966 | **kwargs)) |
| 967 | return newsig |
| 968 | |
| 969 | |
| 970 | def parse_json_funcsigs(s: str, |