def _load_schema_url(url): import urllib2 try: res = urllib2.urlopen(url) tables = res.read() except urllib2.URLError: raise SchemingException("Could not load %s" % url) return loader.loads(tables, url)
def _load_schema_url(url): from six.moves import urllib try: res = urllib.request.urlopen(url) tables = res.read() except urllib.error.URLError: raise SchemingException("Could not load %s" % url) return loader.loads(tables, url)
def get_validator_or_converter(name): """ Get a validator or converter by name """ if name == 'unicode': return unicode try: v = get_validator(name) return v except UnknownValidator: pass raise SchemingException('validator/converter not found: %r' % name)
def _expand_preset(f): """ If scheming field f includes a preset value return a new field based on the preset with values from f overriding any values in the preset. raises SchemingException if the preset given is not found. """ if 'preset' not in f: return f if f['preset'] not in _SchemingMixin._presets: raise SchemingException("preset '%s' not defined" % f['preset']) return dict(_SchemingMixin._presets[f['preset']], **f)
def _expand(schema, field): """ If scheming field f includes a preset value return a new field based on the preset with values from f overriding any values in the preset. raises SchemingException if the preset given is not found. """ preset = field.get('preset') if preset: if preset not in _SchemingMixin._presets: raise SchemingException('preset \'{}\' not defined'.format(preset)) field = dict(_SchemingMixin._presets[preset], **field) return field
def _expand(schema, field): """ If scheming field f includes a preset value return a new field based on the preset with values from f overriding any values in the preset. Applies default values to fields that are expected to always exist. raises SchemingException if the preset given is not found. """ preset = field.get('preset') if preset: if preset not in _SchemingMixin._presets: raise SchemingException('preset \'{}\' not defined'.format(preset)) field = dict(_SchemingMixin._presets[preset], **field) field.setdefault('display_group', schema.get('display_group_default', u'General')) return field