def build_stack(obj):
 if (type(obj) is list):
  layers = map(build_stack, obj)
  return Stack(layers)
 elif (type(obj) is dict):
  keys = (('src', 'layername'), ('color', 'colorname'), ('mask', 'maskname'), ('opacity', 'opacity'), ('mode', 'blendmode'), ('adjustments', 'adjustments'), ('zoom', 'zoom'))
  args = [(arg, obj[key]) for (key, arg) in keys if (key in obj)]
  return Layer(**dict(args))
 else:
  raise Exception('Uh oh')

def build_stack ( obj ) : if ( type ( obj ) is list ) : layers = map ( build_stack , obj ) return Stack ( layers ) elif ( type ( obj ) is dict ) : keys = ( ( 'src' , 'layername' ) , ( 'color' , 'colorname' ) , ( 'mask' , 'maskname' ) , ( 'opacity' , 'opacity' ) , ( 'mode' , 'blendmode' ) , ( 'adjustments' , 'adjustments' ) , ( 'zoom' , 'zoom' ) ) args = [ ( arg , obj [ key ] ) for ( key , arg ) in keys if ( key in obj ) ] return Layer ( ** dict ( args ) ) else : raise Exception ( 'Uh oh' )
build up a data structure of stack and layer objects from lists of dictionaries .