Changeset 51f14603 in sasview for src/sans/data_util/registry.py
- Timestamp:
- Apr 3, 2014 11:37:53 AM (11 years ago)
- Branches:
- master, ESS_GUI, ESS_GUI_Docs, ESS_GUI_batch_fitting, ESS_GUI_bumps_abstraction, ESS_GUI_iss1116, ESS_GUI_iss879, ESS_GUI_iss959, ESS_GUI_opencl, ESS_GUI_ordering, ESS_GUI_sync_sascalc, costrafo411, magnetic_scatt, release-4.1.1, release-4.1.2, release-4.2.2, release_4.0.1, ticket-1009, ticket-1094-headless, ticket-1242-2d-resolution, ticket-1243, ticket-1249, ticket885, unittest-saveload
- Children:
- 2f2d9d0
- Parents:
- eea3ffa
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/sans/data_util/registry.py
r4bae1ef r51f14603 15 15 Note that there may be multiple loaders for the same extension. 16 16 17 Example: 17 Example: :: 18 18 19 registry = ExtensionRegistry()19 registry = ExtensionRegistry() 20 20 21 # Add an association by setting an element22 registry['.zip'] = unzip23 24 # Multiple extensions for one loader25 registry['.tgz'] = untar26 registry['.tar.gz'] = untar21 # Add an association by setting an element 22 registry['.zip'] = unzip 23 24 # Multiple extensions for one loader 25 registry['.tgz'] = untar 26 registry['.tar.gz'] = untar 27 27 28 # Generic extensions to use after trying more specific extensions;29 # these will be checked after the more specific extensions fail.30 registry['.gz'] = gunzip28 # Generic extensions to use after trying more specific extensions; 29 # these will be checked after the more specific extensions fail. 30 registry['.gz'] = gunzip 31 31 32 # Multiple loaders for one extension33 registry['.cx'] = cx134 registry['.cx'] = cx235 registry['.cx'] = cx332 # Multiple loaders for one extension 33 registry['.cx'] = cx1 34 registry['.cx'] = cx2 35 registry['.cx'] = cx3 36 36 37 # Show registered extensions38 print registry.extensions()39 40 # Can also register a format name for explicit control from caller41 registry['cx3'] = cx342 print registry.formats()37 # Show registered extensions 38 print registry.extensions() 39 40 # Can also register a format name for explicit control from caller 41 registry['cx3'] = cx3 42 print registry.formats() 43 43 44 # Retrieve loaders for a file name45 registry.lookup('hello.cx') -> [cx3,cx2,cx1]44 # Retrieve loaders for a file name 45 registry.lookup('hello.cx') -> [cx3,cx2,cx1] 46 46 47 # Run loader on a filename 48 registry.load('hello.cx') -> 49 try: 47 # Run loader on a filename 48 registry.load('hello.cx') -> 49 try: 50 return cx3('hello.cx') 51 except: 52 try: 53 return cx2('hello.cx') 54 except: 55 return cx1('hello.cx') 56 57 # Load in a specific format ignoring extension 58 registry.load('hello.cx',format='cx3') -> 50 59 return cx3('hello.cx') 51 except:52 try:53 return cx2('hello.cx')54 except:55 return cx1('hello.cx')56 57 # Load in a specific format ignoring extension58 registry.load('hello.cx',format='cx3') ->59 return cx3('hello.cx')60 60 """ 61 61 def __init__(self, **kw):
Note: See TracChangeset
for help on using the changeset viewer.