def apply_3(self, f, optvals, optname, evaluation): "OptionValue[f_, optvals_, optname_]" if type(optname) is String: name = optname.to_python()[1:-1] else: name = optname.get_name() if not name: name = optname.get_string_value() if name: name = ensure_context(name) if not name: evaluation.message("OptionValue", "sym", optname, 1) return # Look first in the explicit list if optvals: val = get_option(optvals.get_option_values(evaluation), name, evaluation) else: val = None # then, if not found, look at $f$. It could be a symbol, or a list of symbols, rules, and list of rules... if val is None: if f.is_symbol(): val = get_option( evaluation.definitions.get_options(f.get_name()), name, evaluation) else: if f.get_head_name() in ("System`Rule", "System`RuleDelayed"): f = Expression("List", f) if f.get_head_name() == "System`List": for leave in f.get_leaves(): if leave.is_symbol(): val = get_option( evaluation.definitions.get_options( leave.get_name()), name, evaluation, ) if val: break else: values = leave.get_option_values(evaluation) val = get_option(values, name, evaluation) if val: break if val is None and evaluation.options: val = get_option(evaluation.options, name, evaluation) if val is None: evaluation.message("OptionValue", "optnf", optname) return Symbol(name) return val
def _importer_exporter_options(available_options, options, builtin_name: str, evaluation): stream_options = [] custom_options = [] remaining_options = options.copy() if available_options and available_options.has_form('List', None): for name in available_options.leaves: if isinstance(name, String): py_name = name.get_string_value() elif isinstance(name, Symbol): py_name = strip_context(name.get_name()) else: py_name = None if py_name: value = get_option(remaining_options, py_name, evaluation, pop=True) if value is not None: expr = Expression('Rule', String(py_name), value) if py_name == 'CharacterEncoding': stream_options.append(expr) else: custom_options.append(expr) syntax_option = remaining_options.get("System`$OptionSyntax", None) if syntax_option and syntax_option != Symbol("System`Ignore"): # warn about unsupported options. for name, value in remaining_options.items(): print(" es de acá....") evaluation.message( builtin_name, "optx", Expression('Rule', strip_context(name), value), strip_context(builtin_name)) return stream_options, custom_options
def apply_1(self, optname, evaluation): "OptionValue[optname_]" if evaluation.options is None: return if type(optname) is String: name = optname.to_python()[1:-1] else: name = optname.get_name() name = optname.get_name() if not name: name = optname.get_string_value() if name: name = ensure_context(name) if not name: evaluation.message("OptionValue", "sym", optname, 1) return val = get_option(evaluation.options, name, evaluation) if val is None: evaluation.message("OptionValue", "optnf", optname) return Symbol(name) return val