text
stringlengths
0
828
Helper method provided because we actually can't put that in the constructor, it creates a bug in Nose tests
ERROR: type should be string, got " https://github.com/nose-devs/nose/issues/725"
:param parser:
:param desired_type:
:param obj:
:param caught:
:param options:
:return:
""""""
try:
typ = get_pretty_type_str(desired_type)
except:
typ = str(desired_type)
e = ParsingException('Error while parsing ' + str(obj) + ' as a ' + typ + ' with parser \''
+ str(parser) + '\' using options=(' + str(options) + ') : caught \n '
+ str(caught.__class__.__name__) + ' : ' + str(caught))\
.with_traceback(caught.__traceback__) # 'from e' was hiding the inner traceback. This is much better for debug
e.__cause__ = None
# e.__cause__ = caught
# store the exception still, to be able to handle it later
e.caught = caught
return e"
715,"def create_for_wrong_result_type(parser: _BaseParserDeclarationForRegistries, desired_type: Type[T],
obj: PersistedObject, result: T, options: Dict[str, Dict[str, Any]]):
""""""
Helper method provided because we actually can't put that in the constructor, it creates a bug in Nose tests
ERROR: type should be string, got " https://github.com/nose-devs/nose/issues/725"
:param parser:
:param desired_type:
:param obj:
:param result:
:param options:
:return:
""""""
msg = ""Error while parsing {obj} as a {typ} with parser {p} using options=({opts}) - parser returned an object "" \
""of wrong type {tret}: {ret}"".format(obj=obj, typ=get_pretty_type_str(desired_type), p=parser,
opts=options, tret=type(result), ret=result)
return WrongTypeCreatedError(msg)"
716,"def execute(self, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T:
""""""
Called to parse the object as described in this parsing plan, using the provided arguments for the parser.
* Exceptions are caught and wrapped into ParsingException
* If result does not match expected type, an error is thrown
:param logger: the logger to use during parsing (optional: None is supported)
:param options: a dictionary of option sets. Each option set is identified with an id in the dictionary.
:return:
""""""
try:
res = self._execute(logger, options)
except Exception as e:
raise ParsingException.create_for_caught_error(self.parser, self.obj_type, self.obj_on_fs_to_parse, e,
options)
# Check that the returned parsed object has the correct type
if res is not None:
if robust_isinstance(res, self.obj_type):
return res
# wrong type : error
raise WrongTypeCreatedError.create_for_wrong_result_type(self.parser, self.obj_type, self.obj_on_fs_to_parse,
res, options)"
717,"def _execute(self, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T:
""""""
Implementing classes should perform the parsing here, possibly using custom methods of self.parser.
:param logger:
:param options:
:return:
""""""
pass"
718,"def _get_applicable_options(self, options: Dict[str, Dict[str, Any]]):
""""""
Returns the options that are applicable to this particular parser, from the full map of options.
It first uses 'get_id_for_options()' to know the id of this parser, and then simply extracts the contents of
the options corresponding to this id, or returns an empty dict().
:param options: a dictionary parser_id > options
:return:
""""""
return get_options_for_id(options, self.get_id_for_options())"
719,"def create_parsing_plan(self, desired_type: Type[T], filesystem_object: PersistedObject, logger: Logger,
options: Dict[str, Dict[str, Any]]) -> ParsingPlan[T]:
""""""
Creates a parsing plan to parse the given filesystem object into the given desired_type.
Implementing classes may wish to support additional parameters.
:param desired_type: the type of object that should be created as the output of parsing plan execution.
:param filesystem_object: the persisted object that should be parsed
:param logger: an optional logger to log all parsing plan creation and execution information
:param options: a dictionary additional implementation-specific parameters (one dict per parser id).
Implementing classes may use 'self._get_applicable_options()' to get the options that are of interest for this
parser.
:return:
""""""
pass"
720,"def add(self, f_ipaddr, f_macaddr, f_hostname, f_netbios_name, f_engineer, f_asset_group, f_confirmed):