Easy plugin for open-close class objects
Project description
open-close-mixin
About
Easy pluggable Mixin (and decorators) for objects that may benefit from open-close dynamics.
Installing
You can simply install it using pip as follows:
$ pip install open-close-mixin
Usage
You may import an OpenCloseMixin
along some other decorators from the package root and use them further on to create your own class with open and close dynamics!
>>> from open_close_mixin import OpenCloseMixin, always
>>> class Foo(OpenCloseMixin):
>>> # only while open, that's default behaviour
>>> def run_when_open(self):
>>> print("The instance is open so I was able to run")
>>>
>>> @always
>>> def run_always(self):
>>> print("I am ALWAYS able to run, whether the instance is open or not")
>>>
>>> f = Foo()
>>> f.open()
>>> f.run_always()
I am ALWAYS able to run, whether the instance is open or not
>>>
>>> f.run_when_open()
The instance is open so I was able to run
>>>
>>> f.close()
>>> f.run_always()
I am ALWAYS able to run, whether the instance is open or not
>>>
>>> f.run_when_open()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/alberto/Projects/personal/open-close-mixin/open_close_mixin/decorators.py", line 27, in wrapper
raise exception from None
ValueError: The instance is not open and the method "Foo.run_when_open" cannot run under such condition.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file open-close-mixin-1.1.1.tar.gz
.
File metadata
- Download URL: open-close-mixin-1.1.1.tar.gz
- Upload date:
- Size: 4.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f6865a739e5d4b11fbf53afd080a8e3ceb08a70ce67df981f201410aeb3be9a |
|
MD5 | 9fc12ea9aa6369a3f9257a49bc53a726 |
|
BLAKE2b-256 | d1cca2744ea49049cf91eb0e41a6b0db945f8f90ca32fac303ccc863bf1222b7 |
File details
Details for the file open_close_mixin-1.1.1-py3-none-any.whl
.
File metadata
- Download URL: open_close_mixin-1.1.1-py3-none-any.whl
- Upload date:
- Size: 6.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/51.1.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f382c1c1cd594034ff5aaa699ed8c2016598446b3bd0846bed4e2e57505dcf3e |
|
MD5 | af507df0bf79437f08c14a067484c611 |
|
BLAKE2b-256 | 041d8dcd7e7137169a3662bf807bf78bc13eb8e97c8e640e092ee40fdaff040f |