# sfepy.base.base module

sfepy.base.base.debug(frame=None, frames_back=1)

  Start debugger on line where it is called, roughly equivalent to:

      import pdb; pdb.set_trace()

  First, this function tries to start an IPython-enabled debugger using the IPython API.

  When this fails, the plain old pdb is used instead.

  With IPython, one can say in what frame the debugger can stop.

class sfepy.base.base.Container(objs=None, **kwargs)
  append(obj)
  as_dict()

    Return stored objects in a dictionary with object names as keys.

  extend(objs)

    Extend the container items by the sequence objs.

  get(ii, default=None, msg_if_none=None)

    Get an item from Container - a wrapper around Container.__getitem__() with defaults and custom error message.

    Parameters:
      ii int or str

        The index or name of the item.

      default any, optional

        The default value returned in case the item ii does not exist.

      msg_if_none str, optional

        If not None, and if default is None and the item ii does not exist, raise ValueError with this message.

  get_names()
  has_key(ii)
  insert(ii, obj)
  iteritems()
  iterkeys()
  itervalues()
  print_names()
  remove_name(name)
  update(objs=None)

    A dict-like update for Struct attributes.

class sfepy.base.base.IndexedStruct(**kwargs)
  setdefault(key, default=None)

class sfepy.base.base.OneTypeList(item_class, seq=None)
  find(name, ret_indx=False)
  get_names()
  print_names()

class sfepy.base.base.Output(prefix, filename=None, quiet=False, combined=False, append=False, **kwargs)

  Factory class providing output (print) functions. All SfePy printing should be accomplished by this class.

  Examples

      >>> from sfepy.base.base import Output
      >>> output = Output('sfepy:')
      >>> output(1, 2, 3, 'hello')
      sfepy: 1 2 3 hello
      >>> output.prefix = 'my_cool_app:'
      >>> output(1, 2, 3, 'hello')
      my_cool_app: 1 2 3 hello

  get_output_function()
  get_output_prefix()
  property prefix
  set_output(filename=None, quiet=False, combined=False, append=False)

    Set the output mode.

    If quiet is True, no messages are printed to screen. If simultaneously filename is not None, the messages are logged into the specified file.

    If quiet is False, more combinations are possible. If filename is None, output is to screen only, otherwise it is to the specified file. Moreover, if combined is True, both the ways are used.

    Parameters:
      filename str or file object

        Print messages into the specified file.

      quiet bool

        Do not print anything to screen.

      combined bool

        Print both on screen and into the specified file.

      append bool

        Append to an existing file instead of overwriting it. Use with filename.

  set_output_prefix(prefix)

class sfepy.base.base.Struct(**kwargs)
  copy(deep=False, name=None)

    Make a (deep) copy of self.

    Parameters:

    deepbool

      Make a deep copy.

    namestr

      Name of the copy, with default self.name + ‘_copy’.

  get(key, default=None, msg_if_none=None)

    A dict-like get() for Struct attributes.

  set_default(key, default=None)

    Behaves like dict.setdefault().

  str_all()
  str_class()

    As __str__(), but for class attributes.

  to_dict()
  update(other, **kwargs)

    A dict-like update for Struct attributes.

sfepy.base.base.as_float_or_complex(val)

  Try to cast val to Python float, and if this fails, to Python complex type.

sfepy.base.base.assert_(condition, msg='assertion failed!')

sfepy.base.base.check_names(names1, names2, msg)

  Check if all names in names1 are in names2, otherwise raise IndexError with the provided message msg.

sfepy.base.base.configure_output(options)

  Configure the standard `output()` function using output_log_name and output_screen attributes of options.

  Parameters:
    options Struct or dict

      The options with output_screen and output_log_name items. Defaults are provided if missing.

sfepy.base.base.debug(frame=None, frames_back=1)

  Start debugger on line where it is called, roughly equivalent to:

      import pdb; pdb.set_trace()

  First, this function tries to start an IPython-enabled debugger using the IPython API.

  When this fails, the plain old pdb is used instead.

  With IPython, one can say in what frame the debugger can stop.

sfepy.base.base.debug_on_error()

  Start debugger at the line where an exception was raised.

sfepy.base.base.dict_extend(d1, d2)

sfepy.base.base.dict_from_keys_init(keys, seq_class=None)

sfepy.base.base.dict_to_array(adict)

  Convert a dictionary of nD arrays of the same shapes with non-negative integer keys to a single (n+1)D array.

sfepy.base.base.dict_to_struct(*args, **kwargs)

  Convert a dict instance to a Struct instance.

sfepy.base.base.edit_dict_strings(str_dict, old, new, recur=False)

  Replace substrings old with new in string values of dictionary str_dict. Both old and new can be lists of the same length - items in old are replaced by items in new with the same index.

  Parameters:
    str_dict dict

      The dictionary with string values or tuples containing strings.

    old str or list of str

      The old substring or list of substrings.

    new str or list of str

      The new substring or list of substrings.

    recur bool

      If True, edit tuple values recursively.

  Returns:
    new_dict dict

      The dictionary with edited strings.

sfepy.base.base.edit_tuple_strings(str_tuple, old, new, recur=False)

  Replace substrings old with new in items of tuple str_tuple. Non-string items are just copied to the new tuple.

  Parameters:
    str_tuple tuple

      The tuple with string values.

    old str

      The old substring.

    new str

      The new substring.

    recur bool

      If True, edit items that are tuples recursively.

  Returns:
    new_tuple tuple

      The tuple with edited strings.

sfepy.base.base.find_subclasses(context, classes, omit_unnamed=False, name_attr='name')

  Find subclasses of the given classes in the given context.

  Examples

      >>> solver_table = find_subclasses(vars().items(),
                                         [LinearSolver, NonlinearSolver,
                                          TimeSteppingSolver, EigenvalueSolver,
                                          OptimizationSolver])

sfepy.base.base.get_arguments(omit=None)

  Get a calling function’s arguments.

  Returns:

  argsdict

    The calling function’s arguments.

sfepy.base.base.get_debug()

  Utility function providing `debug()` function.

sfepy.base.base.get_default(arg, default, msg_if_none=None)

sfepy.base.base.get_default_attr(obj, attr, default, msg_if_none=None)

sfepy.base.base.get_subdict(adict, keys)

  Get a sub-dictionary of adict with given keys.

sfepy.base.base.import_file(filename, package_name=None, can_reload=True)

  Import a file as a module. The module is explicitly reloaded to prevent undesirable interactions.

sfepy.base.base.insert_as_static_method(cls, name, function)

sfepy.base.base.insert_method(instance, function)

sfepy.base.base.insert_static_method(cls, function)

sfepy.base.base.invert_dict(d, is_val_tuple=False, unique=True)

  Invert a dictionary by making its values keys and vice versa.

  Parameters:
    d dict

      The input dictionary.

    is_val_tuple bool

      If True, the d values are tuples and new keys are the tuple items.

    unique bool

      If True, the d values are unique and so the mapping is one to one. If False, the d values (possibly) repeat, so the inverted dictionary will have as items lists of corresponding keys.

  Returns:
    di dict

      The inverted dictionary.

sfepy.base.base.ipython_shell(frame=0)

sfepy.base.base.is_derived_class(cls, parent)

sfepy.base.base.is_integer(var)

sfepy.base.base.is_sequence(var)

sfepy.base.base.is_string(var)

sfepy.base.base.iter_dict_of_lists(dol, return_keys=False)

sfepy.base.base.load_classes(filenames, classes, package_name=None, ignore_errors=False, name_attr='name')

  For each filename in filenames, load all subclasses of classes listed.

sfepy.base.base.ordered_iteritems(adict)

sfepy.base.base.pause(msg=None)

  Prints the line number and waits for a keypress.

  If you press: “q” …………. it will call sys.exit() any other key … it will continue execution of the program

  This is useful for debugging.

sfepy.base.base.print_structs(objs)

  Print Struct instances in a container, works recursively. Debugging utility function.

sfepy.base.base.python_shell(frame=0)

sfepy.base.base.remap_dict(d, map)

  Utility function to remap state dict keys according to var_map.

sfepy.base.base.select_by_names(objs_all, names, replace=None, simple=True)

sfepy.base.base.set_defaults(dict_, defaults)

sfepy.base.base.shell(frame=0)

  Embed an IPython (if available) or regular Python shell in the given frame.

sfepy.base.base.spause(msg=None)

  Waits for a keypress.

  If you press: “q” …………. it will call sys.exit() any other key … it will continue execution of the program

  This is useful for debugging. This function is called from pause().

sfepy.base.base.structify(obj)

  Convert a (nested) dict obj into a (nested) Struct.

sfepy.base.base.try_imports(imports, fail_msg=None)

  Try import statements until one succeeds.

  Parameters:
    imports list

      The list of import statements.

    fail_msg str

      If not None and no statement succeeds, a ValueError is raised with the given message, appended to all failed messages.

  Returns:
    imported dict

      The dictionary of imported modules.

sfepy.base.base.update_dict_recursively(dst, src, tuples_too=False, overwrite_by_none=True)

  Update dst dictionary recursively using items in src dictionary.

  Parameters:
    dst dict

      The destination dictionary.

    src dict

      The source dictionary.

    tuples_too bool

      If True, recurse also into dictionaries that are members of tuples.

    overwrite_by_none bool

      If False, do not overwrite destination dictionary values by None.

  Returns:
    dst dict

      The destination dictionary.

sfepy.base.base.use_method_with_name(instance, method, new_name)