Name | deny-me JSON |
Version |
1.1
JSON |
| download |
home_page | None |
Summary | A python library for function decorators to restrict access to functions and much more |
upload_time | 2024-07-12 12:19:29 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.12 |
license | MIT License Copyright (c) 2024 Soumyo Deep Gupta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
keywords |
d33pster
deny-me
deny
me
decorators
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
[![Implementation Test](https://github.com/d33pster/deny-me/actions/workflows/Tests.yml/badge.svg)](https://github.com/d33pster/deny-me/actions/workflows/Tests.yml)
[![CD](https://github.com/d33pster/deny-me/actions/workflows/Deploy.yml/badge.svg)](https://github.com/d33pster/deny-me/actions/workflows/Deploy.yml)
# Overview
You must have often wondered about how to make a function restricted to the user so that it could only be called a specific number of time, or even a function that is password protected.
This library provides an array of function decorators that can be used for the same.
## Table of Contents
- [Features](#features)
- [Installation](#installation)
- [Usage](#usage)
## Features
- Easily restrict any function according to your needs.
- improve overall acessibility of your program.
## Installation
> Install using pip.
```sh
pip install deny-me
```
## Usage
- **Once/Twice**
To make your function run only once.
> import the decorators.
```python
from deny_me.restrict import once, twice
```
> use acording to your needs.
```python
# demo function
# This function will be callable only once.
# Repeated calling will generate error.
class some_class:
def __init__(self):
...
@once
def function1(self, name: str, school: str = "ABC"):
print(f"{name} goes to {school}!")
...
# demo funtion 2
# This function will be callable two times.
# will generate error if called more than twice
@twice
def function2(self, *args, **kwargs):
...
```
> **Note to the users.**
If other decorators are used for a function other than these, then it is recommended to use these decorators at the last.
`For example:`
```python
# demo class
class Demo:
def __init__(self):
...
# suppose you need to define a property
# that is only callable once.
@property
# use property first
@once
# and then use once
def property1(self):
return ...
# similarly if you want to define a setter
# for the property.
@property1.setter # use this
# and then the once decorator
@once
def property1(self, value: str):
self.value = value
...
```
- **Run custom times**
To run a function n times.
> import the Allow class.
```python
from deny_me.restrict import Allow
```
> run n=10 times
```python
# demo function
# this function will run 10 times
class Demo:
def __init__(Self):
...
@Allow(10).times
def function(self, *args, **kwargs):
...
```
> Note: Similar to the Once/Twice decorators, If other decorators are needed, such as `property`, then it should be at the top and the `Allow(n).times` should be the last decorator.
- **Password Protection**
To make your function password protected.
> import the Password class.
```python
from deny_me.password import Password
```
> Use the password decorator.
```python
# demo function
# this function will be password protected.
class some_class:
def __init__(self):
...
@Password("pass123").protected
def function(*args, **kwargs):
...
# It is recommended that the above function has `*args`
# and `**kwargs` in its parameters.
# If some parameters are mandatory, they can be defined before
# mentioning `*args` and `**kwargs`.
## FOR EXAMPLE:
@Password("pass123").protected
def function(name: str, school: str = "ABC", *args, **kwargs):
...
```
> **How to call the function?**
```python
# To call the function, just add `password=` parameter
# while calling.
c = some_class()
c.function(name="hehe", password="pass123")
# This will run fine as the password is correct!
# However, if the password is wrong, it will
# prompt about the same.
# NOTE: if the `password=` parameter is missing while calling
# the function then it will raise an error stating that
# an exclusive feature has been called that is not made
# available to the users.
```
Raw data
{
"_id": null,
"home_page": null,
"name": "deny-me",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": "Soumyo Deep Gupta <deep.main.ac@gmail.com>",
"keywords": "d33pster, deny-me, deny, me, decorators",
"author": null,
"author_email": "Soumyo Deep Gupta <deep.main.ac@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/b2/61/62f3d33278cc0d37f78efc548aaa721a610c70fa13e68f24ebcffe7b95ea/deny_me-1.1.tar.gz",
"platform": null,
"description": "[![Implementation Test](https://github.com/d33pster/deny-me/actions/workflows/Tests.yml/badge.svg)](https://github.com/d33pster/deny-me/actions/workflows/Tests.yml)\n[![CD](https://github.com/d33pster/deny-me/actions/workflows/Deploy.yml/badge.svg)](https://github.com/d33pster/deny-me/actions/workflows/Deploy.yml)\n\n# Overview\n\nYou must have often wondered about how to make a function restricted to the user so that it could only be called a specific number of time, or even a function that is password protected.\n\nThis library provides an array of function decorators that can be used for the same.\n\n## Table of Contents\n\n- [Features](#features)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## Features\n\n- Easily restrict any function according to your needs.\n- improve overall acessibility of your program.\n\n## Installation\n\n> Install using pip.\n\n```sh\npip install deny-me\n```\n\n## Usage\n\n- **Once/Twice**\n\nTo make your function run only once.\n\n> import the decorators.\n\n```python\nfrom deny_me.restrict import once, twice\n```\n\n> use acording to your needs.\n\n```python\n# demo function\n# This function will be callable only once.\n# Repeated calling will generate error.\nclass some_class:\n def __init__(self):\n ...\n\n @once\n def function1(self, name: str, school: str = \"ABC\"):\n print(f\"{name} goes to {school}!\")\n ...\n\n # demo funtion 2\n # This function will be callable two times.\n # will generate error if called more than twice\n @twice\n def function2(self, *args, **kwargs):\n ...\n```\n\n> **Note to the users.**\n\nIf other decorators are used for a function other than these, then it is recommended to use these decorators at the last.\n\n`For example:`\n\n```python\n# demo class\nclass Demo:\n def __init__(self):\n ...\n \n # suppose you need to define a property\n # that is only callable once.\n @property\n # use property first\n @once\n # and then use once\n def property1(self):\n return ...\n \n # similarly if you want to define a setter\n # for the property.\n @property1.setter # use this\n # and then the once decorator\n @once\n def property1(self, value: str):\n self.value = value\n ...\n```\n\n- **Run custom times**\n\nTo run a function n times.\n\n> import the Allow class.\n\n```python\nfrom deny_me.restrict import Allow\n```\n\n> run n=10 times\n\n```python\n# demo function\n# this function will run 10 times\n\nclass Demo:\n def __init__(Self):\n ...\n \n @Allow(10).times\n def function(self, *args, **kwargs):\n ...\n```\n\n> Note: Similar to the Once/Twice decorators, If other decorators are needed, such as `property`, then it should be at the top and the `Allow(n).times` should be the last decorator.\n\n- **Password Protection**\n\nTo make your function password protected.\n\n> import the Password class.\n\n```python\nfrom deny_me.password import Password\n```\n\n> Use the password decorator.\n\n```python\n# demo function\n# this function will be password protected.\nclass some_class:\n def __init__(self):\n ...\n\n @Password(\"pass123\").protected\n def function(*args, **kwargs):\n ...\n\n # It is recommended that the above function has `*args` \n # and `**kwargs` in its parameters.\n # If some parameters are mandatory, they can be defined before \n # mentioning `*args` and `**kwargs`.\n ## FOR EXAMPLE:\n\n @Password(\"pass123\").protected\n def function(name: str, school: str = \"ABC\", *args, **kwargs):\n ... \n```\n\n> **How to call the function?**\n\n```python\n# To call the function, just add `password=` parameter \n# while calling.\n\nc = some_class()\nc.function(name=\"hehe\", password=\"pass123\")\n\n# This will run fine as the password is correct!\n# However, if the password is wrong, it will\n# prompt about the same.\n\n# NOTE: if the `password=` parameter is missing while calling\n# the function then it will raise an error stating that\n# an exclusive feature has been called that is not made\n# available to the users.\n```\n",
"bugtrack_url": null,
"license": "MIT License Copyright (c) 2024 Soumyo Deep Gupta Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
"summary": "A python library for function decorators to restrict access to functions and much more",
"version": "1.1",
"project_urls": {
"GitHub": "https://github.com/d33pster/deny-me"
},
"split_keywords": [
"d33pster",
" deny-me",
" deny",
" me",
" decorators"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "b5bc1263fe557fbbad0e0d44ff49699532fcc94ee8a6b66e8d362d3cad8ba73f",
"md5": "9200d89c732a6987ee96785a2215fd27",
"sha256": "0e7006aefab954876c5295cdb3ba6f46de3fd2ef17308cd4ff01c10b3a0329dd"
},
"downloads": -1,
"filename": "deny_me-1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "9200d89c732a6987ee96785a2215fd27",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 6244,
"upload_time": "2024-07-12T12:19:27",
"upload_time_iso_8601": "2024-07-12T12:19:27.986185Z",
"url": "https://files.pythonhosted.org/packages/b5/bc/1263fe557fbbad0e0d44ff49699532fcc94ee8a6b66e8d362d3cad8ba73f/deny_me-1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b26162f3d33278cc0d37f78efc548aaa721a610c70fa13e68f24ebcffe7b95ea",
"md5": "38d333bae4f1b2df5f4637732f72a684",
"sha256": "fd7da4b35cdc6e039fb3ecfc68c7ac5b279dc8e061f747a03f086bc8ff42eb70"
},
"downloads": -1,
"filename": "deny_me-1.1.tar.gz",
"has_sig": false,
"md5_digest": "38d333bae4f1b2df5f4637732f72a684",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 6200,
"upload_time": "2024-07-12T12:19:29",
"upload_time_iso_8601": "2024-07-12T12:19:29.023456Z",
"url": "https://files.pythonhosted.org/packages/b2/61/62f3d33278cc0d37f78efc548aaa721a610c70fa13e68f24ebcffe7b95ea/deny_me-1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-12 12:19:29",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "d33pster",
"github_project": "deny-me",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "deny-me"
}