def _result(self, item): """Make item into a returnable result. Normalize 'level' and add constant attributes. Also run any postprocessing steps, such as adding a hash. """ # Parse if a string if isinstance(item, str): item = self._parser.parseLine(item) # Normalize the 'level' value if 'level' in item: level = item['level'] if hasattr(level, 'upper'): lvlname = item['level'].upper() item['level'] = Level.getLevel(lvlname) # Add constant key, value pairs: do a copy and # reverse update so new values override old ones. if self._const_nvp: _tmp = self._const_nvp.copy() _tmp.update(item) item = _tmp # Do post-processing. if self._add_hash: item[HASH_FIELD] = hash_event(item) # Done return item
def _preprocess(self, data): """Called before data is handed to subclass in order to allow standardized massaging / filtering of input data. Returns: - Result of module's process() function, or None if the data was rejected by validation. Exceptions: - ValueError """ if self._add_hash: data[HASH_FIELD] = hash_event(data) return data