Advanced descriptors for special cases.
Project description
Advanced descriptors
This package includes helpers for special cases:
SeparateClassMethod - allow to have classmethod and normal method both with the same name.
AdvancedProperty - property with possibility to set class wide getter.
LogOnAccess - property with logging on successful get/set/delete or failure.
SeparateClassMethod
This descriptor can be set using standard decorator syntax. Create instance with arguments:
def imeth(instance):
return instance.value
def cmeth(owner):
return owner.value
class Target(object):
value = 1
def __init__(self):
self.value = 2
getval = advanced_descriptors.SeparateClassMethod(
imeth, cmeth
)
Create instance wrapping as decorator:
class Target(object):
value = 1
def __init__(self):
self.value = 2
@advanced_descriptors.SeparateClassMethod
def getval(self):
return self.value
@getval.class_method
def getval(cls):
return cls.value
Cases with method only and classmethod only is useless: method as-is and @classmethod should be used in corresponding cases.
AdvancedProperty
This descriptor should be used in cases, when in addition to normal property API, class getter is required. If class-wide setter and deleter also required - you should use standard propery in metaclass.
Usage examples:
In addition to normal property API:
class Target(object): _value = 777 def __init__(self): self._value = 42 @advanced_descriptors.AdvancedProperty def val(self): return self._value @val.setter def val(self, value): self._value = value @val.deleter def val(self): self._value = 0 @val.cgetter def val(cls): return cls._value
Use class-wide getter for instance too:
class Target(object): _value = 1 val = advanced_descriptors.AdvancedProperty() @val.cgetter def val(cls): return cls._value
LogOnAccess
This special case of property is useful in cases, where a lot of properties should be logged by similar way without writing a lot of code.
Basic API is conform with property, but in addition it is possible to customize logger, log levels and log conditions.
Usage examples:
Simple usage. All by default, logger is re-used from instance if available with names logger or log else used internal advanced_descriptors.log_on_access logger:
import logging class Target(object): def init(self, val='ok') self.val = val self.logger = logging.get_logger(self.__class__.__name__) # Single for class, follow subclassing def __repr__(self): return "{cls}(val={self.val})".format(cls=self.__class__.__name__, self=self) @advanced_descriptors.LogOnAccess def ok(self): return self.val @ok.setter def ok(self, val): self.val = val @ok.deleter def ok(self): self.val = ""
Use with global logger for class:
class Target(object): def init(self, val='ok') self.val = val def __repr__(self): return "{cls}(val={self.val})".format(cls=self.__class__.__name__, self=self) @advanced_descriptors.LogOnAccess def ok(self): return self.val @ok.setter def ok(self, val): self.val = val @ok.deleter def ok(self): self.val = "" ok.logger = 'test_logger' ok.log_level = logging.INFO ok.exc_level = logging.ERROR ok.log_object_repr = True # As by default ok.log_success = True # As by default ok.log_failure = True # As by default ok.log_traceback = True # As by default ok.override_name = None # As by default: use original name
Testing
The main test mechanism for the package advanced-descriptors is using tox. Available environments can be collected via tox -l
CI systems
For code checking several CI systems is used in parallel:
Travis CI: is used for checking: PEP8, pylint, bandit, installation possibility and unit tests. Also it’s publishes coverage on coveralls.
coveralls: is used for coverage display.
Azure CI: is used for functional tests on Windows.
CD system
Travis CI: is used for package delivery on PyPI.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for Advanced_Descriptors-2.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec40fec8c9edf80bb6520a32dd511d959d671894874b5e8e35fb26f0ba8663e1 |
|
MD5 | 26da48a07a20ce66c95aa8ddb091a9f9 |
|
BLAKE2b-256 | a741a1534cebc4af728dc150f1919a117a25d50df2060577736e3731dbaaa2d4 |
Hashes for Advanced_Descriptors-2.2.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7a5708655ca3657592c08a6a909304561751355ee3581cca9f6380ad6f5647e |
|
MD5 | b1fa0e987aa8050f31ec7ef2d9fc2a70 |
|
BLAKE2b-256 | 0a8876409d9dc67f60339557a4784fb7fc56946137c83f9d6a8a3e3494204246 |
Hashes for Advanced_Descriptors-2.2.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed60c5c4a55cdc8554c82c318455258e50ddce0232f17a082b6d8b05f2700201 |
|
MD5 | 67e861423d541556e47ac83843fcdc42 |
|
BLAKE2b-256 | 5b8c87045c55da19962a62c70a4b078e877cc16f158151e4b230f5ae36be3cc4 |
Hashes for Advanced_Descriptors-2.2.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b640c7c4d646b646905d004043b597232783cca6e547fe2c2067cce430b11a55 |
|
MD5 | a8c4b1b8e6f2c05fc2fe2a631678f6e0 |
|
BLAKE2b-256 | 643734d9e7b25db2f4038a3cc671d37cda8c7cc5c47000edc6a232bfbef5579a |
Hashes for Advanced_Descriptors-2.2.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f3b422cb58195339efa772359ac667cc5339c8316ca610b0e7ef9829a9092e2 |
|
MD5 | 3fdee745ffae9282d2ef1235f7e2d116 |
|
BLAKE2b-256 | 128a3e360840a9b12d83b416bea7f6a95b4a62ff2fd9c85c3ac2cac21d9fa8bc |
Hashes for Advanced_Descriptors-2.2.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad52ca21b099d6df76dd301938134b0ad7b2fd86cb548f10e02ee8015c2141d3 |
|
MD5 | 70b6e21a13a057111369afaafe24930a |
|
BLAKE2b-256 | 65c7f35106c4174b197c21ead2ccaed35a56c9ae0e62cc91d7f6d3891d0e5196 |
Hashes for Advanced_Descriptors-2.2.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 032f4839e660d4e415e1e76df8892bbcb46333538c70749826df3efc1dd4630e |
|
MD5 | dbf82de185adbcfac63eaba3b78eae89 |
|
BLAKE2b-256 | 468a974adf1cb53bfa9e02c69a7f46ab0bc22ec99be8f8a4f5724ee78e60ff4d |
Hashes for Advanced_Descriptors-2.2.3-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2357447d9530e3d5890d0554eef997e88250fb4e573504fae18623e9b04132bd |
|
MD5 | 2806f502f6db67d70e9df246bd035a16 |
|
BLAKE2b-256 | bb4d145585df82b981706e7cbe43820f1a1886ded023b720d32ecfb480926dea |
Hashes for Advanced_Descriptors-2.2.3-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aed80f29b0998a87dd6f1a3bab826e09107357bfb45e5f528733406b4618f4dd |
|
MD5 | c7d10f8ecdef65ccb20d7b1768d69f03 |
|
BLAKE2b-256 | 2138a69cf7d416be226af2a479d22f67c4eb7d408b78935b36168ff27aca16fb |
Hashes for Advanced_Descriptors-2.2.3-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b8a5b44ca1f83ffbe7b24e80c5b0900811ec2ee439166e0718a36cb095f9ff1 |
|
MD5 | 9edfc85142881d1f1ba680a25e67bfa5 |
|
BLAKE2b-256 | af1ebd6301396dc36f38fd0d8721eccf8a5adceb9ddc247a4c53531817a660d9 |
Hashes for Advanced_Descriptors-2.2.3-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43f0825b08ffb33f2aa5ca0c8d5d341b6fe67a39fd7d1067a6be73274610ad0c |
|
MD5 | 2e56effd2aac197eb256976c9fac444a |
|
BLAKE2b-256 | 3b6f2f013059739fd3257c525ab50edf06784a963854a6f416c209eef4d2a226 |
Hashes for Advanced_Descriptors-2.2.3-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c93776bf88fe7240fa595362fdcce406a05a21b23c7fba8c4b447997b142577b |
|
MD5 | 971429ed2ca672b76415e835025fffdb |
|
BLAKE2b-256 | 7b71faa685d7da520cc4745894f9ec5f03746bf3343a64569b95e198607a8284 |