LSSTApplications  17.0+124,17.0+14,17.0+73,18.0.0+37,18.0.0+80,18.0.0-4-g68ffd23+4,18.1.0-1-g0001055+12,18.1.0-1-g03d53ef+5,18.1.0-1-g1349e88+55,18.1.0-1-g2505f39+44,18.1.0-1-g5315e5e+4,18.1.0-1-g5e4b7ea+14,18.1.0-1-g7e8fceb+4,18.1.0-1-g85f8cd4+48,18.1.0-1-g8ff0b9f+4,18.1.0-1-ga2c679d+1,18.1.0-1-gd55f500+35,18.1.0-10-gb58edde+2,18.1.0-11-g0997b02+4,18.1.0-13-gfe4edf0b+12,18.1.0-14-g259bd21+21,18.1.0-19-gdb69f3f+2,18.1.0-2-g5f9922c+24,18.1.0-2-gd3b74e5+11,18.1.0-2-gfbf3545+32,18.1.0-26-g728bddb4+5,18.1.0-27-g6ff7ca9+2,18.1.0-3-g52aa583+25,18.1.0-3-g8ea57af+9,18.1.0-3-gb69f684+42,18.1.0-3-gfcaddf3+6,18.1.0-32-gd8786685a,18.1.0-4-gf3f9b77+6,18.1.0-5-g1dd662b+2,18.1.0-5-g6dbcb01+41,18.1.0-6-gae77429+3,18.1.0-7-g9d75d83+9,18.1.0-7-gae09a6d+30,18.1.0-9-gc381ef5+4,w.2019.45
LSSTDataManagementBasePackage
Functions
lsst.daf.persistence.utils Namespace Reference

Functions

def listify (x)
 
def iterify (x)
 
def sequencify (x)
 
def setify (x)
 
def doImport (pythonType)
 

Function Documentation

◆ doImport()

def lsst.daf.persistence.utils.doImport (   pythonType)
Import a python object given an importable string

Definition at line 106 of file utils.py.

106 def doImport(pythonType):
107  """Import a python object given an importable string"""
108  try:
109  if not isinstance(pythonType, basestring):
110  raise TypeError("Unhandled type of pythonType, val:%s" % pythonType)
111  # import this pythonType dynamically
112  # pythonType is sometimes unicode with Python 2 and pybind11; this breaks the interpreter
113  pythonTypeTokenList = str(pythonType).split('.')
114  importClassString = pythonTypeTokenList.pop()
115  importClassString = importClassString.strip()
116  importPackage = ".".join(pythonTypeTokenList)
117  importType = __import__(importPackage, globals(), locals(), [importClassString], 0)
118  pythonType = getattr(importType, importClassString)
119  return pythonType
120  except ImportError:
121  pass
122  # maybe python type is a member function, in the form: path.to.object.Class.funcname
123  pythonTypeTokenList = pythonType.split('.')
124  importClassString = '.'.join(pythonTypeTokenList[0:-1])
125  importedClass = doImport(importClassString)
126  pythonType = getattr(importedClass, pythonTypeTokenList[-1])
127  return pythonType
128 
def doImport(pythonType)
Definition: utils.py:106

◆ iterify()

def lsst.daf.persistence.utils.iterify (   x)
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.

Definition at line 51 of file utils.py.

51 def iterify(x):
52  """Takes any object. Returns it if it is iterable. If it
53  is not iterable it puts the object in a list and returns
54  the list. None will return an empty list. If a new list
55  is always required use listify(). Strings will be placed
56  in a list with a single element.
57  """
58  if x is None:
59  x = []
60  elif isinstance(x, basestring):
61  x = [x]
62  elif hasattr(x, '__iter__'):
63  pass
64  else:
65  x = [x]
66  return x
67 
68 

◆ listify()

def lsst.daf.persistence.utils.listify (   x)
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

Definition at line 31 of file utils.py.

31 def listify(x):
32  """Takes any object and puts that whole object in a list:
33  - strings will be made into a single element in the list
34  - tuples will be converted to list
35  - lists will remain as lists
36  - None will be made into an empty list
37  """
38  if x is None:
39  x = []
40  elif isinstance(x, basestring):
41  x = [x]
42  elif isinstance(x, dict):
43  x = [x]
44  elif hasattr(x, '__iter__'):
45  x = list(x)
46  else:
47  x = [x]
48  return x
49 
50 
daf::base::PropertyList * list
Definition: fits.cc:903

◆ sequencify()

def lsst.daf.persistence.utils.sequencify (   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.

Definition at line 69 of file utils.py.

69 def sequencify(x):
70  """Takes an object, if it is a sequence return it,
71  else put it in a tuple. Strings are not sequences.
72  If x is a dict, returns a sorted tuple of keys."""
73  if isinstance(x, (Sequence, Set)) and not isinstance(x, basestring):
74  pass
75  elif isinstance(x, Mapping):
76  x = tuple(sorted(x.keys()))
77  else:
78  x = (x, )
79  return x
80 
81 

◆ setify()

def lsst.daf.persistence.utils.setify (   x)
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)

Definition at line 82 of file utils.py.

82 def setify(x):
83  """Take an object x and return it in a set.
84 
85  If x is a container, will create a set from the contents of the container.
86  If x is an object, will create a set with a single item in it.
87  If x is a string, will treat the string as a single object (i.e. not as a list of chars)"""
88  if x is None:
89  x = set()
90 
91  # Here we have to explicity for strings because the set initializer will use each character in a string as
92  # a separate element. We cannot use the braces initialization because x might be a list, and we do not
93  # want the list to be an item; we want each item in the list to be represented by an item in the set.
94  # Then, we have to fall back to braces init because if the item is NOT a list then the set initializer
95  # won't take it.
96  if isinstance(x, basestring):
97  x = set([x])
98  else:
99  try:
100  x = set(x)
101  except TypeError:
102  x = set([x])
103  return x
104 
105 
daf::base::PropertySet * set
Definition: fits.cc:902