doncatnip / kanone Goto Github PK
View Code? Open in Web Editor NEWA general purpose validation library
License: The Unlicense
A general purpose validation library
License: The Unlicense
When #14 is done, tagging needs to be reworked as right now nested tag parameters work as follows:
o = MyComposedValidator(taggedValidator_validationParameter=42)
with under_score naming this would not be possible.
Example:
before
@messages\
( type="Invalid type (%(value.type)s), must be a integer"
, convert="Could not convert %(value.type)s to integer"
)
after
from gettext import gettext as _
@messages\
( type=_("Invalid type (%(value.type)s), must be a integer")
, convert=_("Could not convert %(value.type)s to integer")
)
I'found that Match validator seems to be copy pasted ? Am I right ?
...
def setParameters(self, required, ignoreCase=False):
...
"required" adds misunderstand in validator uses, maybe it will be better to change to something more meaningful ? like expression, pattern or s.e.
/kanone/validator/check.py
from:
max="Value cannot have more than least%(max)i elements/characters (has %(len)s)"
to:
max="Value cannot have more than least %(max)i elements/characters (has %(len)s)"
missing space between "least %(max)i"
Refactor kanone to use under_score instead of camelCase for variables, parameters and function names
@messages\
( type="Invalid type (%(value.type)s), must be a bool"
)
class HumanBoolean( TypeValidator):
def on_value(self, context, value):
if isinstance(value, int )\
and not(value<0 or value>1):
value = bool(value)
if not (isinstance( value, bool )):
if self._convert:
if str(value).lower() in ('1', 'true', 'yes', 'on'):
return True
elif str(value).lower() in ('0', 'false', 'no', 'off'):
return False
raise Invalid( value, self, 'type' )
return value
the code
s2 = (
't1', String() & Len(max=9),
)
s = Schema(
*s2
)
c2 = {
't1': u'Скушай яблоко',
}
c = s.context(c2)
Traceback (most recent call last):
File "utils.py", line 94, in
result = c.result
File "build/bdist.linux-x86_64/egg/kanone/lib.py", line 222, in result
return self.validate()
File "build/bdist.linux-x86_64/egg/kanone/lib.py", line 331, in validate
result = self.validator.validate( self, self.value)
File "build/bdist.linux-x86_64/egg/kanone/validator/core.py", line 116, in validate
return self.on_value( context, value )
File "build/bdist.linux-x86_64/egg/kanone/validator/schema.py", line 69, in on_value
return self.on_value( context, value )
File "build/bdist.linux-x86_64/egg/kanone/validator/schema.py", line 174, in _createContextChilds_on_value
res = context( key ).result
File "build/bdist.linux-x86_64/egg/kanone/lib.py", line 222, in result
return self.validate()
File "build/bdist.linux-x86_64/egg/kanone/lib.py", line 334, in validate
self.error = e
File "build/bdist.linux-x86_64/egg/kanone/lib.py", line 250, in error
extra['value'] = str(value)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-5: ordinal not in range(128)
since Blank is restricted to the String datatype only maybe on_blank should not be a thing - and if we want to keep it, a string containing whitespaces should count as blank too.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.