Skip to content

Commit

Permalink
Lazy-load parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
adeptex committed Oct 5, 2024
1 parent 1a63b87 commit d8c47a1
Showing 1 changed file with 34 additions and 16 deletions.
50 changes: 34 additions & 16 deletions whispers/core/pairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,6 @@
from whispers.core.utils import global_exception_handler, is_static, strip_string
from whispers.models.appconfig import AppConfig
from whispers.models.pair import KeyValuePair
from whispers.plugins.config import Config
from whispers.plugins.dockercfg import Dockercfg
from whispers.plugins.dockerfile import Dockerfile
from whispers.plugins.elixir import Elixir
from whispers.plugins.gradle import Gradle
from whispers.plugins.html import Html
from whispers.plugins.htpasswd import Htpasswd
from whispers.plugins.jproperties import Jproperties
from whispers.plugins.json import Json
from whispers.plugins.npmrc import Npmrc
from whispers.plugins.pip import Pip
from whispers.plugins.plaintext import Plaintext
from whispers.plugins.pypirc import Pypirc
from whispers.plugins.shell import Shell
from whispers.plugins.xml import Xml
from whispers.plugins.yml import Yml


def make_pairs(config: AppConfig, file: Path) -> Optional[Iterator[KeyValuePair]]:
Expand Down Expand Up @@ -115,54 +99,88 @@ def load_plugin(file: Path, ast: bool = False) -> Optional[object]:
filetype = file_name.split(".")[-1]

if filetype in ["yaml", "yml"]:
from whispers.plugins.yml import Yml

return Yml

elif filetype == "json":
from whispers.plugins.json import Json

return Json

elif filetype == "xml":
from whispers.plugins.xml import Xml

return Xml

elif filetype.startswith("npmrc"):
from whispers.plugins.npmrc import Npmrc

return Npmrc

elif filetype.startswith("pypirc"):
from whispers.plugins.pypirc import Pypirc

return Pypirc

elif file_name == "pip.conf":
from whispers.plugins.pip import Pip

return Pip

elif file_name == "build.gradle":
from whispers.plugins.gradle import Gradle

return Gradle

elif filetype in ["conf", "cfg", "cnf", "config", "ini", "credentials", "s3cfg"]:
from whispers.plugins.config import Config

return Config

elif filetype == "properties":
from whispers.plugins.jproperties import Jproperties

return Jproperties

elif filetype.startswith(("sh", "bash", "zsh", "env")) or file_name == "environment":
from whispers.plugins.shell import Shell

return Shell

elif "dockerfile" in file_name:
from whispers.plugins.dockerfile import Dockerfile

return Dockerfile

elif filetype == "dockercfg":
from whispers.plugins.dockercfg import Dockercfg

return Dockercfg

elif filetype.startswith("htpasswd"):
from whispers.plugins.htpasswd import Htpasswd

return Htpasswd

elif filetype == "txt":
from whispers.plugins.plaintext import Plaintext

return Plaintext

elif filetype.startswith("htm"):
from whispers.plugins.html import Html

return Html

elif filetype == "exs":
from whispers.plugins.elixir import Elixir

return Elixir

elif REGEX_PRIVKEY_FILE.match(filetype):
from whispers.plugins.plaintext import Plaintext

return Plaintext

elif ast and REGEX_AST_FILE.match(filetype):
Expand Down

0 comments on commit d8c47a1

Please sign in to comment.