diffpy.srfit.util package
Submodules
diffpy.srfit.util.inpututils module
Input utilities.
- diffpy.srfit.util.inpututils.inputToString(input)[source]
Convert input from various modes to a string.
This is useful when you want a method to accept a string, open file object or file name.
- diffpy.srfit.util.inpututils.input
An open file-like object, name of a file or a string containing the input.
Returns the input in a string Raises IOError if the input is supected to be a file name, but the file cannot be found.
diffpy.srfit.util.nameutils module
Name utilities.
diffpy.srfit.util.observable module
- class diffpy.srfit.util.observable.Observable(**kwds)[source]
Bases:
object
Provide notification support for classes that maintain dynamic associations with multiple clients.
Observers, i.e. clients of the observable, register event handlers that will be invoked to notify them whenever something interesting happens to the observable. The nature of what is being observed is defined by Observable descendants and their managers. For example, instances of pyre.calc.Node are observable by other nodes whose value depends on them so that the dependents can be notified about value changes and forced to recompute their own value.
The event handlers are callables that take the observable instance as their single argument.
- interface:
addObserver: registers its callable argument with the list of handlers to invoke removeObserver: remove an event handler from the list of handlers to invoke notify: invoke the registered handlers in the order in which they were registered
diffpy.srfit.util.tagmanager module
TagManager class.
The TagManager class takes hashable objects and assigns tags to them. Objects can then be easily referenced via their assigned tags.
- class diffpy.srfit.util.tagmanager.TagManager[source]
Bases:
object
TagManager class.
Manage tags on hashable objects. Tags are strings that carry metadata.
- silent
Flag indicating whether to silently pass by when a tag cannot be found (bool, True). If this is False, then a KeyError will be thrown when a tag cannot be found.
- _tagdict
A dictionary of tags to sets of tagged objects.
- tag(obj, *tags)[source]
Tag an object.
Tags are stored as strings.
- obj
Any hashable object to be untagged.
- \*tags
Tags to apply to obj.
Raises TypeError if obj is not hashable.
Module contents
Utilities and constants used throughout SrFit.
- diffpy.srfit.util.sortKeyForNumericString(s)[source]
Compute key for sorting strings according to their integer numeric value.
Each string gets split to string and integer segments to create keys for comparison. Signs, decimal points and exponents are ignored. This function is intended as the
key
argument for thesorted
orlist.sort
function.- Parameters:
s (str) – String which may have numeric components, e.g., “a12b”.
- Returns:
Tuple of non-numeric segments intermixed with integer values.
- Return type:
tuple