# -*- coding: utf-8 -*-
# $Id: BackendSchema.py 1603 2011-10-10 12:33:02Z amelung $
#
# Copyright (c) 2007-2011 Otto-von-Guericke-Universität Magdeburg
#
# This file is part of ECSpooler.
try:
import hashlib
except ImportError:
class Field:
"""
Class attribute _properties is a dictionary containing all of a
field's property values.
"""
_properties = {
'type' : None,
'required' : False,
'format' : None,
'label' : '',
'description': '',
'languageIndependent' : False,
}
"""
Assign name to __name__. Add properties and passed-in
keyword args to __dict__.
"""
if name is None:
global _field_count
_field_count += 1
"""Return the name of this field as a string"""
"""
Return a dict with all properties and values stored for this Field.
"""
return properties
"""
Return a copy of field instance, consisting of field name and
properties dictionary. field name can be changed to given name.
"""
"""Utility method for converting a Field to a string for the
purpose of comparing fields. Right now it's pretty crude"""
for k in sorted_keys:
return retval
"""
Return a string representation consisting of name, type and permissions.
"""
#class TestSpec(Field):
"""
Testing environment
"""
'test': None,
'syntax': None,
'semantic': None,
'compiler': None,
'interpreter': None,
'encoding': 'utf-8'
})
"""
"""
'type' : 'RepeatField',
'format' : 'text',
'accessor': '_getLines',
})
"""Return the accessor method for getting data out of this
field"""
return None
"""
"""
result = []
if value:
# we don't want empty lines
# end if
return result
"""
Class attribute _properties is a dictionary containing all of a
field's property values.
"""
'type' : 'InputField',
'format' : 'text',
})
class Schemata:
"""
Manage a list of fields by grouping them together.
Schematas are identified by their names.
"""
#__implements__ = ISchemata
"""Initialize Schemata and add optional fields"""
if fields is not None:
"""Returns the Schemata's name"""
"""
Returns a new Schemata object that contains all fields and layers
from ``self`` and ``other``.
"""
print "in Schemata.__add__"
c = Schemata()
return c
"""Returns a deep copy of this Schemata.
"""
c = Schemata()
return c
"""Returns a list of my fields in order of their indices"""
"""Returns a subset of self.fields(), containing only fields that
satisfy the given conditions.
You can either specify predicates or values or both. If you provide
both, all conditions must be satisfied.
For each ``predicate`` (positional argument), ``predicate(field)`` must
return 1 for a Field ``field`` to be returned as part of the result.
Each ``attr=val`` function argument defines an additional predicate:
A field must have the attribute ``attr`` and field.attr must be equal
to value ``val`` for it to be in the returned list.
"""
results = []
# predicate failed:
if failed: continue
# attribute missing:
if missing_attrs: continue
# attribute value unequal:
if diff_values: continue
return results
"""Adds a given field to my dictionary of fields"""
#field = aq_base(field)
"""Validates fields on adding and bootstrapping
"""
# two primary fields are forbidden
raise Exception("Tried to add '%s' as primary field " \
"but %s already has the primary field '%s'" % \
)
# Do not allowed unqualified references
raise Exception("Unqualified relationship or "\
"unsupported relationship var type in field '%s'. "\
"The relationship qualifer must be a non empty "\
"string" % name
)
"""Returns a list containing names of all searchable fields"""
"""Returns the first primary field or False"""
return f
return False
"""Manage a list of fields and run methods over them"""
#__implements__ = ISchema
_properties = {}
"""
Initialize a Schema.
The first positional argument may be a sequence of
Fields. (All further positional arguments are ignored.)
Keyword arguments are added to my properties.
"""
else:
msg = ('You are passing positional arguments '
'to the Schema constructor. '
'Please consult the docstring '
'for %s.BasicSchema.__init__' %
level = 3
level = 4
c = BasicSchema()
# We can't use update and keep the order so we do it manually
# Need to be smarter when joining layers
# and internal props
return c
"""Returns a deep copy of this Schema.
"""
c = BasicSchema()
# Need to be smarter when joining layers
# and internal props
return c
# def setDefaults(self, instance):
# """Only call during object initialization. Sets fields to
# schema defaults
# """
# for field in self.values():
# if field.getName().lower() == 'id': continue
# if field.type == "reference": continue
#
# # always set defaults on writable fields
# mutator = field.getMutator(instance)
# if mutator is None:
# continue
# default = field.getDefault(instance)
#
# args = (default,)
# kw = {'field': field.__name__,
# '_initializing_': True}
# if shasattr(field, 'default_content_type'):
# # specify a mimetype if the mutator takes a
# # mimetype argument
# kw['mimetype'] = field.default_content_type
# mapply(mutator, *args, **kw)
"""This method mutates fields in the given instance.
For each keyword argument k, the key indicates the name of the
field to mutate while the value is used to call the mutator.
E.g. updateAll(instance, id='123', amount=500) will, depending on the
actual mutators set, result in two calls: ``instance.setId('123')`` and
``instance.setAmount(500)``.
"""
if field is None:
continue
continue
# If passed the test above, mutator is guaranteed to
# exist.
s = s + '%s,' % (f.toString())
s = s + '}'
return s
"""
"""
#return md5(self.toString()).digest()
# def replaceField(self, name, field):
# if IField.isImplementedBy(field):
# oidx = self._names.index(name)
# new_name = field.getName()
# self._names[oidx] = new_name
# del self._fields[name]
# self._fields[new_name] = field
# else:
# raise ValueError, "Object doesn't implement IField: %r" % field
"""
Schema
"""
"""
"""
"""
"""
c = Schema()
# We can't use update and keep the order so we do it manually
# Need to be smarter when joining layers
# and internal props
#layers = {}
#for k, v in self.registeredLayers():
# layers[k] = v
#for k, v in other.registeredLayers():
# layers[k] = v
#for k, v in layers.items():
# c.registerLayer(k, v)
return c
"""Returns a deep copy of this Schema.
"""
if factory is None:
c = factory()
# Need to be smarter when joining layers
# and internal props
#layers = {}
#for k, v in self.registeredLayers():
# c.registerLayer(k, v)
return c
# -- Test section -------------------------------------------------------------
if __name__ == "__main__":
'simpleTest',
label = 'Simple',
description = 'Simple test; no permutations.',
test = 'def test(a, b): return (a == b)',
semantic = 'import sys\n\n',
),
'model',
label = 'Model solution',
description = 'Enter a model solution.',
i18n_domain = 'EC',
),
'testData',
label = 'Tests',
description = 'Enter one or more test calls',
i18n_domain = 'EC',
),
))
#for field in simpleSchema.filterFields(type='TestEnvironment'):
# print field
#for field in simpleSchema.filterFields(type='InputField'):
# print field.getName()
# print field.required
#
# print field.getAllProperties()
#repeatFields = simpleSchema.filterFields(type='RepeatField')
#repeatField = repeatFields[0]
#print repeatField.getAccessor()('1')
#field = simpleSchema.get('testData')
#print field.getAllProperties()
print simpleSchema.fields()
print simpleSchema.fields()