Coverage for python/lsst/daf/persistence/utils.py : 82%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python
# # LSST Data Management System # Copyright 2016 LSST Corporation. # # This product includes software developed by the # LSST Project (http://www.lsst.org/). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the LSST License Statement and # the GNU General Public License along with this program. If not, # see <http://www.lsstcorp.org/LegalNotices/>. #
except ImportError: from collections import Sequence, Set, Mapping
# -*- python -*-
"""Takes any object and puts that whole object in a list: - strings will be made into a single element in the list - tuples will be converted to list - lists will remain as lists - None will be made into an empty list """ else:
"""Takes any object. Returns it if it is iterable. If it is not iterable it puts the object in a list and returns the list. None will return an empty list. If a new list is always required use listify(). Strings will be placed in a list with a single element. """ else: x = [x]
"""Takes an object, if it is a sequence return it, else put it in a tuple. Strings are not sequences. If x is a dict, returns a sorted tuple of keys.""" else:
"""Take an object x and return it in a set.
If x is a container, will create a set from the contents of the container. If x is an object, will create a set with a single item in it. If x is a string, will treat the string as a single object (i.e. not as a list of chars)"""
# Here we have to explicity for strings because the set initializer will use each character in a string as # a separate element. We cannot use the braces initialization because x might be a list, and we do not # want the list to be an item; we want each item in the list to be represented by an item in the set. # Then, we have to fall back to braces init because if the item is NOT a list then the set initializer # won't take it. else: except TypeError: x = set([x])
"""Import a python object given an importable string""" raise TypeError("Unhandled type of pythonType, val:%s" % pythonType) # import this pythonType dynamically # pythonType is sometimes unicode with Python 2 and pybind11; this breaks the interpreter except ImportError: pass # maybe python type is a member function, in the form: path.to.object.Class.funcname pythonTypeTokenList = pythonType.split('.') importClassString = '.'.join(pythonTypeTokenList[0:-1]) importedClass = doImport(importClassString) pythonType = getattr(importedClass, pythonTypeTokenList[-1]) return pythonType |