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.
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-2.2.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ed44b813e9c082d4a38b5f157f1f639ddfbccf7da985c5f0c330e964df36b649 |
|
MD5 | f273b4f0535987328a025c6d1dee9502 |
|
BLAKE2b-256 | fa6dd9d1f76661f683f6b4a62adc178cfed4b2080e23c6a450982a968a872599 |
Hashes for Advanced_Descriptors-2.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c0fe97d5cf6423420ee3bdd906d60e37d53b1277f7b7614572738b853822b973 |
|
MD5 | 3eaea0c318f1664be38f7f6f0dfc6938 |
|
BLAKE2b-256 | 327439716a324ec8d31adb079cf23931a1ef4aafd9cdd152250131e092b16577 |
Hashes for Advanced_Descriptors-2.2.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df130485f0ee3de2c57afa8cb0b0970ec9d41f5b1345b83522425fb87c2fbdc2 |
|
MD5 | cdf46dc9bc7549313a2b31cb5213aa76 |
|
BLAKE2b-256 | 2bc3117c96d87e7d6429704d96b71767a1e664f2c76f0f4012cc778679709ae2 |
Hashes for Advanced_Descriptors-2.2.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 169e045bf07e125859351ee03eee0c5b3057810d8db317524955cce31c9122d3 |
|
MD5 | 97ec03fb6b40bf0012ceca362cce5e27 |
|
BLAKE2b-256 | 7a8a822c459db84bfd0a2595ff14f4dd19052c3fcdbc7ae0202a0c9e12fc5e38 |
Hashes for Advanced_Descriptors-2.2.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4f7e7c5e1b7f247570c5a25f5d3d72735b87d8a71d43a34d4cd71f3ed4ddf511 |
|
MD5 | f2c9c1a5b5f226c145d0af177eb63dc3 |
|
BLAKE2b-256 | b6b2be87c5c7a8ec7cfa59826444aa51cfb2ae380eb0ec4924d7bc06fbc7443e |
Hashes for Advanced_Descriptors-2.2.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 638856da9dad94122d26fbe22b4ed51be35bf5e405d60f2f255468bff8240df9 |
|
MD5 | b85f1756a9615415f6fcea4aff6f297f |
|
BLAKE2b-256 | 65e412cd288d8dfa3af77a23003ad1333d1b0d8cd07017cf604a46360b5af44f |
Hashes for Advanced_Descriptors-2.2.1-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e67f94fc78b08e0d6437a98eb1539daf5c23f01c8e8216dbfe4bcb46b0afc09f |
|
MD5 | 61a31b6214bc485a11a83d9f9d9fd3fa |
|
BLAKE2b-256 | 4cff402a9d64d54cb66b7675fc6ad3304e8fd82b5feb3c4addbda4bd8f2bda49 |
Hashes for Advanced_Descriptors-2.2.1-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e36e590ecb6cbbefdb3ff68be4653f29af560e29eeec46210cfcb2cb5d830cef |
|
MD5 | 744f3dc7647ed51fe542409cc60f23a5 |
|
BLAKE2b-256 | a40de76cc9284cbd28f9bd1316b0892f57985783f3516fe808c152cd552e1cf9 |
Hashes for Advanced_Descriptors-2.2.1-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 92a5069b78987c054bb29ba768eba9a18e5354a85cb832dd6c854cded5753841 |
|
MD5 | 37cac56396a2de10d158f3acbf1e6dba |
|
BLAKE2b-256 | 8971859d0ec82e65cc360c3cb8f5e3a620aaf371fe7e9e847aeeca1ba9a66bfc |
Hashes for Advanced_Descriptors-2.2.1-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3223737ee3290ec9f1020ad60d0b286908af9c60ed6f8e691b86920200682c36 |
|
MD5 | 8e89e1ef0eac3046cef819aca06ba34f |
|
BLAKE2b-256 | d6da1d04f664a6aad540f56467a8dc2c0720efbb13b875a8de79cd0e415662e3 |