privatefunc 1.6.23

Creator: railscoder56

Last updated:

Add to Cart

Description:

privatefunc 1.6.23

Private Function in Python
"A smarter way to create private functions in python"
from FAHEEM41


version: 1.5.23
first published in: Sololearn
Github first publishing date: 23rd July, 2022
Last Updated: 11th January, 2023




Why use the code?
Let's start with the concept of private functions. Private functions are functions that are only accessible inside the declared module, no other function from any other module can access it.
This project mainly focuses on the security issues of a code. This enables a way to restrict code from accessing other functions from other modules that were not meant to be accessed. And thus, it ensures that only non-private functions i.e. public functions can be accessed from anywhere outside the code.
Here's an example, suppose a module has two functions: add() and main(). main() function is meant to run and can be called from other modules. On the other hand, the add() function is a function that is only called by the main() function, and we want to keep this function private, i.e. ensure that it cannot be accessed or called from any other module.



Understanding the code
Here we have implemented a very naive idea to get our work done. We have used a decorator which will check whether the function is a private or public function and thereby deny or grant access respectively. The decorator will run, as usual, with the function called, and before the function ran.
For details understanding, have a look at the privatefunc.py file; the documentation of the code, along with how the code is working is given inside the source code.



How to use the code? (using pip)
In terminal type the command: pip install privatefunc
Add this lines in your module: from privatefunc import PrivateFuncprivate = PrivateFunc("nameOfThisModuleHere").private
Now add @private before the function you want to make private
For better understanding have a look at moduleWithPrivateFunc.py


Everything put together:
# example.py
from privatefunc import PrivateFunc
private = PrivateFunc("example").private

@private
def hello():
pass


Sample Code
Go through the demo code to completely understand the insights of the source.


© 2021-2023 Md. Faheem Hossain fmhossain2941@gmail.com

License

For personal and professional use. You cannot resell or redistribute these repositories in their original state.

Customer Reviews

There are no reviews.