loader

sans.dataloader.loader

File handler to support different file extensions. Uses reflectometry’s registry utility.

The default readers are found in the ‘readers’ sub-module and registered by default at initialization time.

To add a new default reader, one must register it in the register_readers method found in readers/__init__.py.

A utility method (find_plugins) is available to inspect a directory (for instance, a user plug-in directory) and look for new readers/writers.

class sans.dataloader.loader.Loader

Bases: object

Utility class to use the Registry as a singleton.

_Loader__registry = <sans.dataloader.loader.Registry object at 0x023A7870>
__class__

alias of type

__delattr__

x.__delattr__(‘name’) <==> del x.name

__dict__ = <dictproxy object at 0x01D4DD30>
__getattribute__

x.__getattribute__(‘name’) <==> x.name

__hash__

x.__hash__() <==> hash(x)

__init__

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

__module__ = 'sans.dataloader.loader'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__str__

x.__str__() <==> str(x)

__weakref__

list of weak references to the object (if defined)

_get_registry_creation_time()

Internal method used to test the uniqueness of the registry object

associate_file_reader()

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type()

Look into a module to find whether it contains a Reader class. If so, append it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
find_plugins()

Find plugins in a given directory

Parameters:dir – directory to look into to find new readers/writers
get_wildcards()
load()

Load a file

Parameters:
  • file – file name (path)
  • format – specified format to use (optional)
Returns:

DataInfo object

save()

Save a DataInfo object to file :param file: file name (path) :param data: DataInfo object :param format: format to write the data in

class sans.dataloader.loader.Registry

Bases: data_util.registry.ExtensionRegistry

Registry class for file format extensions. Readers and writers are supported.

__class__

alias of type

__contains__()
__delattr__

x.__delattr__(‘name’) <==> del x.name

__dict__ = <dictproxy object at 0x01D30550>
__getattribute__

x.__getattribute__(‘name’) <==> x.name

__getitem__()
__hash__

x.__hash__() <==> hash(x)

__init__()
__module__ = 'sans.dataloader.loader'
static __new__(S, ...) → a new object with type S, a subtype of T
__reduce__()

helper for pickle

__reduce_ex__()

helper for pickle

__repr__

x.__repr__() <==> repr(x)

__setattr__

x.__setattr__(‘name’, value) <==> x.name = value

__setitem__()
__str__

x.__str__() <==> str(x)

__weakref__

list of weak references to the object (if defined)

_identify_plugin()

Look into a module to find whether it contains a Reader class. If so, add it to readers and (potentially) to the list of writers. :param module: module object

associate_file_reader()

Append a reader object to readers

Parameters:
  • ext – file extension [string]
  • module – reader object
associate_file_type()

Look into a module to find whether it contains a Reader class. If so, APPEND it to readers and (potentially) to the list of writers for the given extension

Parameters:
  • ext – file extension [string]
  • module – module object
extensions()

Return a sorted list of registered extensions.

find_plugins()

Find readers in a given directory. This method can be used to inspect user plug-in directories to find new readers/writers.

Parameters:dir – directory to search into
Returns:number of readers found
formats()

Return a sorted list of the registered formats.

load()

Call the loader for the file type of path.

Parameters:
  • path – file path
  • format – explicit extension, to force the use of a particular reader

Defaults to the ascii (multi-column) reader if no reader was registered for the file’s extension.

lookup()

Return the loader associated with the file type of path.

Raises ValueError if file type is not known.

lookup_writers()
Returns:the loader associated with the file type of path.
Raises ValueError:
 if file type is not known.
save()

Call the writer for the file type of path.

Raises ValueError if no writer is available. Raises KeyError if format is not available.

May raise a writer-defined exception if writer fails.

Table Of Contents

Previous topic

data_info

Next topic

manipulations

This Page