diffpy.srfit.util package
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
keyargument for thesortedorlist.sortfunction.
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.
- Parameters:
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.observable module
- class diffpy.srfit.util.observable.Observable(**kwds)[source]
Bases:
objectProvide 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:
objectTagManager 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.
- Parameters:
obj – Any hashable object to be untagged.
*tags – Tags to apply to obj.
Raises TypeError if obj is not hashable.
diffpy.srfit.util.argbinders module
Functions for binding arguments of callable objects.
diffpy.srfit.util.nameutils module
Name utilities.
diffpy.srfit.util.weakrefcallable module
Picklable storage of callable objects using weak references.
- class diffpy.srfit.util.weakrefcallable.WeakBoundMethod(f, fallback=None)[source]
Bases:
objectCallable wrapper to a bound method stored as a weak reference.
Support storage of bound methods without keeping the associated objects alive forever. Provide facility for a fallback function to be used when method-related object is deleted.
- function
the unbound function extracted from the wrapped bound method.
- Type:
MethodType
- fallback
plain function to be called when object holding the bound method gets deallocated. The fallback function is called with this object as the first argument followed by any positional and keyword arguments passed for the bound method. The fallback function can be used to deregister this wrapper.
- Type:
FunctionType, optional
- _wref
weak reference to the object the wrapped method is bound to.
- Type:
weakref
- _class
the type of the object to which the method is bound. This is only used for pickling.
- Type:
- fallback
- function
- diffpy.srfit.util.weakrefcallable.weak_ref(f, fallback=None)[source]
Create weak-reference wrapper to a bound method.
- Parameters:
f (callable) – object-bound method or a plain function.
fallback (FunctionType, optional) – plain function to be called when object holding
fgets deallocated. The fallback function is called with the wrapper object as the first argument followed by positional and keyword arguments passed for the bound method. The fallback function can be used to deregister the wrapper.
- Returns:
when f is a bound method. If f is a plain function or already of WeakBoundMethod type, return f and ignore the fallback argument.
- Return type: