Submit
Path:
~
/
/
proc
/
thread-self
/
root
/
opt
/
alt
/
python27
/
lib
/
python2.7
/
site-packages
/
File Content:
schema.py
__version__ = '0.3.1' class SchemaError(Exception): """Error during Schema validation.""" def __init__(self, autos, errors): self.autos = autos if type(autos) is list else [autos] self.errors = errors if type(errors) is list else [errors] Exception.__init__(self, self.code) @property def code(self): def uniq(seq): seen = set() seen_add = seen.add return [x for x in seq if x not in seen and not seen_add(x)] a = uniq(i for i in self.autos if i is not None) e = uniq(i for i in self.errors if i is not None) if e: return '\n'.join(e) return '\n'.join(a) class And(object): def __init__(self, *args, **kw): self._args = args assert list(kw) in (['error'], []) self._error = kw.get('error') def __repr__(self): return '%s(%s)' % (self.__class__.__name__, ', '.join(repr(a) for a in self._args)) def validate(self, data): for s in [Schema(s, error=self._error) for s in self._args]: data = s.validate(data) return data class Or(And): def validate(self, data): x = SchemaError([], []) for s in [Schema(s, error=self._error) for s in self._args]: try: return s.validate(data) except SchemaError as _x: x = _x raise SchemaError(['%r did not validate %r' % (self, data)] + x.autos, [self._error] + x.errors) class Use(object): def __init__(self, callable_, error=None): assert callable(callable_) self._callable = callable_ self._error = error def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self._callable) def validate(self, data): try: return self._callable(data) except SchemaError as x: raise SchemaError([None] + x.autos, [self._error] + x.errors) except BaseException as x: f = self._callable.__name__ raise SchemaError('%s(%r) raised %r' % (f, data, x), self._error) def priority(s): """Return priority for a give object.""" if type(s) in (list, tuple, set, frozenset): return 6 if type(s) is dict: return 5 if hasattr(s, 'validate'): return 4 if issubclass(type(s), type): return 3 if callable(s): return 2 else: return 1 class Schema(object): def __init__(self, schema, error=None): self._schema = schema self._error = error def __repr__(self): return '%s(%r)' % (self.__class__.__name__, self._schema) def validate(self, data): s = self._schema e = self._error if type(s) in (list, tuple, set, frozenset): data = Schema(type(s), error=e).validate(data) return type(s)(Or(*s, error=e).validate(d) for d in data) if type(s) is dict: data = Schema(dict, error=e).validate(data) new = type(data)() # new - is a dict of the validated values x = None coverage = set() # non-optional schema keys that were matched # for each key and value find a schema entry matching them, if any sorted_skeys = list(sorted(s, key=priority)) for key, value in data.items(): valid = False skey = None for skey in sorted_skeys: svalue = s[skey] try: nkey = Schema(skey, error=e).validate(key) except SchemaError: pass else: try: nvalue = Schema(svalue, error=e).validate(value) except SchemaError as _x: x = _x raise else: coverage.add(skey) valid = True break if valid: new[nkey] = nvalue elif skey is not None: if x is not None: raise SchemaError(['invalid value for key %r' % key] + x.autos, [e] + x.errors) coverage = set(k for k in coverage if type(k) is not Optional) required = set(k for k in s if type(k) is not Optional) if coverage != required: raise SchemaError('missed keys %r' % (required - coverage), e) if len(new) != len(data): wrong_keys = set(data.keys()) - set(new.keys()) s_wrong_keys = ', '.join('%r' % k for k in sorted(wrong_keys)) raise SchemaError('wrong keys %s in %r' % (s_wrong_keys, data), e) return new if hasattr(s, 'validate'): try: return s.validate(data) except SchemaError as x: raise SchemaError([None] + x.autos, [e] + x.errors) except BaseException as x: raise SchemaError('%r.validate(%r) raised %r' % (s, data, x), self._error) if issubclass(type(s), type): if isinstance(data, s): return data else: raise SchemaError('%r should be instance of %r' % (data, s), e) if callable(s): f = s.__name__ try: if s(data): return data except SchemaError as x: raise SchemaError([None] + x.autos, [e] + x.errors) except BaseException as x: raise SchemaError('%s(%r) raised %r' % (f, data, x), self._error) raise SchemaError('%s(%r) should evaluate to True' % (f, data), e) if s == data: return data else: raise SchemaError('%r does not match %r' % (s, data), e) class Optional(Schema): """Marker for an optional part of Schema."""
Edit
Rename
Chmod
Delete
FILE
FOLDER
Name
Size
Permission
Action
Babel-1.3-py2.7.egg-info
---
0755
Beaker-1.5.4-py2.7.egg-info
---
0755
Jinja2-2.7.2-py2.7.egg-info
---
0755
Mako-0.7.3-py2.7.egg-info
---
0755
Paste-1.7.5.1-py2.7.egg-info
---
0755
Tempita-0.5.1-py2.7.egg-info
---
0755
_dummy_thread
---
0755
_markupbase
---
0755
_thread
---
0755
alembic
---
0755
alembic-0.8.3-py2.7.egg-info
---
0755
argparse-1.2.1-py2.7.egg-info
---
0755
babel
---
0755
beaker
---
0755
builtins
---
0755
chardet
---
0755
chardet-2.3.0-py2.7.egg-info
---
0755
clquota
---
0755
clselect
---
0755
clselector
---
0755
contextlib2-0.5.4-py2.7.egg-info
---
0755
copyreg
---
0755
dateutil
---
0755
docopt-0.6.2-py2.7.egg-info
---
0755
future
---
0755
future-0.17.0-py2.7.egg-info
---
0755
html
---
0755
http
---
0755
jinja2
---
0755
jsonschema
---
0755
jsonschema-2.6.0-py2.7.egg-info
---
0755
libfuturize
---
0755
libpasteurize
---
0755
lvemanager
---
0755
lvestats
---
0755
mako
---
0755
nose
---
0755
nose-1.3.4-py2.7.egg-info
---
0755
past
---
0755
paste
---
0755
pip
---
0755
pip-20.2.4.dist-info
---
0755
pkg_resources
---
0755
python_dateutil-1.4.1-py2.7.egg-info
---
0755
python_editor-0.4-py2.7.egg-info
---
0755
pytz
---
0755
queue
---
0755
raven
---
0755
raven-6.3.0-py2.7.egg-info
---
0755
repoze
---
0755
repoze.lru-0.6-py2.7.egg-info
---
0755
reprlib
---
0755
requests
---
0755
requests-2.10.0-py2.7.egg-info
---
0755
schema-0.3.1-py2.7.egg-info
---
0755
setuptools
---
0755
setuptools-36.3.0.post20231113.dist-info
---
0755
socketserver
---
0755
svgwrite
---
0755
svgwrite-1.1.5-py2.7.egg-info
---
0755
tempita
---
0755
tkinter
---
0755
urllib3
---
0755
urllib3-1.15.1-py2.7.egg-info
---
0755
winreg
---
0755
xmlrpc
---
0755
Paste-1.7.5.1-py2.7-nspkg.pth
304 bytes
0644
PySocks-1.5.7-py2.7.egg-info
322 bytes
0644
argparse.py
87791 bytes
0644
argparse.pyc
67763 bytes
0644
argparse.pyo
67598 bytes
0644
clhooklib.pyc
3126 bytes
0644
contextlib2.py
14828 bytes
0644
contextlib2.pyc
16009 bytes
0644
contextlib2.pyo
16009 bytes
0644
docopt.py
19946 bytes
0644
docopt.pyc
24666 bytes
0644
docopt.pyo
24447 bytes
0644
easy_install.py
126 bytes
0644
easy_install.pyc
328 bytes
0644
easy_install.pyo
328 bytes
0644
editor.py
2550 bytes
0755
editor.pyc
3577 bytes
0644
editor.pyo
3577 bytes
0644
lprettytable.py
23849 bytes
0644
lprettytable.pyc
19697 bytes
0644
lprettytable.pyo
19558 bytes
0644
pyparsing-1.5.6-py2.7.egg-info
670 bytes
0644
pyparsing.py
155429 bytes
0644
pyparsing.pyc
153536 bytes
0644
pyparsing.pyo
153536 bytes
0644
pytz-2012d-py2.7.egg-info
23309 bytes
0644
repoze.lru-0.6-py2.7-nspkg.pth
307 bytes
0644
schema.py
6206 bytes
0644
schema.pyc
8532 bytes
0644
schema.pyo
8443 bytes
0644
six-1.9.0-py2.7.egg-info
1419 bytes
0644
six.py
29664 bytes
0644
six.pyc
30722 bytes
0644
six.pyo
30722 bytes
0644
socks.py
29952 bytes
0644
socks.pyc
25688 bytes
0644
socks.pyo
25688 bytes
0644
sockshandler.py
2913 bytes
0644
sockshandler.pyc
4737 bytes
0644
sockshandler.pyo
4737 bytes
0644
typing-3.5.3.0-py2.7.egg-info
1484 bytes
0644
typing.py
64895 bytes
0644
typing.pyc
79068 bytes
0644
typing.pyo
78407 bytes
0644
N4ST4R_ID | Naxtarrr