|
1 | 1 | #!/usr/bin/env python |
2 | | -# Copyright (c) 2015, 2016 IBM. All rights reserved. |
| 2 | +# Copyright (c) 2015, 2018 IBM. All rights reserved. |
3 | 3 | # |
4 | 4 | # Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | # you may not use this file except in compliance with the License. |
|
21 | 21 |
|
22 | 22 | from ._2to3 import iteritems_, next_, unicode_, STRTYPE, NONETYPE |
23 | 23 | from .error import CloudantArgumentError, CloudantFeedException |
24 | | -from ._common_util import feed_arg_types, TYPE_CONVERTERS |
| 24 | +from ._common_util import ANY_ARG, ANY_TYPE, feed_arg_types, TYPE_CONVERTERS |
25 | 25 |
|
26 | 26 | class Feed(object): |
27 | 27 | """ |
@@ -111,11 +111,18 @@ def _validate(self, key, val, arg_types): |
111 | 111 | Ensures that the key and the value are valid arguments to be used with |
112 | 112 | the feed. |
113 | 113 | """ |
114 | | - if key not in arg_types: |
115 | | - raise CloudantArgumentError(116, key) |
116 | | - if (not isinstance(val, arg_types[key]) or |
117 | | - (isinstance(val, bool) and int in arg_types[key])): |
118 | | - raise CloudantArgumentError(117, key, arg_types[key]) |
| 114 | + if key in arg_types: |
| 115 | + arg_type = arg_types[key] |
| 116 | + else: |
| 117 | + if ANY_ARG not in arg_types: |
| 118 | + raise CloudantArgumentError(116, key) |
| 119 | + arg_type = arg_types[ANY_ARG] |
| 120 | + |
| 121 | + if arg_type == ANY_TYPE: |
| 122 | + return |
| 123 | + if (not isinstance(val, arg_type) or |
| 124 | + (isinstance(val, bool) and int in arg_type)): |
| 125 | + raise CloudantArgumentError(117, key, arg_type) |
119 | 126 | if isinstance(val, int) and val < 0 and not isinstance(val, bool): |
120 | 127 | raise CloudantArgumentError(118, key, val) |
121 | 128 | if key == 'feed': |
|
0 commit comments