From 960144a49e66bd330daecdf3423e3a53c8353352 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 31 May 2016 07:29:39 -0700 Subject: [PATCH] Desupport using uninstantiated REQ with has_request_variables. This makes life difficult for doing static type annotations, and didn't make the code look that much better anyway. --- zerver/decorator.py | 4 ++-- zerver/lib/request.py | 7 ------- zerver/views/__init__.py | 16 ++++++++-------- zerver/views/messages.py | 2 +- zerver/views/report.py | 6 +++--- zerver/views/streams.py | 12 ++++++------ zerver/views/user_settings.py | 2 +- zerver/views/users.py | 6 +++--- zerver/views/webhooks/github.py | 2 +- zilencer/views.py | 2 +- 10 files changed, 26 insertions(+), 33 deletions(-) diff --git a/zerver/decorator.py b/zerver/decorator.py index 840ad82956..efbbe4b412 100644 --- a/zerver/decorator.py +++ b/zerver/decorator.py @@ -170,7 +170,7 @@ def api_key_only_webhook_view(client_name): @csrf_exempt @has_request_variables @wraps(view_func) - def _wrapped_func_arguments(request, api_key=REQ, + def _wrapped_func_arguments(request, api_key=REQ(), *args, **kwargs): try: @@ -280,7 +280,7 @@ def authenticated_api_view(view_func): @require_post @has_request_variables @wraps(view_func) - def _wrapped_view_func(request, email=REQ, api_key=REQ('api_key', default=None), + def _wrapped_view_func(request, email=REQ(), api_key=REQ('api_key', default=None), api_key_legacy=REQ('api-key', default=None), *args, **kwargs): if not api_key and not api_key_legacy: diff --git a/zerver/lib/request.py b/zerver/lib/request.py index edea9c06b4..cbccd03e17 100644 --- a/zerver/lib/request.py +++ b/zerver/lib/request.py @@ -106,13 +106,6 @@ def has_request_variables(view_func): if value.post_var_name is None: value.post_var_name = name post_params.append(value) - elif value == REQ: - # If the function definition does not actually instantiate - # a REQ object but instead uses the REQ class itself as a - # value, we instantiate it as a convenience - post_var = value(name) - post_var.func_var_name = name - post_params.append(post_var) @wraps(view_func) def _wrapped_view_func(request, *args, **kwargs): diff --git a/zerver/views/__init__.py b/zerver/views/__init__.py index 61988ecd2c..6babfec865 100644 --- a/zerver/views/__init__.py +++ b/zerver/views/__init__.py @@ -322,7 +322,7 @@ def api_endpoint_docs(request): @authenticated_json_post_view @has_request_variables -def json_invite_users(request, user_profile, invitee_emails=REQ): +def json_invite_users(request, user_profile, invitee_emails=REQ()): if not invitee_emails: return json_error("You must specify at least one email address.") @@ -1079,7 +1079,7 @@ def get_uploaded_file(request, realm_id, filename, @csrf_exempt @require_post @has_request_variables -def api_fetch_api_key(request, username=REQ, password=REQ): +def api_fetch_api_key(request, username=REQ(), password=REQ()): # type: (Any, Any, Any) -> Any return_data = {} # type: Dict[str, bool] if username == "google-oauth2-token": @@ -1117,7 +1117,7 @@ def get_status_list(requesting_user_profile): 'server_timestamp': time.time()} @has_request_variables -def update_active_status_backend(request, user_profile, status=REQ, +def update_active_status_backend(request, user_profile, status=REQ(), new_user_input=REQ(validator=check_bool, default=False)): status_val = UserPresence.status_from_string(status) if status_val is None: @@ -1184,7 +1184,7 @@ def events_register_backend(request, user_profile, apply_markdown=True, @authenticated_json_post_view @has_request_variables -def json_refer_friend(request, user_profile, email=REQ): +def json_refer_friend(request, user_profile, email=REQ()): if not email: return json_error("No email address specified") if user_profile.invites_granted - user_profile.invites_used <= 0: @@ -1221,11 +1221,11 @@ def add_push_device_token(request, user_profile, token, kind, ios_app_id=None): return json_success() @has_request_variables -def add_apns_device_token(request, user_profile, token=REQ, appid=REQ(default=settings.ZULIP_IOS_APP_ID)): +def add_apns_device_token(request, user_profile, token=REQ(), appid=REQ(default=settings.ZULIP_IOS_APP_ID)): return add_push_device_token(request, user_profile, token, PushDeviceToken.APNS, ios_app_id=appid) @has_request_variables -def add_android_reg_id(request, user_profile, token=REQ): +def add_android_reg_id(request, user_profile, token=REQ()): return add_push_device_token(request, user_profile, token, PushDeviceToken.GCM) def remove_push_device_token(request, user_profile, token, kind): @@ -1241,11 +1241,11 @@ def remove_push_device_token(request, user_profile, token, kind): return json_success() @has_request_variables -def remove_apns_device_token(request, user_profile, token=REQ): +def remove_apns_device_token(request, user_profile, token=REQ()): return remove_push_device_token(request, user_profile, token, PushDeviceToken.APNS) @has_request_variables -def remove_android_reg_id(request, user_profile, token=REQ): +def remove_android_reg_id(request, user_profile, token=REQ()): return remove_push_device_token(request, user_profile, token, PushDeviceToken.GCM) diff --git a/zerver/views/messages.py b/zerver/views/messages.py index faf13dbf5e..79fe0c8d77 100644 --- a/zerver/views/messages.py +++ b/zerver/views/messages.py @@ -809,7 +809,7 @@ def json_fetch_raw_message(request, user_profile, return json_success({"raw_content": message.content}) @has_request_variables -def render_message_backend(request, user_profile, content=REQ): +def render_message_backend(request, user_profile, content=REQ()): rendered_content = bugdown.convert(content, user_profile.realm.domain) return json_success({"rendered": rendered_content}) diff --git a/zerver/views/report.py b/zerver/views/report.py index 1e456d8e65..4d4ca28b1e 100644 --- a/zerver/views/report.py +++ b/zerver/views/report.py @@ -68,9 +68,9 @@ def json_report_unnarrow_time(request, user_profile, @authenticated_json_post_view @has_request_variables -def json_report_error(request, user_profile, message=REQ, stacktrace=REQ, - ui_message=REQ(validator=check_bool), user_agent=REQ, - href=REQ, log=REQ, +def json_report_error(request, user_profile, message=REQ(), stacktrace=REQ(), + ui_message=REQ(validator=check_bool), user_agent=REQ(), + href=REQ(), log=REQ(), more_info=REQ(validator=check_dict([]), default=None)): if not settings.ERROR_REPORTING: diff --git a/zerver/views/streams.py b/zerver/views/streams.py index 84bcc46fb8..6b873ca15c 100644 --- a/zerver/views/streams.py +++ b/zerver/views/streams.py @@ -125,34 +125,34 @@ def deactivate_stream_backend(request, user_profile, stream_name): @require_realm_admin @has_request_variables -def add_default_stream(request, user_profile, stream_name=REQ): +def add_default_stream(request, user_profile, stream_name=REQ()): do_add_default_stream(user_profile.realm, stream_name) return json_success() @require_realm_admin @has_request_variables -def remove_default_stream(request, user_profile, stream_name=REQ): +def remove_default_stream(request, user_profile, stream_name=REQ()): do_remove_default_stream(user_profile.realm, stream_name) return json_success() @authenticated_json_post_view @require_realm_admin @has_request_variables -def json_rename_stream(request, user_profile, old_name=REQ, new_name=REQ): +def json_rename_stream(request, user_profile, old_name=REQ(), new_name=REQ()): do_rename_stream(user_profile.realm, old_name, new_name) return json_success() @authenticated_json_post_view @require_realm_admin @has_request_variables -def json_make_stream_public(request, user_profile, stream_name=REQ): +def json_make_stream_public(request, user_profile, stream_name=REQ()): do_make_stream_public(user_profile, user_profile.realm, stream_name) return json_success() @authenticated_json_post_view @require_realm_admin @has_request_variables -def json_make_stream_private(request, user_profile, stream_name=REQ): +def json_make_stream_private(request, user_profile, stream_name=REQ()): do_make_stream_private(user_profile.realm, stream_name) return json_success() @@ -404,7 +404,7 @@ def get_streams_backend(request, user_profile, @authenticated_json_post_view @has_request_variables -def json_stream_exists(request, user_profile, stream=REQ, +def json_stream_exists(request, user_profile, stream=REQ(), autosubscribe=REQ(default=False)): return stream_exists_backend(request, user_profile, stream, autosubscribe) diff --git a/zerver/views/user_settings.py b/zerver/views/user_settings.py index 092eeb9268..29e32d1608 100644 --- a/zerver/views/user_settings.py +++ b/zerver/views/user_settings.py @@ -50,7 +50,7 @@ def json_change_ui_settings(request, user_profile, @authenticated_json_post_view @has_request_variables def json_change_settings(request, user_profile, - full_name=REQ, + full_name=REQ(), old_password=REQ(default=""), new_password=REQ(default=""), confirm_password=REQ(default="")): diff --git a/zerver/views/users.py b/zerver/views/users.py index 034ad06736..daed9d75bc 100644 --- a/zerver/views/users.py +++ b/zerver/views/users.py @@ -164,7 +164,7 @@ def regenerate_bot_api_key(request, user_profile, email): return json_success(json_result) @has_request_variables -def add_bot_backend(request, user_profile, full_name=REQ, short_name=REQ, +def add_bot_backend(request, user_profile, full_name=REQ(), short_name=REQ(), default_sending_stream=REQ(default=None), default_events_register_stream=REQ(default=None), default_all_public_streams=REQ(validator=check_bool, default=None)): @@ -266,8 +266,8 @@ def get_members_backend(request, user_profile): @require_realm_admin @has_request_variables -def create_user_backend(request, user_profile, email=REQ, password=REQ, - full_name=REQ, short_name=REQ): +def create_user_backend(request, user_profile, email=REQ(), password=REQ(), + full_name=REQ(), short_name=REQ()): form = CreateUserForm({'full_name': full_name, 'email': email}) if not form.is_valid(): return json_error('Bad name or username') diff --git a/zerver/views/webhooks/github.py b/zerver/views/webhooks/github.py index 7b2cef058b..a9427f10ca 100644 --- a/zerver/views/webhooks/github.py +++ b/zerver/views/webhooks/github.py @@ -124,7 +124,7 @@ def api_github_v2(user_profile, event, payload, branches, default_stream, commit @authenticated_api_view @has_request_variables -def api_github_landing(request, user_profile, event=REQ, +def api_github_landing(request, user_profile, event=REQ(), payload=REQ(validator=check_dict([])), branches=REQ(default=''), stream=REQ(default=''), diff --git a/zilencer/views.py b/zilencer/views.py index f28efa295d..1fef034c22 100644 --- a/zilencer/views.py +++ b/zilencer/views.py @@ -76,7 +76,7 @@ def submit_feedback(request, deployment, message=REQ(validator=check_dict([]))): return HttpResponse(message['sender_email']) @has_request_variables -def report_error(request, deployment, type=REQ, report=REQ(validator=check_dict([]))): +def report_error(request, deployment, type=REQ(), report=REQ(validator=check_dict([]))): report['deployment'] = deployment.name if type == 'browser': notify_browser_error(report)