Answer the question
In order to leave comments, you need to log in
How to restrict access to a Python module?
The essence of the task: restrict access to modules if the domain is not in the list that these modules are available to.
How to implement?
so far the ideas are:
- (not suitable) a decorator that restricts access to each module function
- import the module with a check if the check fails - block further module execution (I don’t know how to do it and is it even possible)
- something based on hooks( link ), but have not yet figured out how it works
How to do it?
Answer the question
In order to leave comments, you need to log in
The dictionary list of connected modules in python is always stored in sys.modules
At runtime (at startup) it will always show you which modules are connected...
to limit them you can just do this
sys.modules['mymodule'] = none
try:
__import__('mymodule')
except ImportError :
sys.exit("Module disabled")
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question