text
stringlengths 0
828
|
|---|
called. This is a synonym for #__call__(). The first time the function is
|
called will return immediately and not block. Therefore, it is important to
|
put the call at the beginning of the timed block, like this:
|
# Example
|
```python
|
clock = Clock(fps=50)
|
while True:
|
clock.sleep()
|
# Processing ...
|
```
|
""""""
|
current = time.time()
|
if self.last < 0:
|
self.last = current
|
return
|
delta = current - self.last
|
if delta < self.seconds:
|
time.sleep(self.seconds - delta)
|
self.last = time.time()"
|
464,"def read_config(desired_type: Type[ConfigParser], file_object: TextIOBase,
|
logger: Logger, *args, **kwargs) -> ConfigParser:
|
""""""
|
Helper method to read a configuration file according to the 'configparser' format, and return it as a dictionary
|
of dictionaries (section > [property > value])
|
:param file_object:
|
:return:
|
""""""
|
# see https://docs.python.org/3/library/configparser.html for details
|
config = ConfigParser()
|
config.read_file(file_object)
|
return config"
|
465,"def get_default_config_parsers() -> List[AnyParser]:
|
""""""
|
Utility method to return the default parsers able to parse a dictionary from a file.
|
:return:
|
""""""
|
return [SingleFileParserFunction(parser_function=read_config,
|
streaming_mode=True,
|
supported_exts={'.cfg', '.ini'},
|
supported_types={ConfigParser}),
|
]"
|
466,"def config_to_dict_of_dict(desired_type: Type[T], config: ConfigParser, logger: Logger,
|
conversion_finder: ConversionFinder, **kwargs) -> DictOfDict:
|
""""""
|
Helper method to read a configuration file according to the 'configparser' format, and return it as a dictionary
|
of dictionaries [section > [property > value]].
|
:param file_object:
|
:return:
|
""""""
|
# return dict(config)
|
# get the base collection type if provided
|
base_typ, discarded = _extract_collection_base_type(desired_type, exception_if_none=False)
|
# if none, at least declare dict
|
base_typ = base_typ or Dict
|
# convert the whole config to a dictionary by flattening all sections. If a key is found twice in two different
|
# sections an error is raised
|
results = dict()
|
for section, props in config.items():
|
# convert all values of the sub-dictionary
|
results[section] = ConversionFinder.convert_collection_values_according_to_pep(props, base_typ,
|
conversion_finder, logger,
|
**kwargs)
|
return results"
|
467,"def merge_all_config_sections_into_a_single_dict(desired_type: Type[T], config: ConfigParser, logger: Logger,
|
conversion_finder: ConversionFinder, **kwargs) -> Dict[str, Any]:
|
""""""
|
Helper method to convert a 'configparser' into a dictionary [property > value].
|
Properties from all sections are collected. If the same key appears in several sections, an
|
error will be thrown
|
:param file_object:
|
:return:
|
""""""
|
# convert the whole config to a dictionary by flattening all sections. If a key is found twice in two different
|
# sections an error is raised
|
results = dict()
|
for section, props in config.items():
|
for key, value in props.items():
|
if key in results.keys():
|
# find all sections where it appears
|
sections_where_it_appears = [s for s, p in config.items() if key in p.keys()]
|
raise MultipleKeyOccurenceInConfigurationError.create(key, sections_where_it_appears)
|
else:
|
results[key] = value
|
return ConversionFinder.convert_collection_values_according_to_pep(results, desired_type, conversion_finder,
|
logger, **kwargs)"
|
468,"def get_default_config_converters(conv_finder: ConversionFinder) -> List[Union[Converter[Any, ConfigParser], Converter[ConfigParser, Any]]]:
|
""""""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.