Use check_list instead of json_to_list.

(imported from commit 9ead12bc2a4744b94a747ca27054124aacde7ae4)
This commit is contained in:
Steve Howell 2014-02-14 10:25:31 -05:00
parent 8b58d8574b
commit 3d04f5f738
3 changed files with 11 additions and 10 deletions

View File

@ -49,6 +49,7 @@ def check_list(sub_validator, length=None):
if length is not None and length != len(val): if length is not None and length != len(val):
return '%s should have exactly %d items' % (var_name, length) return '%s should have exactly %d items' % (var_name, length)
if sub_validator:
for i, item in enumerate(val): for i, item in enumerate(val):
vname = '%s[%d]' % (var_name, i) vname = '%s[%d]' % (var_name, i)
error = sub_validator(vname, item) error = sub_validator(vname, item)

View File

@ -5,10 +5,10 @@ from zerver.models import get_client
from zerver.decorator import asynchronous, \ from zerver.decorator import asynchronous, \
authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \ authenticated_json_post_view, internal_notify_view, RespondAsynchronously, \
has_request_variables, json_to_list, json_to_dict, REQ has_request_variables, json_to_dict, REQ
from zerver.lib.response import json_success, json_error from zerver.lib.response import json_success, json_error
from zerver.lib.validator import check_bool from zerver.lib.validator import check_bool, check_list, check_string
from zerver.tornado_callbacks import process_notification from zerver.tornado_callbacks import process_notification
from zerver.lib.event_queue import allocate_client_descriptor, get_client_descriptor from zerver.lib.event_queue import allocate_client_descriptor, get_client_descriptor
@ -48,9 +48,9 @@ def get_events_backend(request, user_profile, handler = None,
queue_id = REQ(default=None), queue_id = REQ(default=None),
apply_markdown = REQ(default=False, validator=check_bool), apply_markdown = REQ(default=False, validator=check_bool),
all_public_streams = REQ(default=False, validator=check_bool), all_public_streams = REQ(default=False, validator=check_bool),
event_types = REQ(default=None, converter=json_to_list), event_types = REQ(default=None, validator=check_list(check_string)),
dont_block = REQ(default=False, validator=check_bool), dont_block = REQ(default=False, validator=check_bool),
narrow = REQ(default=[], converter=json_to_list), narrow = REQ(default=[], validator=check_list(None)),
lifespan_secs = REQ(default=0, converter=int)): lifespan_secs = REQ(default=0, converter=int)):
if user_client is None: if user_client is None:
user_client = request.client user_client = request.client

View File

@ -55,7 +55,7 @@ from zerver.lib.validator import check_string, check_list, check_dict, check_int
from zerver.decorator import require_post, \ from zerver.decorator import require_post, \
authenticated_api_view, authenticated_json_post_view, \ authenticated_api_view, authenticated_json_post_view, \
has_request_variables, authenticated_json_view, \ has_request_variables, authenticated_json_view, \
to_non_negative_int, json_to_dict, json_to_list, json_to_bool, \ to_non_negative_int, json_to_dict, json_to_bool, \
JsonableError, get_user_profile_by_email, REQ, require_realm_admin, \ JsonableError, get_user_profile_by_email, REQ, require_realm_admin, \
RequestVariableConversionError RequestVariableConversionError
from zerver.lib.avatar import avatar_url, get_avatar_url from zerver.lib.avatar import avatar_url, get_avatar_url