-def read_search_path(conf: configparser.SectionProxy) -> SearchPath:
- mapping: Mapping[str, Type[SearchPath]] = {
- 'alias': AliasSearchPath,
- 'channel': ChannelSearchPath,
- 'git': GitSearchPath,
+K = TypeVar('K')
+V = TypeVar('V')
+
+
+def partition_dict(pred: Callable[[K, V], bool],
+ d: Dict[K, V]) -> Tuple[Dict[K, V], Dict[K, V]]:
+ selected: Dict[K, V] = {}
+ remaining: Dict[K, V] = {}
+ for k, v in d.items():
+ if pred(k, v):
+ selected[k] = v
+ else:
+ remaining[k] = v
+ return selected, remaining
+
+
+def filter_dict(d: Dict[K, V], fields: Set[K]
+ ) -> Tuple[Dict[K, V], Dict[K, V]]:
+ return partition_dict(lambda k, v: k in fields, d)
+
+
+def read_config_section(
+ conf: configparser.SectionProxy) -> Tuple[SearchPath, Optional[Pin]]:
+ mapping: Mapping[str, Tuple[Type[SearchPath], Type[Pin]]] = {
+ 'alias': (AliasSearchPath, AliasPin),
+ 'channel': (ChannelSearchPath, ChannelPin),
+ 'git': (GitSearchPath, GitPin),