diffpy.srfit.util package

Submodules

diffpy.srfit.util.inpututils module

Input utilities.

diffpy.srfit.util.inpututils.inputToString(inpt)

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.

diffpy.srfit.util.nameutils.isIdentifier(s)

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

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

diffpy.srfit.util.nameutils.validateName(name)

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.

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
addObserver(callable)

Add callable to the set of observers

hasObserver(callable)

True if callable is present in the set of observers.

notify(other=())

Notify all observers

removeObserver(callable)

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.

alltags()

Get all tags managed by the TagManager.

hasTags(obj, *tags)

Determine if an object has all passed tags.

Returns bool

intersection(*tags)

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.

tags(obj)

Get all tags on an object.

Returns list

union(*tags)

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

verifyTags(*tags)

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.

diffpy.srfit.util.sortKeyForNumericString(s)

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