summaryrefslogtreecommitdiff
path: root/voluptuous.py
diff options
context:
space:
mode:
authorAlec Thomas <alec@swapoff.org>2011-08-14 15:52:53 -0700
committerAlec Thomas <alec@swapoff.org>2011-08-14 15:52:53 -0700
commit5c3ef8b5f838aa8c86507ce937b3f1ec8a38373a (patch)
tree726a7b3e3bdd2680910d8f50929feb04b7b577cb /voluptuous.py
parentfcc144ab7342bd6bb7c3382d855a3c0772a97e5d (diff)
parente71af67202598126cc54a9baaeb42fd632bfaba8 (diff)
downloadvoluptuous-5c3ef8b5f838aa8c86507ce937b3f1ec8a38373a.tar.gz
Merge pull request #2 from kjkuan/master
dict and list as type validators; validation returns the correct type of instance.
Diffstat (limited to 'voluptuous.py')
-rw-r--r--voluptuous.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/voluptuous.py b/voluptuous.py
index be450a8..20da1a1 100644
--- a/voluptuous.py
+++ b/voluptuous.py
@@ -160,15 +160,15 @@ class Schema(object):
return self.validate([], self.schema, data)
def validate(self, path, schema, data):
+ if isinstance(schema, dict):
+ return self.validate_dict(path, schema, data)
+ elif isinstance(schema, list):
+ return self.validate_list(path, schema, data)
type_ = type(schema)
if type_ is type:
type_ = schema
- if type_ is dict:
- return self.validate_dict(path, schema, data)
- elif type_ is list:
- return self.validate_list(path, schema, data)
- elif type_ in (int, long, str, unicode, float, complex, object,
- types.NoneType) or callable(schema):
+ if type_ in (int, long, str, unicode, float, complex, object,
+ list, dict, types.NoneType) or callable(schema):
return self.validate_scalar(path, schema, data)
raise SchemaError('unsupported schema data type %r' %
type(schema).__name__)
@@ -232,7 +232,7 @@ class Schema(object):
if not isinstance(data, dict):
raise Invalid('expected a dictionary', path)
- out = {}
+ out = type(data)()
required_keys = set(key for key in schema
if
(self.required and not isinstance(key, optional))
@@ -309,7 +309,7 @@ class Schema(object):
if not schema:
return data
- out = []
+ out = type(data)()
invalid = None
index_path = UNDEFINED
for i, value in enumerate(data):