text
stringlengths
0
828
loc=obj.get_pretty_location(blank_parent_part=(not GLOBAL_CONFIG.full_paths_in_logs),
compact_file_ext=True)))
elif background_parsing:
# -- TODO create a thread to perform the parsing in the background
raise ValueError('Background parsing is not yet supported')
else:
# Parse right now
results = OrderedDict()
# parse all children according to their plan
# -- use key-based sorting on children to lead to reproducible results
# (in case of multiple errors, the same error will show up first everytime)
for child_name, child_plan in sorted(parsing_plan_for_children.items()):
results[child_name] = child_plan.execute(logger, options)
# logger.debug('Assembling a ' + get_pretty_type_str(desired_type) + ' from all parsed children of '
# + str(obj))
if issubclass(desired_type, list):
# return a list facade
return KeySortedListFacadeForDict(results)
elif issubclass(desired_type, tuple):
# return a tuple facade
return KeySortedTupleFacadeForDict(results)
elif issubclass(desired_type, set):
# return a set facade
return SetFacadeForDict(results)
elif issubclass(desired_type, dict):
# return the dict directly
return results
else:
raise TypeError('Cannot build the desired collection out of the multifile children: desired type is not '
'supported: ' + get_pretty_type_str(desired_type))"
262,"def dispatch(self, producer=None):
""""""
Dispatch the event, sending a message to the queue using a producer.
:param producer: optional `Producer` to replace the default one.
""""""
log.info('@Event.dispatch `{}` with subject `{}`'
.format(self.name, self.subject))
producer = (producer or Registry.get_producer())
if not producer:
raise MissingProducerError('You have not registered a Producer')
try:
producer.produce(self.topic, self.name, self.subject, self.data)
except:
fallback = Registry.get_fallback()
fallback(self)
raise"
263,"def read_annotation_file(annotation_file, annotation_type):
""""""read_annotation_file(annotation_file, annotation_type) -> annotations
Reads annotations from the given ``annotation_file``.
The way, how annotations are read depends on the given ``annotation_type``.
Depending on the type, one or several annotations might be present in the annotation file.
Currently, these variants are implemented:
- ``'lr-eyes'``: Only the eye positions are stored, in a single row, like: ``le_x le_y re_x re_y``, comment lines starting with ``'#'`` are ignored.
- ``'named'``: Each line of the file contains a name and two floats, like ``reye x y``; empty lines separate between sets of annotations.
- ``'idiap'``: A special 22 point format, where each line contains the index and the locations, like ``1 x y``.
- ``'fddb'``: a special format for the FDDB database; empty lines separate between sets of annotations
Finally, a list of ``annotations`` is returned in the format: ``[{name: (y,x)}]``.
**Parameters:**
``annotation_file`` : str
The file name of the annotation file to read
``annotation_type`` : str (see above)
The style of annotation file, in which the given ``annotation_file`` is
**Returns:**
``annotations`` : [dict]
A list of annotations read from the given file, grouped by annotated objects (faces).
Each annotation is generally specified as the two eye coordinates, i.e., ``{'reye' : (rey, rex), 'leye' : (ley, lex)}``, but other types of annotations might occur as well.
""""""
annotations = [{}]
with open(annotation_file) as f:
if annotation_type == 'idiap':
# This is a special format where we have enumerated annotations, and a 'gender'
for line in f:
positions = line.rstrip().split()
if positions:
if positions[0].isdigit():
# position field
assert len(positions) == 3
id = int(positions[0])
annotations[-1]['key%d'%id] = (float(positions[2]),float(positions[1]))
else:
# another field, we take the first entry as key and the rest as values
annotations[-1][positions[0]] = positions[1:]
elif len(annotations[-1]) > 0:
# empty line; split between annotations
annotations.append({})
# finally, we add the eye center coordinates as the center between the eye corners; the annotations 3 and 8 seem to be the pupils...
for annotation in annotations:
if 'key1' in annotation and 'key5' in annotation: