Export schema as a dictionary
483590
def export_schema(cls, recursive=True, include_parent_ref=False):
        """"""
        parent_excludes = {}
        if not include_parent_ref:
            parent_ref = cls.__mapper__.relationships.get(cls.export_parent)
            if parent_ref:
                parent_excludes = {c.name for c in parent_ref.local_columns}

        def formatter(c):
            return ('{0} Default ({1})'.format(
                str(c.type), c.default.arg) if c.default else str(c.type))

        schema = {c.name: formatter(c) for c in cls.__table__.columns
                  if (c.name in cls.export_fields and
                  c.name not in parent_excludes)}
        if recursive:
            for c in cls.export_children:
                child_class = cls.__mapper__.relationships[c].argument.class_
                schema[c] = [child_class.export_schema(recursive=recursive,
                             include_parent_ref=include_parent_ref)]
        return schema
784963
def fields_to_dtypes(schema):
    
    datetime_types = ['date', 'datetime']
    datetime_fields = {
        f['name']: _TABLE_SCHEMA_DTYPE_MAPPING.get(f['type'], 'object')
        for f in schema['fields']
        if f['type'] in datetime_types}

    other_fields = {
        f['name']: _TABLE_SCHEMA_DTYPE_MAPPING.get(f['type'], 'object')
        for f in schema['fields']
        if f['type'] not in datetime_types}

    return {'dates': datetime_fields, 'other': other_fields}
21441
def get_json_schema(filename):
    
    file_path = os.path.join("schemas", filename)
    with open(file_path) as f:
        schema = yaml.load(f)
    return schema
805495
def _get_mapping(self, schema):
        
        properties = {}
        for field, field_schema in schema.items():
            field_mapping = self._get_field_mapping(field_schema)
            if field_mapping:
                properties[field] = field_mapping
        return {'properties': properties}
1224088
private function schema() {
		
		//todo: consider caching this
		$expanded_tables = [];
		$tables = config('center.tables', []);

		foreach ($tables as $table=>$table_properties) {
			
			//sanitize for use in db names and php functions
			$table = str_slug($table, '_');

			//parse table definition
			$table_properties = self::associateNumericKeys($table_properties);
			$table_properties['name'] = $table;
			$table_properties['title'] = trans('center::' . $table . '.title');
			if (!isset($table_properties['keep_clean'])) $table_properties['keep_clean'] = false;
			if (!isset($table_properties['creatable'])) $table_properties['creatable'] = true;
			if (!isset($table_properties['editable'])) $table_properties['editable'] = true;
			if (!isset($table_properties['deletable'])) $table_properties['deletable'] = true;
			if (!isset($table_properties['list'])) $table_properties['list'] = [];
			if (!isset($table_properties['export'])) $table_properties['export'] = [];
			if (!isset($table_properties['search'])) $table_properties['search'] = [];
			if (!isset($table_properties['filters'])) $table_properties['filters'] = [];
			if (!isset($table_properties['timestamps'])) $table_properties['timestamps'] = true;
			
			//temp, soon to look up from permissions table
			$table_properties['dates'] = [];
			
			//loop through fields
			if (!isset($table_properties['fields'])) $table_properties['fields'] = [];
			$expanded_fields = [];
			foreach ($table_properties['fields'] as $field=>$field_properties) {
				
				//resolve shorthand, eg 'updated_at'
				if (is_int($field)) $field = $field_properties;
				if (is_string($field_properties)) {
					if (strpos($field_properties, ' ') !== false) {
						$parts = explode(' ', $field_properties);
						$field_properties = [
							'required' => in_array('required', $parts),
							'hidden' => in_array('hidden', $parts),
							'type' => implode(array_diff($parts, ['required', 'hidden'])),
						];
					} else {
						$field_properties = ['type' => $field_properties];
					}
				}
				$field_properties = self::associateNumericKeys($field_properties);

				//set types on reserved system fields
				if ($field == 'permissions') $field_properties['type'] = 'permissions';
				if (in_array($field, ['created_at', 'updated_at', 'deleted_at'])) $field_properties['type'] = 'datetime';
				if (in_array($field, ['id', 'created_by', 'updated_by', 'deleted_by', 'precedence'])) $field_properties['type'] = 'integer';
				
				//check field type is supported
				if (!in_array($field_properties['type'], self::$field_types)) {
					trigger_error('field ' . $table . '.' . $field . ' is of type ' . $field_properties['type'] . ' which is not supported.');
				}
				
				//relationship columns always end in _id, eg image_id
				//this is so that $model->image_id and $model->image->src can work
				if (in_array($field_properties['type'], ['image', 'select', 'user'])) {
					if (!ends_with($field, '_id')) $field .= '_id';
				}

				//set other field attributes
				$field_properties['name'] = $field;
				$field_properties['title'] = trans('center::' . $table . '.fields.' . $field);
				if (!isset($field_properties['required'])) {
					if (in_array($field, ['id', 'created_at', 'updated_at'])) {
						$field_properties['required'] = true;
					} elseif (in_array($field_properties['type'], ['checkbox'])) {
						$field_properties['required'] = true;
					} else {
						$field_properties['required'] = false;
					}
				}

				//in general, the name of a checkboxes field should be the name of its joining table
				//however your are allowed to name the source, and let the system set the joining table for you
				if (($field_properties['type'] == 'checkboxes') && empty($field_properties['source'])) {
					$field_properties['source'] = $field;
					$field = $field_properties['name'] = RowController::formatJoiningTable($table, $field);
				}
				
				if ($field_properties['type'] == 'user') $field_properties['source'] = config('center.db.users');

				//field max lengths
				if ($field_properties['type'] == 'phone') $field_properties['maxlength'] = 10;
				if ($field_properties['type'] == 'zip') $field_properties['maxlength'] = 5;
				if ($field_properties['type'] == 'us_state') $field_properties['maxlength'] = 2;
				if ($field_properties['type'] == 'country') $field_properties['maxlength'] = 2;
				
				if (!isset($field_properties['hidden'])) $field_properties['hidden'] = in_array($field, ['id', 'created_at', 'updated_at', 'deleted_at', 'created_by', 'updated_by', 'deleted_by', 'password', 'precedence']);
				if (in_array($field_properties['type'], ['image' ,'images'])) {
					if (empty($field_properties['width'])) $field_properties['width'] = null;
					if (empty($field_properties['height'])) $field_properties['height'] = null;
				}

				//empty source on 
				if (in_array($field_properties['type'], ['latitude', 'longitude', 'slug'])) {
					if (empty($field_properties['source'])) $field_properties['source'] = null;
				}
				
				//forced overrides
				if ($field_properties['type'] == 'password') $field_properties['hidden'] = true;
				if ($field_properties['hidden']) $field_properties['required'] = false;
				
				//save
				$expanded_fields[$field] = (object) $field_properties;
				
			}
			
			//save fields to table as an object
			$table_properties['fields'] = (object) $expanded_fields;

			//default table properties
			if (!isset($table_properties['list_grouping'])) $table_properties['list_grouping'] = '';
			if (!isset($table_properties['model'])) $table_properties['model'] = studly_case(str_singular($table));
			if (!isset($table_properties['hidden'])) $table_properties['hidden'] = false;
			if (!isset($table_properties['links'])) $table_properties['links'] = [];
			if (!isset($table_properties['order_by'])) {
				$table_properties['order_by'] = [$table . '.id'=>'asc'];
			} else {
				$table_properties['order_by'] = self::associateNumericKeys($table_properties['order_by'], 'asc');
				foreach ($table_properties['order_by'] as $column => $direction) {
					//add table name to disambiguate
					if (!strstr($column, '.')) {
						unset($table_properties['order_by'][$column]);
						$table_properties['order_by'][$table . '.' . $column] = $direction;
					}
				}
			}

			//save table to $tables array as an object
			$expanded_tables[$table] = (object) $table_properties;
		}

		//sort alpha by title
		uksort($expanded_tables, function($a, $b) use ($expanded_tables) {
			return $expanded_tables[$a]->title > $expanded_tables[$b]->title;
		});

		//dd($expanded_tables);

		Config::set('center.tables', $expanded_tables);		
	}
409043
def _schema_getter(self, db):
        """"""
        # Change DB connection if needed
        if self.database != db:
            self.change_db(db)
        schema_dict = {tbl: self.get_schema(tbl) for tbl in self.tables}

        schema_lst = []
        for table, schema in schema_dict.items():
            for col in schema:
                col.insert(0, table)
                schema_lst.append(col)
        return schema_lst
23028
def export_to_dict(session,
                   recursive,
                   back_references,
                   include_defaults):
    """"""
    logging.info('Starting export')
    dbs = session.query(Database)
    databases = [database.export_to_dict(recursive=recursive,
                 include_parent_ref=back_references,
                 include_defaults=include_defaults) for database in dbs]
    logging.info('Exported %d %s', len(databases), DATABASES_KEY)
    cls = session.query(DruidCluster)
    clusters = [cluster.export_to_dict(recursive=recursive,
                include_parent_ref=back_references,
                include_defaults=include_defaults) for cluster in cls]
    logging.info('Exported %d %s', len(clusters), DRUID_CLUSTERS_KEY)
    data = dict()
    if databases:
        data[DATABASES_KEY] = databases
    if clusters:
        data[DRUID_CLUSTERS_KEY] = clusters
    return data
1347521
def build_schema(self, fields, language):
        
        content_field_name = ''
        mapping = {
            DJANGO_CT: {'type': 'string', 'index': 'not_analyzed', 'include_in_all': False},
            DJANGO_ID: {'type': 'string', 'index': 'not_analyzed', 'include_in_all': False},
        }

        for field_name, field_class in fields.items():
            field_mapping = FIELD_MAPPINGS.get(
                field_class.field_type, DEFAULT_FIELD_MAPPING).copy()
            if field_class.boost != 1.0:
                field_mapping['boost'] = field_class.boost

            if field_class.document is True:
                content_field_name = field_class.index_fieldname

            # Do this last to override `text` fields.
            if field_mapping['type'] == 'string':
                # Use the language analyzer for text fields.
                if field_mapping['analyzer'] == DEFAULT_FIELD_MAPPING['analyzer']:
                    field_mapping['analyzer'] = get_analyzer_for(language)
                if field_class.indexed is False or hasattr(field_class, 'facet_for'):
                    field_mapping['index'] = 'not_analyzed'
                    del field_mapping['analyzer']

            mapping[field_class.index_fieldname] = field_mapping

        return content_field_name, mapping
764300
def get_schema(self, table, with_headers=False):
        """"""
        f = self.fetch('desc ' + wrap(table))
        if not isinstance(f[0], list):
            f = [f]

        # Replace None with ''
        schema = [['' if col is None else col for col in row] for row in f]

        # If with_headers is True, insert headers to first row before returning
        if with_headers:
            schema.insert(0, ['Column', 'Type', 'Null', 'Key', 'Default', 'Extra'])
        return schema
1198797
function dict(schema, defaults, options) {
  if (kindOf(schema) !== 'array' || schema.length !== 2) {
    if (process.env.NODE_ENV !== 'production') {
      throw new Error(
        `Dict structs must be defined as an array with two elements, but you passed: ${schema}`
      )
    } else {
      throw new Error(`Invalid schema: ${schema}`)
    }
  }

  const obj = scalar('object', undefined, options)
  const keys = any(schema[0], undefined, options)
  const values = any(schema[1], undefined, options)
  const name = 'dict'
  const type = `dict<${keys.type},${values.type}>`
  const validate = value => {
    const resolved = resolveDefaults(defaults)
    value = resolved ? { ...resolved, ...value } : value
    const [error] = obj.validate(value)

    if (error) {
      error.type = type
      return [error]
    }

    const ret = {}
    const errors = []

    for (let k in value) {
      const v = value[k]
      const [e, r] = keys.validate(k)

      if (e) {
        const allE = e.errors || [e]
        allE.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      k = r
      const [e2, r2] = values.validate(v)

      if (e2) {
        const allE2 = e2.errors || [e2]
        allE2.forEach(singleE => {
          singleE.path = [k].concat(singleE.path)
          singleE.data = value
          errors.push(singleE)
        })
        continue
      }

      ret[k] = r2
    }

    if (errors.length) {
      const first = errors[0]
      first.errors = errors
      return [first]
    }

    return [undefined, ret]
  }

  return new Kind(name, type, validate)
}
374813
def load_schema(path):
    """"""
    with open(path) as json_data:
        schema = json.load(json_data)
    return schema
791897
def load_schema(schema_path):
    '''
    
    '''
    with open(schema_path) as fd:
        schema = json.load(fd)
    schema_dir, schema_file = path.split(schema_path)
    return _load_schema(schema, schema_dir)
718374
def DefaultExtension(schema_obj, form_obj, schemata=None):
    """"""

    if schemata is None:
        schemata = ['systemconfig', 'profile', 'client']

    DefaultExtends = {
        'schema': {
            "properties/modules": [
                schema_obj
            ]
        },
        'form': {
            'modules': {
                'items/': form_obj
            }
        }
    }

    output = {}

    for schema in schemata:
        output[schema] = DefaultExtends

    return output
1146898
def to_dict(self):
        

        # 1. extract the schema fields
        data = self.extract_fields()

        # 2. include custom key-value pairs listed in the mapping dictionary
        for key, attr in self.attributes.iteritems():
            if key in self.ignore:
                continue  # skip ignores
            # fetch the mapped attribute
            value = getattr(self.context, attr, None)
            if value is None:
                value = getattr(self, attr, None)
            # handle function calls
            if callable(value):
                value = value()
            # map the value to the given key from the mapping
            data[key] = api.to_json_value(self.context, key, value)
        return data
531418
def db_export(schema, uuid, object_filter, export_format, filename, pretty, all_schemata, omit):
    """"""

    internal_backup(schema, uuid, object_filter, export_format, filename, pretty, all_schemata, omit)
340762
def dict(self):
        
        d = {p.key: getattr(self, p.key) for p in self.__mapper__.attrs
             if p.key not in ('table', 'stats', '_codes', 'data')}

        if not d:
            raise Exception(self.__dict__)

        d['schema_type'] = self.schema_type

        if self.data:
            # Copy data fields into top level dict, but don't overwrite existind values.
            for k, v in six.iteritems(self.data):
                if k not in d and k not in ('table', 'stats', '_codes', 'data'):
                    d[k] = v

        return d
272902
def dump(schema):
    
    result = {}

    for name, _ in iteritems(schema.getschemas()):

        if hasattr(schema, name):
            val = getattr(schema, name)

            if isinstance(val, DynamicValue):
                val = val()

            if isinstance(val, Schema):
                val = dump(val)

            result[name] = val

    return result