Fix Extension.register() API and related files

This commit is contained in:
Namhyeon Go 2024-07-06 22:52:53 +09:00
parent 96f77b956f
commit f953341330
7 changed files with 26 additions and 18 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@ certs/
savedfiles/ savedfiles/
settings.ini settings.ini
.env .env
*.pyc

14
base.py
View File

@ -3,16 +3,17 @@
# base.py # base.py
# base (common) file # base (common) file
# #
# Caterpillar Proxy - The simple and parasitic web proxy SPAM spam filter # Caterpillar Proxy - The simple web debugging proxy (formerly, php-httpproxy)
# Namyheon Go (Catswords Research) <gnh1201@gmail.com> # Namyheon Go (Catswords Research) <gnh1201@gmail.com>
# https://github.com/gnh1201/caterpillar # https://github.com/gnh1201/caterpillar
# Created at: 2024-05-20 # Created at: 2024-05-20
# Updated at: 2024-05-21 # Updated at: 2024-07-06
# #
import hashlib import hashlib
import json import json
import re import re
import importlib
client_encoding = 'utf-8' client_encoding = 'utf-8'
@ -71,8 +72,13 @@ class Extension():
cls.buffer_size = _buffer_size cls.buffer_size = _buffer_size
@classmethod @classmethod
def register(cls, f): def register(cls, module_path, class_name):
cls.extensions.append(f) try:
module = importlib.import_module(module_path)
_class = getattr(module, class_name)
cls.extensions.append(_class())
except (ImportError, AttributeError) as e:
raise ImportError(class_name + " in " + module_path)
@classmethod @classmethod
def get_filters(cls): def get_filters(cls):

View File

@ -7,12 +7,12 @@
# Namyheon Go (Catswords Research) <gnh1201@gmail.com> # Namyheon Go (Catswords Research) <gnh1201@gmail.com>
# https://github.com/gnh1201/caterpillar # https://github.com/gnh1201/caterpillar
# Created at: 2024-03-04 # Created at: 2024-03-04
# Updated at: 2024-03-13 # Updated at: 2024-07-06
# #
import docker import docker
from server import Extension from base import Extension
class Container(Extension): class Container(Extension):
def __init__(self): def __init__(self):

View File

@ -8,7 +8,7 @@
# https://github.com/gnh1201/caterpillar # https://github.com/gnh1201/caterpillar
# #
# Created in: 2022-10-06 # Created in: 2022-10-06
# Updated in: 2024-06-05 # Updated in: 2024-07-06
# #
import io import io
@ -19,7 +19,7 @@ import os.path
from decouple import config from decouple import config
from PIL import Image from PIL import Image
from server import Extension from base import Extension
try: try:
client_encoding = config('CLIENT_ENCODING', default='utf-8') client_encoding = config('CLIENT_ENCODING', default='utf-8')

View File

@ -7,12 +7,13 @@
# Namyheon Go (Catswords Research) <gnh1201@gmail.com> # Namyheon Go (Catswords Research) <gnh1201@gmail.com>
# https://github.com/gnh1201/caterpillar # https://github.com/gnh1201/caterpillar
# Created at: 2024-03-13 # Created at: 2024-03-13
# Updated at: 2024-03-13 # Updated at: 2024-07-06
# #
import requests import requests
from decouple import config
from server import Extension from base import Extension
try: try:
client_encoding = config('CLIENT_ENCODING') client_encoding = config('CLIENT_ENCODING')

View File

@ -23,7 +23,6 @@ import time
import hashlib import hashlib
import traceback import traceback
import textwrap import textwrap
import importlib
from datetime import datetime from datetime import datetime
from platform import python_version from platform import python_version
@ -499,9 +498,10 @@ def start(): #Main Program
if __name__== "__main__": if __name__== "__main__":
# load extensions # load extensions
#Extension.register(importlib.import_module("plugins.fediverse").Fediverse()) #Extension.register("plugins.fediverse", "Fediverse")
#Extension.register(importlib.import_module("plugins.container").Container()) #Extension.register("plugins.container", "Container")
#Extension.register(importlib.import_module("plugins.wayback").Wayback()) Extension.register("plugins.wayback", "Wayback")
#Extension.register("plugins.bio", "PyBio")
# start Caterpillar # start Caterpillar
start() start()

4
web.py
View File

@ -7,7 +7,7 @@
# Namyheon Go (Catswords Research) <gnh1201@gmail.com> # Namyheon Go (Catswords Research) <gnh1201@gmail.com>
# https://github.com/gnh1201/caterpillar # https://github.com/gnh1201/caterpillar
# Created at: 2024-05-20 # Created at: 2024-05-20
# Updated at: 2024-05-20 # Updated at: 2024-07-06
# #
from flask import Flask, request, redirect, url_for, render_template from flask import Flask, request, redirect, url_for, render_template
@ -94,6 +94,6 @@ if __name__ == "__main__":
Extension.set_protocol('http') Extension.set_protocol('http')
# load extensions # load extensions
#Extension.register(importlib.import_module("plugins.yourownplugin").YourOwnPlugin()) #Extension.register("plugins.YOUR_OWN_MODULE_NAME", "YOUR_OWN_CLASS_NAME");
app.run(debug=True, host='0.0.0.0', port=listening_port) app.run(debug=True, host='0.0.0.0', port=listening_port)