Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
C
corepost
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
nexlab
corepost
Commits
fb637a21
Commit
fb637a21
authored
Sep 04, 2011
by
Jacek Furmankiewicz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial validators working
parent
0f3a3792
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
10 deletions
+17
-10
.pydevproject
.pydevproject
+1
-1
org.eclipse.ltk.core.refactoring.prefs
.settings/org.eclipse.ltk.core.refactoring.prefs
+3
-0
validate.feature
corepost/test/feature/validate.feature
+2
-2
web.py
corepost/web.py
+11
-7
No files found.
.pydevproject
View file @
fb637a21
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
<?eclipse-pydev version="1.0"?>
<?eclipse-pydev version="1.0"?>
<pydev_project>
<pydev_project>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_INTERPRETER"
>
py
py
</pydev_property>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_INTERPRETER"
>
py
thon
</pydev_property>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_VERSION"
>
python 2.7
</pydev_property>
<pydev_property
name=
"org.python.pydev.PYTHON_PROJECT_VERSION"
>
python 2.7
</pydev_property>
<pydev_pathproperty
name=
"org.python.pydev.PROJECT_SOURCE_PATH"
>
<pydev_pathproperty
name=
"org.python.pydev.PROJECT_SOURCE_PATH"
>
<path>
/corepost
</path>
<path>
/corepost
</path>
...
...
.settings/org.eclipse.ltk.core.refactoring.prefs
0 → 100644
View file @
fb637a21
#Sat Sep 03 22:26:56 EDT 2011
eclipse.preferences.version=1
org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false
corepost/test/feature/validate.feature
View file @
fb637a21
...
@@ -18,10 +18,10 @@ Feature: Argument Validators
...
@@ -18,10 +18,10 @@ Feature: Argument Validators
|
custom
|
childId=jacekf
|
201
|
23
-
jacekf
-
{}
|
|
custom
|
childId=jacekf
|
201
|
23
-
jacekf
-
{}
|
|
custom
|
childId=jacekf&otherId=test
|
201
|
23
-
jacekf
-
{'otherId':
'test'}
|
|
custom
|
childId=jacekf&otherId=test
|
201
|
23
-
jacekf
-
{'otherId':
'test'}
|
|
custom
|
childId=test
|
201
|
23
-
test
-
{}
|
|
custom
|
childId=test
|
201
|
23
-
test
-
{}
|
|
custom
|
childId=wrong
|
400
|
'wrong'
is
not
a
valid
value
for
'childId':
The
input
is
not
valid
|
|
custom
|
childId=wrong
|
400
|
childId:
The
input
is
not
valid
('wrong')
|
# validates using Schema
# validates using Schema
|
schema
|
childId=jacekf
|
201
|
23
-
jacekf
-
{}
|
|
schema
|
childId=jacekf
|
201
|
23
-
jacekf
-
{}
|
|
schema
|
childId=jacekf&otherId=test
|
201
|
23
-
jacekf
-
{'otherId':
'test'}
|
|
schema
|
childId=jacekf&otherId=test
|
201
|
23
-
jacekf
-
{'otherId':
'test'}
|
|
schema
|
childId=test
|
201
|
23
-
test
-
{}
|
|
schema
|
childId=test
|
201
|
23
-
test
-
{}
|
|
schema
|
childId=wrong
|
400
|
'wrong'
is
not
a
valid
value
for
'childId':
The
input
is
not
valid
|
|
schema
|
childId=wrong
|
400
|
childId:
The
input
is
not
valid
('wrong')
|
\ No newline at end of file
corepost/web.py
View file @
fb637a21
...
@@ -251,16 +251,15 @@ def validate(schema=None,**vKwargs):
...
@@ -251,16 +251,15 @@ def validate(schema=None,**vKwargs):
def
fn
(
realfn
):
def
fn
(
realfn
):
def
wrap
(
*
args
,
**
kwargs
):
def
wrap
(
*
args
,
**
kwargs
):
# first run schema validation, then the custom validators
# first run schema validation, then the custom validators
errors
=
()
errors
=
[]
if
schema
!=
None
:
if
schema
!=
None
:
try
:
try
:
schema
.
to_python
(
kwargs
)
schema
.
to_python
(
kwargs
)
except
Invalid
as
ex
:
except
Invalid
as
ex
:
errors
=
()
for
arg
,
error
in
ex
.
error_dict
.
items
():
for
error
in
ex
.
error_dict
.
keys
():
errors
.
append
(
"
%
s:
%
s ('
%
s')"
%
(
arg
,
error
.
msg
,
error
.
value
))
errors
.
append
()
raise
TypeError
(
"
%
s"
%
ex
)
# custom validators
for
arg
in
vKwargs
.
keys
():
for
arg
in
vKwargs
.
keys
():
validator
=
vKwargs
[
arg
]
validator
=
vKwargs
[
arg
]
if
arg
in
kwargs
:
if
arg
in
kwargs
:
...
@@ -268,10 +267,15 @@ def validate(schema=None,**vKwargs):
...
@@ -268,10 +267,15 @@ def validate(schema=None,**vKwargs):
try
:
try
:
validator
.
to_python
(
val
)
validator
.
to_python
(
val
)
except
Invalid
as
ex
:
except
Invalid
as
ex
:
raise
TypeError
(
"'
%
s' is not a valid value for '
%
s':
%
s"
%
(
val
,
arg
,
ex
))
errors
.
append
(
"
%
s:
%
s ('
%
s')"
%
(
arg
,
ex
,
val
))
else
:
else
:
if
isinstance
(
validator
,
FancyValidator
)
and
validator
.
not_empty
:
if
isinstance
(
validator
,
FancyValidator
)
and
validator
.
not_empty
:
raise
TypeError
(
"Missing mandatory argument '
%
s'"
%
arg
)
raise
TypeError
(
"Missing mandatory argument '
%
s'"
%
arg
)
# fire error if anything failed validation
if
len
(
errors
)
>
0
:
raise
TypeError
(
'
\n
'
.
join
(
errors
))
# all OK
return
realfn
(
*
args
,
**
kwargs
)
return
realfn
(
*
args
,
**
kwargs
)
return
wrap
return
wrap
return
fn
return
fn
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment