29
29
import tempfile
30
30
from abc import ABC
31
31
from abc import abstractmethod
32
- from typing import Any
32
+ from typing import Any , Container
33
33
from typing import Dict
34
34
from typing import Iterator
35
35
from typing import List
@@ -316,8 +316,7 @@ def __init__(self,
316
316
normalize_names : Optional [bool ] = False ,
317
317
client_class = cdsapi .Client ,
318
318
endpoint_url = None ,
319
- cds_api_key = None
320
- ):
319
+ cds_api_key = None ):
321
320
"""Instantiate a CDS data opener.
322
321
323
322
:param normalize_names: if True, all variable names in the returned
@@ -330,7 +329,7 @@ def __init__(self,
330
329
:param endpoint_url: CDS API URL. Will be passed to the CDS API client.
331
330
If omitted, the client will read the value from an environment
332
331
variable or configuration file.
333
- :param cds_api_url : CDS API key. Will be passed to the CDS API client.
332
+ :param cds_api_key : CDS API key. Will be passed to the CDS API client.
334
333
If omitted, the client will read the value from an environment
335
334
variable or configuration file.
336
335
"""
@@ -759,17 +758,23 @@ def get_type_specifiers_for_data(self, data_id: str) -> Tuple[str, ...]:
759
758
return TYPE_SPECIFIER_CUBE ,
760
759
761
760
def get_data_ids (self , type_specifier : Optional [str ] = None ,
762
- include_titles : bool = True ) \
763
- -> Iterator [Tuple [str , Optional [str ]]]:
764
- if not self ._is_type_specifier_satisfied (type_specifier ):
765
- # If the type specifier isn't compatible, return an empty iterator.
766
- return iter (())
767
- return iter (
768
- (data_id ,
769
- self ._handler_registry [data_id ].
770
- get_human_readable_data_id (data_id ) if include_titles else None )
771
- for data_id in self ._handler_registry
772
- )
761
+ include_attrs : Container [str ] = None ) -> \
762
+ Union [Iterator [str ], Iterator [Tuple [str , Dict [str , Any ]]]]:
763
+
764
+ if self ._is_type_specifier_satisfied (type_specifier ):
765
+ # Only if the type specifier isn't compatible
766
+ return_tuples = include_attrs is not None
767
+ # TODO: respect names other than "title" in include_attrs
768
+ include_titles = return_tuples and 'title' in include_attrs
769
+
770
+ for data_id , handler in self ._handler_registry .items ():
771
+ if return_tuples :
772
+ if include_titles :
773
+ yield data_id , {'title' : handler .get_human_readable_data_id (data_id )}
774
+ else :
775
+ yield data_id , {}
776
+ else :
777
+ yield data_id
773
778
774
779
def has_data (self , data_id : str , type_specifier : Optional [str ] = None ) \
775
780
-> bool :
0 commit comments