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 Distribution
Built Distributions
Hashes for Advanced-Descriptors-3.0.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 082d790de94097054ea2d4be7ed6afa25f11e3923a8a291b662e7c05d0f07128 |
|
MD5 | b8e325a1382fa7b4a9e10b738319649b |
|
BLAKE2b-256 | 2031db3feea790b9da1b84f53b0b9d37d938f04097da15541fd63c7eaf1efe0b |
Hashes for Advanced_Descriptors-3.0.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 482dc92cf0843ad2803c8429583eb8315d37ffd497d07bebe8aa7623bef0b0bc |
|
MD5 | fe9337d5c5b4e085826e834695b8552f |
|
BLAKE2b-256 | fcb3ed19b3eb92788662bcacc5dce9dc4d419e27bfc251c786d3293befef4cfc |
Hashes for Advanced_Descriptors-3.0.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8320a735597ab0cfe45ae41a47bf8b930ed94ef47241a304d18f183c1878f666 |
|
MD5 | f3edfa4c85b82181fdfdb2317319223b |
|
BLAKE2b-256 | a39ac02eddeb2f7e9a40e36c8c28d080887d780579b0459efcb2778be758cc5a |
Hashes for Advanced_Descriptors-3.0.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e2f2b88244b6d83333dcf4b17df792cb5612668bdf9395787441f62143d1da1 |
|
MD5 | cf427303a980418009e1fec5608324ec |
|
BLAKE2b-256 | c08815c8240e89288af824b0f995ae39df8e58177691970d30409611addb1973 |
Hashes for Advanced_Descriptors-3.0.4-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a9b7eb7b97194b2a316977dddb55b51238d8168bd40a09b33fbb05789c99b556 |
|
MD5 | e0464c63bd190de044ee9c8a89859b0f |
|
BLAKE2b-256 | cb1c158d35d9c5b832efcf005aa71f30a69b48f0095ffd44ec10c94780a00515 |
Hashes for Advanced_Descriptors-3.0.4-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 788e6ab488f2d833b4005ac93054c0a393499092a6eba4e147f7b948537911fd |
|
MD5 | 2125ab52e40afa93901ac72e0c3694aa |
|
BLAKE2b-256 | da5adc65f903594ea71aba5de719c12091fa44be279fada94a35baa5c1c0f195 |
Hashes for Advanced_Descriptors-3.0.4-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4bff69458345867b91d496a043ed57a82c37dab0cbd8582dfc1080d4a3670e60 |
|
MD5 | 86978826fb985714af269b9eb09e02e1 |
|
BLAKE2b-256 | 7b5cb320dacfd24654c3961f27c8f962a44c4043abb423657d92d9e513049438 |
Hashes for Advanced_Descriptors-3.0.4-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6183d1014958976b5b93344e2ee405c4be800515d787bd0780be270b54a9a3bb |
|
MD5 | 04226cfae7a6a639ffbb769544e14f6b |
|
BLAKE2b-256 | 5a695638bf549a3c240af0e2d667a091c01f6fb425e7532f4e2ec55f03b4c2c0 |
Hashes for Advanced_Descriptors-3.0.4-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ad30a1f5cf717b48717a41452dada7088292abaa7d0c1352d33fe02ca4c4824f |
|
MD5 | 89d20ab670f4ce395a421f3a851ae215 |
|
BLAKE2b-256 | 573de39dcab904dfb424bd64502531a48292db19bc1fd30e3e56a1e003fc0568 |
Hashes for Advanced_Descriptors-3.0.4-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff4c5a6cdbc14771a0c4610634c89ff0ffb7475a80a140cb59a2feebb45345b5 |
|
MD5 | e001ddd6e40f51047ff86114d6b12bf7 |
|
BLAKE2b-256 | 4d96724f528ee768cd95d0fa9ed785296d32f0c5413484e0e7c3af19d8fde00f |