text
stringlengths
0
828
# right now jprops relies on a byte stream. So we convert back our nicely decoded Text stream to a unicode
# byte stream ! (urgh)
class Unicoder:
def __init__(self, file_object):
self.f = file_object
def __iter__(self):
return self
def __next__(self):
line = self.f.__next__()
return line.encode(encoding='utf-8')
res = jprops.load_properties(Unicoder(file_object))
# first automatic conversion of strings > numbers
res = {key: try_parse_num_and_booleans(val) for key, val in res.items()}
# further convert if required
return ConversionFinder.convert_collection_values_according_to_pep(res, desired_type, conversion_finder, logger,
**kwargs)"
771,"def get_default_jprops_parsers(parser_finder: ParserFinder, conversion_finder: ConversionFinder) -> List[AnyParser]:
""""""
Utility method to return the default parsers able to parse a dictionary from a properties file.
:return:
""""""
return [SingleFileParserFunction(parser_function=read_dict_from_properties,
streaming_mode=True, custom_name='read_dict_from_properties',
supported_exts={'.properties', '.txt'},
supported_types={dict},
function_args={'conversion_finder': conversion_finder}),
# SingleFileParserFunction(parser_function=read_list_from_properties,
# streaming_mode=True,
# supported_exts={'.properties', '.txt'},
# supported_types={list}),
]"
772,"def hook(event=None, dependencies=None):
""""""Hooking decorator. Just `@hook(event, dependencies)` on your function
Kwargs:
event (str): String or Iterable with events to hook
dependencies (str): String or Iterable with modules whose hooks have
to be called before this one for **this** event
Wraps :func:`EventList.hook`
""""""
def wrapper(func):
""""""I'm a simple wrapper that manages event hooking""""""
func.__deps__ = dependencies
EVENTS.hook(func, event, dependencies)
return func
return wrapper"
773,"def load(path):
""""""Helper function that tries to load a filepath (or python module notation)
as a python module and on failure `exec` it.
Args:
path (str): Path or module to load
The function tries to import `example.module` when either `example.module`,
`example/module` or `example/module.py` is given.
""""""
importpath = path.replace(""/"", ""."").replace(""\\"", ""."")
if importpath[-3:] == "".py"":
importpath = importpath[:-3]
try:
importlib.import_module(importpath)
except (ModuleNotFoundError, TypeError):
exec(open(path).read())"
774,"def add_image(self, image_path, annotations):
""""""Adds an image and its bounding boxes to the current list of files
The bounding boxes are automatically estimated based on the given annotations.
**Parameters:**
``image_path`` : str
The file name of the image, including its full path
``annotations`` : [dict]
A list of annotations, i.e., where each annotation can be anything that :py:func:`bounding_box_from_annotation` can handle; this list can be empty, in case the image does not contain any faces
""""""
self.image_paths.append(image_path)
self.bounding_boxes.append([bounding_box_from_annotation(**a) for a in annotations])"
775,"def add_from_db(self, database, files):
""""""Adds images and bounding boxes for the given files of a database that follows the :py:ref:`bob.bio.base.database.BioDatabase <bob.bio.base>` interface.
**Parameters:**
``database`` : a derivative of :py:class:`bob.bio.base.database.BioDatabase`
The database interface, which provides file names and annotations for the given ``files``
``files`` : :py:class:`bob.bio.base.database.BioFile` or compatible
The files (as returned by :py:meth:`bob.bio.base.database.BioDatabase.objects`) which should be added to the training list
""""""
for f in files:
annotation = database.annotations(f)