From fa3ce885d02a201505f63053748f89b7e653df67 Mon Sep 17 00:00:00 2001 From: Preeti Arora Date: Wed, 16 Jun 2021 12:13:26 +0000 Subject: [PATCH 1/2] Update minor version for Release --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index c3545b6..e8a910e 100644 --- a/setup.py +++ b/setup.py @@ -68,7 +68,7 @@ def read_requirements(req="base.txt"): setup( name="awslambdaric", - version="1.1.1", + version="1.2.1", author="Amazon Web Services", description="AWS Lambda Runtime Interface Client for Python", long_description=read("README.md"), From 484d932cdbbb98097e51e3eb2b3fabf96efeebb7 Mon Sep 17 00:00:00 2001 From: Preeti Arora Date: Fri, 25 Jun 2021 13:53:01 +0000 Subject: [PATCH 2/2] Add support for / in handler name --- awslambdaric/bootstrap.py | 1 + tests/test_bootstrap.py | 18 ++++++++++++++++++ tests/test_built_in_module_name/sys.py | 2 ++ tests/test_handler_with_slash/test_handler.py | 2 ++ 4 files changed, 23 insertions(+) create mode 100644 tests/test_built_in_module_name/sys.py create mode 100644 tests/test_handler_with_slash/test_handler.py diff --git a/awslambdaric/bootstrap.py b/awslambdaric/bootstrap.py index a43078e..73f2679 100644 --- a/awslambdaric/bootstrap.py +++ b/awslambdaric/bootstrap.py @@ -36,6 +36,7 @@ def _get_handler(handler): "Cannot use built-in module {} as a handler module".format(modname), ) return make_fault_handler(fault) + modname = modname.replace("/", ".") m = importlib.import_module(modname) except ImportError as e: fault = FaultException( diff --git a/tests/test_bootstrap.py b/tests/test_bootstrap.py index 15ed6f7..b6f4b23 100644 --- a/tests/test_bootstrap.py +++ b/tests/test_bootstrap.py @@ -780,6 +780,12 @@ def test_get_event_handler_missing_error(self): returned_exception, ) + def test_get_event_handler_slash(self): + importlib.invalidate_caches() + handler_name = "tests/test_handler_with_slash/test_handler.my_handler" + response_handler = bootstrap._get_handler(handler_name) + response_handler() + def test_get_event_handler_build_in_conflict(self): response_handler = bootstrap._get_handler("sys.hello") with self.assertRaises(FaultException) as cm: @@ -793,6 +799,18 @@ def test_get_event_handler_build_in_conflict(self): returned_exception, ) + def test_get_event_handler_doesnt_throw_build_in_module_name_slash(self): + response_handler = bootstrap._get_handler( + "tests/test_built_in_module_name/sys.my_handler" + ) + response_handler() + + def test_get_event_handler_doent_throw_build_in_module_name(self): + response_handler = bootstrap._get_handler( + "tests.test_built_in_module_name.sys.my_handler" + ) + response_handler() + class TestContentType(unittest.TestCase): def setUp(self): diff --git a/tests/test_built_in_module_name/sys.py b/tests/test_built_in_module_name/sys.py new file mode 100644 index 0000000..3008676 --- /dev/null +++ b/tests/test_built_in_module_name/sys.py @@ -0,0 +1,2 @@ +def my_handler(): + return "Same name as Built in module, but different path" diff --git a/tests/test_handler_with_slash/test_handler.py b/tests/test_handler_with_slash/test_handler.py new file mode 100644 index 0000000..45a5035 --- /dev/null +++ b/tests/test_handler_with_slash/test_handler.py @@ -0,0 +1,2 @@ +def my_handler(): + return "Good with slash"