diffpy.srfit.util package


diffpy.srfit.util.inpututils module

Input utilities.


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.

inpt – 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.


Check to see if a python string is a valid identifier.

From http://code.activestate.com/recipes/413487/


Validate that a name is a valid identifier.

Raises ValueError if the name is invalid.

diffpy.srfit.util.observable module

class diffpy.srfit.util.observable.Observable(**kwds)

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.

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

Add callable to the set of observers


True if callable is present in the set of observers.


Notify all observers


Remove callable from the set of observers

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

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.


Get all tags managed by the TagManager.

hasTags(obj, *tags)

Determine if an object has all passed tags.

Returns bool


Get all objects that have all of the passed tags.

Returns set

tag(obj, *tags)

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.


Get all tags on an object.

Returns list


Get all objects that have any of the passed tags.

Returns set

untag(obj, *tags)

Remove tags from an object.

obj – Any hashable object to be untagged. *tags – Tags to remove from obj. If this is empty, then all

tags will be removed from obj.

Raises KeyError if a passed tag does not apply to obj and self.silent is False


Check that tags are all extant.

Raises KeyError if a passed tag does not exist. This ignores self.silent.

Module contents

Utilities and constants used throughout SrFit.


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 the sorted or list.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