Пример #1
0
 def expand(self):
     """Flesh out undefined items with defaults, if any, from the spec."""
     if not self.dense:
         dense = OrderedDictWithDefaults()
         # Populate dict with default values from the spec
         stack = [[dense, self.spec]]
         while stack:
             defs, spec = stack.pop()
             for key, val in spec.items():
                 if isinstance(val, dict):
                     if key not in defs:
                         defs[key] = OrderedDictWithDefaults()
                     stack.append((defs[key], spec[key]))
                 else:
                     try:
                         defs[key] = spec[key][1]
                     except IndexError:
                         if spec[key][0].endswith('_LIST'):
                             defs[key] = []
                         else:
                             defs[key] = None
         # override defaults with sparse values
         m_override(dense, self.sparse)
         un_many(dense)
         self.dense = dense
Пример #2
0
def expand(sparse, spec):
    # get dense defaults
    dense = get_defaults(spec)
    # override defaults with sparse values
    m_override(dense, sparse)
    un_many(dense)
    return dense
Пример #3
0
def expand( sparse, spec ):
    # get dense defaults
    dense = get_defaults(spec)
    # override defaults with sparse values
    m_override( dense, sparse )
    un_many( dense )
    return dense
Пример #4
0
 def expand(self):
     """Flesh out undefined items with defaults, if any, from the spec."""
     if not self.dense:
         dense = OrderedDictWithDefaults()
         # Populate dict with default values from the spec
         stack = [[dense, self.spec]]
         while stack:
             defs, spec = stack.pop()
             for key, val in spec.items():
                 if isinstance(val, dict):
                     if key not in defs:
                         defs[key] = OrderedDictWithDefaults()
                     stack.append((defs[key], spec[key]))
                 else:
                     try:
                         defs[key] = spec[key][1]
                     except IndexError:
                         if spec[key][0].endswith('_LIST'):
                             defs[key] = []
                         else:
                             defs[key] = None
         # override defaults with sparse values
         m_override(dense, self.sparse)
         un_many(dense)
         self.dense = dense