From 02a117f336e198a26eb423e9f11f14155daca70a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Tue, 7 Apr 2020 14:03:58 -0600 Subject: [PATCH] Avoid using typing annotations so tests run with Python 3.4. --- plugins/python/example_approval_plugin.py | 5 ++--- plugins/python/example_audit_plugin.py | 3 +-- plugins/python/example_group_plugin.py | 4 +--- plugins/python/example_io_plugin.py | 17 +++++++---------- plugins/python/example_policy_plugin.py | 16 +++++++--------- ...io_plugin_fails_with_python_backtrace.stdout | 4 ++-- 6 files changed, 20 insertions(+), 29 deletions(-) diff --git a/plugins/python/example_approval_plugin.py b/plugins/python/example_approval_plugin.py index bc7deb04a..56ac8656a 100644 --- a/plugins/python/example_approval_plugin.py +++ b/plugins/python/example_approval_plugin.py @@ -1,12 +1,11 @@ import sudo from datetime import datetime -from typing import Tuple class BusinessHoursApprovalPlugin(sudo.Plugin): - def check(self, command_info: Tuple[str, ...], run_argv: Tuple[str, ...], - run_env: Tuple[str, ...]) -> int: + def check(self, command_info: tuple, run_argv: tuple, + run_env: tuple) -> int: error_msg = "" now = datetime.now() if now.weekday() >= 5: diff --git a/plugins/python/example_audit_plugin.py b/plugins/python/example_audit_plugin.py index 081446545..d582e28b2 100644 --- a/plugins/python/example_audit_plugin.py +++ b/plugins/python/example_audit_plugin.py @@ -1,7 +1,6 @@ import sudo import os -from typing import Tuple VERSION = 1.0 @@ -22,7 +21,7 @@ class SudoAuditPlugin(sudo.Plugin): def __del__(self): self._log("-- Finished --") - def open(self, submit_optind: int, submit_argv: Tuple[str, ...]) -> int: + def open(self, submit_optind: int, submit_argv: tuple) -> int: # To cut out the sudo options, use "submit_optind": program_args = submit_argv[submit_optind:] if program_args: diff --git a/plugins/python/example_group_plugin.py b/plugins/python/example_group_plugin.py index 4e2315663..bb53fdb1b 100644 --- a/plugins/python/example_group_plugin.py +++ b/plugins/python/example_group_plugin.py @@ -1,7 +1,5 @@ import sudo -from typing import Tuple - class SudoGroupPlugin(sudo.Plugin): """Example sudo input/output plugin @@ -32,7 +30,7 @@ class SudoGroupPlugin(sudo.Plugin): """ # -- Plugin API functions -- - def query(self, user: str, group: str, user_pwd: Tuple): + def query(self, user: str, group: str, user_pwd: tuple): """Query if user is part of the specified group. Beware that user_pwd can be None if user is not present in the password diff --git a/plugins/python/example_io_plugin.py b/plugins/python/example_io_plugin.py index f3b21de62..6cb644b73 100644 --- a/plugins/python/example_io_plugin.py +++ b/plugins/python/example_io_plugin.py @@ -5,7 +5,6 @@ import errno import signal import sys import json -from typing import Tuple VERSION = 1.0 @@ -15,9 +14,7 @@ class SudoIOPlugin(sudo.Plugin): """Example sudo input/output plugin Demonstrates how to use the sudo IO plugin API. All functions are added as - an example on their syntax, but note that all of them are optional. Also - typing annotations are just here for the help on the syntax (requires - python >= 3.5). + an example on their syntax, but note that all of them are optional. On detailed description of the functions refer to sudo_plugin manual (man sudo_plugin). @@ -44,13 +41,13 @@ class SudoIOPlugin(sudo.Plugin): # -- Plugin API functions -- def __init__(self, version: str, - plugin_options: Tuple[str, ...], **kwargs): + plugin_options: tuple, **kwargs): """The constructor of the IO plugin. Other variables you can currently use as arguments are: - user_env: Tuple[str, ...] - settings: Tuple[str, ...] - user_info: Tuple[str, ...] + user_env: tuple + settings: tuple + user_info: tuple For their detailed description, see the open() call of the C plugin API in the sudo manual ("man sudo"). @@ -72,8 +69,8 @@ class SudoIOPlugin(sudo.Plugin): self._log("", "-- Plugin DESTROYED --") self._log_file.close() - def open(self, argv: Tuple[str, ...], - command_info: Tuple[str, ...]) -> int: + def open(self, argv: tuple, + command_info: tuple) -> int: """Receives the command the user wishes to run. This function works the same as open() call of the C IO plugin API (see diff --git a/plugins/python/example_policy_plugin.py b/plugins/python/example_policy_plugin.py index d7a62f81e..dfb15ca44 100644 --- a/plugins/python/example_policy_plugin.py +++ b/plugins/python/example_policy_plugin.py @@ -6,7 +6,6 @@ import os import pwd import grp import shutil -from typing import Tuple VERSION = 1.0 @@ -17,8 +16,7 @@ class SudoPolicyPlugin(sudo.Plugin): Demonstrates how to use the sudo policy plugin API. All functions are added as an example on their syntax, but note that most of them are optional - (except check_policy). Also typing annotations are just here for the help - on the syntax (requires python >= 3.5). + (except check_policy). On detailed description of the functions refer to sudo_plugin manual (man sudo_plugin). @@ -47,13 +45,13 @@ class SudoPolicyPlugin(sudo.Plugin): # -- Plugin API functions -- - def __init__(self, user_env: Tuple[str, ...], settings: Tuple[str, ...], + def __init__(self, user_env: tuple, settings: tuple, version: str, **kwargs): """The constructor matches the C sudo plugin API open() call Other variables you can currently use as arguments are: - user_info: Tuple[str, ...] - plugin_options: Tuple[str, ...] + user_info: tuple + plugin_options: tuple For their detailed description, see the open() call of the C plugin API in the sudo manual ("man sudo"). @@ -66,7 +64,7 @@ class SudoPolicyPlugin(sudo.Plugin): self.user_env = sudo.options_as_dict(user_env) self.settings = sudo.options_as_dict(settings) - def check_policy(self, argv: Tuple[str, ...], env_add: Tuple[str, ...]): + def check_policy(self, argv: tuple, env_add: tuple): cmd = argv[0] # Example for a simple reject: if not self._is_command_allowed(cmd): @@ -86,7 +84,7 @@ class SudoPolicyPlugin(sudo.Plugin): return (sudo.RC.ACCEPT, command_info_out, argv, user_env_out) - def init_session(self, user_pwd: Tuple, user_env: Tuple[str, ...]): + def init_session(self, user_pwd: tuple, user_env: tuple): """Perform session setup Beware that user_pwd can be None if user is not present in the password @@ -101,7 +99,7 @@ class SudoPolicyPlugin(sudo.Plugin): # If you do not want to change user_env, you can just return (or None): # return sudo.RC.OK - def list(self, argv: Tuple[str, ...], is_verbose: int, user: str): + def list(self, argv: tuple, is_verbose: int, user: str): cmd = argv[0] if argv else None as_user_text = "as user '{}'".format(user) if user else "" diff --git a/plugins/python/regress/testdata/check_example_io_plugin_fails_with_python_backtrace.stdout b/plugins/python/regress/testdata/check_example_io_plugin_fails_with_python_backtrace.stdout index 66cf33035..eb938f069 100644 --- a/plugins/python/regress/testdata/check_example_io_plugin_fails_with_python_backtrace.stdout +++ b/plugins/python/regress/testdata/check_example_io_plugin_fails_with_python_backtrace.stdout @@ -1,7 +1,7 @@ Example sudo python plugin will log to /some/not/writable/directory/sudo.log Traceback: - File "SRC_DIR/example_io_plugin.py", line 67, in __init__ + File "SRC_DIR/example_io_plugin.py", line 64, in __init__ self._open_log_file(path.join(log_path, "sudo.log")) - File "SRC_DIR/example_io_plugin.py", line 140, in _open_log_file + File "SRC_DIR/example_io_plugin.py", line 137, in _open_log_file self._log_file = open(log_path, "a")