diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 333a608d..75a1127a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -6,7 +6,7 @@ jobs: unittest: strategy: matrix: - python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] runs-on: macos-13 name: Python ${{ matrix.python-version }} tests steps: @@ -27,7 +27,7 @@ jobs: unittest-arm64: strategy: matrix: - python-version: ["3.8.10", "3.9.13", "3.10.11", "3.11.9"] + python-version: ["3.8.10", "3.9.13", "3.10.11", "3.11.9", "3.12.7"] runs-on: macos-latest name: Python ${{ matrix.python-version }} tests steps: diff --git a/lyrebird/compatibility.py b/lyrebird/compatibility.py index 05bfafe3..99bb50a4 100644 --- a/lyrebird/compatibility.py +++ b/lyrebird/compatibility.py @@ -32,7 +32,7 @@ def decorator(func): ''' PYTHON_MIN_VERSION = (3, 8, 0) -PYTHON_MAX_VERSION = (3, 11, float('inf')) +PYTHON_MAX_VERSION = (3, 13, float('inf')) ''' diff --git a/lyrebird/event.py b/lyrebird/event.py index b03f4be3..191f6bae 100644 --- a/lyrebird/event.py +++ b/lyrebird/event.py @@ -5,7 +5,6 @@ Run events handler and background task worker """ import os -import imp import sys import copy import uuid @@ -71,7 +70,10 @@ def import_func_module(path): if pkg in sys.modules: continue sys.path.append(str(Path(path)/pkg)) - imp.load_package(pkg, Path(path)/pkg) + spec = importlib.util.spec_from_file_location(pkg, str(Path(path)/pkg/'__init__.py')) + module = importlib.util.module_from_spec(spec) + sys.modules[pkg] = module + spec.loader.exec_module(module) def import_func_from_file(filepath, func_name): diff --git a/lyrebird/mock/blueprints/core.py b/lyrebird/mock/blueprints/core.py index 81c9df71..cc2492be 100644 --- a/lyrebird/mock/blueprints/core.py +++ b/lyrebird/mock/blueprints/core.py @@ -52,13 +52,13 @@ def index(path=''): resp = Response( gen(), status=req_context.flow['response']['code'], - headers=req_context.flow['response']['headers'] + headers=req_context.get_response_headers() ) elif req_context.flow['response']: resp = Response( req_context.flow['response'].get('data', ''), status=req_context.flow['response'].get('code', 200), - headers=req_context.flow['response'].get('headers', {}) + headers=req_context.get_response_headers() ) else: path_not_found_handler.handle(req_context) diff --git a/lyrebird/mock/handlers/handler_context.py b/lyrebird/mock/handlers/handler_context.py index 2d871b50..d7b68c8c 100644 --- a/lyrebird/mock/handlers/handler_context.py +++ b/lyrebird/mock/handlers/handler_context.py @@ -19,6 +19,7 @@ logger = get_logger() proxy_handler = ProxyHandler() +lyrebird_response_headers = None class HandlerContext: @@ -221,7 +222,20 @@ def get_request_headers(self): continue headers[name] = value return headers - + + # Before response returns, remove the Lyrebird internal headers + def get_response_headers(self): + global lyrebird_response_headers + if not lyrebird_response_headers: + lyrebird_response_headers = application.config.get('proxy.response.delete_headers', []) + + headers = self.flow['response'].get('headers', {}) + lyrebird_response_headers = [] + for key in lyrebird_response_headers: + if key in headers: + del headers[key] + return headers + def get_request_cookies(self, in_request_handler=True): if in_request_handler: return self.request.cookies diff --git a/lyrebird/plugins/plugin_loader.py b/lyrebird/plugins/plugin_loader.py index df11fb57..c0431d10 100644 --- a/lyrebird/plugins/plugin_loader.py +++ b/lyrebird/plugins/plugin_loader.py @@ -1,5 +1,4 @@ import os -import imp import inspect import traceback from pathlib import Path @@ -7,6 +6,8 @@ import pkg_resources import setuptools +import importlib + from ..log import get_logger from .plugin import Plugin @@ -141,7 +142,12 @@ def load_from_path(plugin_path): sys.modules.pop(pkg) if pkg+'.manifest' in sys.modules: sys.modules.pop(pkg+'.manifest') - imp.load_package(pkg, Path(plugin_path)/pkg) + + spec = importlib.util.spec_from_file_location(pkg, str(Path(plugin_path)/pkg/'__init__.py')) + module = importlib.util.module_from_spec(spec) + sys.modules[pkg] = module + spec.loader.exec_module(module) + __import__(pkg+'.manifest') # There can only one manifest in each plugin diff --git a/lyrebird/version.py b/lyrebird/version.py index b1599561..b75092e9 100644 --- a/lyrebird/version.py +++ b/lyrebird/version.py @@ -1,3 +1,3 @@ -IVERSION = (3, 1, 2) +IVERSION = (3, 2, 0) VERSION = ".".join(str(i) for i in IVERSION) LYREBIRD = "Lyrebird " + VERSION diff --git a/requirements.txt b/requirements.txt index b3b2f073..293ad213 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,3 +14,5 @@ netifaces==0.11.0 jsonschema==4.17.0 Flask-Cors==4.0.0 redis==4.6.0 +setuptools +sortedcontainers diff --git a/requirements.txt.lock b/requirements.txt.lock index b0dc31f3..2f19f677 100644 --- a/requirements.txt.lock +++ b/requirements.txt.lock @@ -1,4 +1,25 @@ -aiohttp==3.8.3 +aiohttp==3.9; python_version > "3.11" +urllib3==1.26.20; python_version > "3.11" +Werkzeug==3.1.3; python_version > "3.11" +yarl==1.9.4; python_version > "3.11" +Flask==3.1.0; python_version > "3.11" +frozenlist==1.5; python_version > "3.11" +itsdangerous==2.2.0; python_version > "3.11" +multidict==6.1.0; python_version > "3.11" +Pillow==11.0.0; python_version > "3.11" +setuptools==75; python_version > "3.11" + +aiohttp==3.8.3; python_version <= "3.11" +urllib3==1.24.3; python_version <= "3.11" +Werkzeug==2.2.2; python_version <= "3.11" +yarl==1.8.1; python_version <= "3.11" +Flask==2.2.2; python_version <= "3.11" +frozenlist==1.3.1; python_version <= "3.11" +itsdangerous==2.1.2; python_version <= "3.11" +multidict==6.0.2; python_version <= "3.11" +Pillow==9.4.0; python_version <= "3.11" +setuptools==70; python_version <= "3.11" + aiosignal==1.2.0 aniso8601==9.0.1 async-timeout==4.0.2 @@ -11,21 +32,16 @@ chardet==3.0.4 charset-normalizer==2.1.1 click==8.1.3 colorama==0.4.1 -Flask==2.2.2 Flask-RESTful==0.3.9 Flask-SocketIO==5.3.0 Flask-Cors==4.0.0 -frozenlist==1.3.1 idna==2.8 importlib-metadata==5.0.0 -itsdangerous==2.1.2 Jinja2==3.1.2 jsonschema==4.17.0 MarkupSafe==2.1.1 -multidict==6.0.2 netifaces==0.11.0 packaging==19.0 -Pillow==9.4.0 portpicker==1.3.1 pycodestyle==2.9.1 pyparsing==3.0.9 @@ -39,8 +55,5 @@ six==1.16.0 soupsieve==2.3.2.post1 SQLAlchemy==1.3.22 toml==0.10.2 -urllib3==1.24.3 -Werkzeug==2.2.2 -yarl==1.8.1 zipp==3.10.0 redis==4.6.0 diff --git a/setup.py b/setup.py index 2247e084..e957d9ed 100644 --- a/setup.py +++ b/setup.py @@ -31,11 +31,12 @@ def read_requirements(name): zip_safe=False, classifiers=[ "Programming Language :: Python :: 3 :: Only", - "Programming Language :: Python :: 3.7", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", "License :: OSI Approved :: MIT License", "Operating System :: MacOS", "Operating System :: Microsoft :: Windows",