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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff20a8eef00ac6a4ed8fb9bb8f569e7afe2a0ac05244d22dbbb1465bd027c8ab |
|
MD5 | acdd46a9ef549132fd2a2c0acf960981 |
|
BLAKE2b-256 | 72217a69079ed38f20c76d13908957c23ef58f75853819fc21dcf93d227c0030 |
Hashes for Advanced_Descriptors-3.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 28bd8613eeef7977a9efa9c1e1dae4d6ea8109bd95ad20f1189a117f33e44dd8 |
|
MD5 | fc82da3b362c6007e8e1c8d3886f7d4c |
|
BLAKE2b-256 | 8275458644f44cd8859f71973936657a10b815f0ec87291010625321a400a187 |
Hashes for Advanced_Descriptors-3.0.3-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e18169ac8accc08d02535ca2a295da9f00fcf5753343fddfae612f9f5360186 |
|
MD5 | 63a364597ae27f40cdda3978fd1a11da |
|
BLAKE2b-256 | 262ab11c92e25016d05b26a2b7e2121560a6694e86437958c1ce3adb4c00e9ae |
Hashes for Advanced_Descriptors-3.0.3-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 616b0bebb9eda4d543c57082ee0eb9a3b145fc09c5127564b1a20c2135a551d8 |
|
MD5 | 4dd48ba7fd0e7c2f61aa07e22f20f219 |
|
BLAKE2b-256 | 5d72f3e7530887637ec5fe1ea4b021e3538e03763ec2b82a14e63226e5144a94 |
Hashes for Advanced_Descriptors-3.0.3-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4a08c9fb2f959a1a7143ca70cd83b583bfa5e220b97de91c73c1836a20d906ab |
|
MD5 | d6ee2cf39adfd239c2f6751e05b0ea89 |
|
BLAKE2b-256 | 1489f979194d3368d65cad0de79e780fb8d5fd2b7c943e73690b910bad8fe7db |
Hashes for Advanced_Descriptors-3.0.3-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6435da7d70730fd42fc17e2b0ddf2d5710277aca7e44505a8507a4bffd78b8a9 |
|
MD5 | 02393850adfed4e2834d9e610f33704b |
|
BLAKE2b-256 | 0c59d2abf86284535bfbce9f292ea7f3b379e8f83e7f30ba4e7f0e101ce6f7b5 |
Hashes for Advanced_Descriptors-3.0.3-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd6c8adf7395b9bdcbcd85dd6204a1619958ca42e6251404ead1349131b2e74a |
|
MD5 | 6cc52f792524b24518032f98c5b51349 |
|
BLAKE2b-256 | 2af074282d3280075ab0bda9555e571caa6508c7cacb25bf5db03755616ae012 |
Hashes for Advanced_Descriptors-3.0.3-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de410a9c0623607b58dc3ae736b8cd40743ccb440d0e256f3e8584d7edbb7337 |
|
MD5 | 0f0749b852d98e9f55ddae2308ebcaef |
|
BLAKE2b-256 | fc6e3b139392332464a1cd78de306275962aff7b2251339f7f7b7dd9bf255147 |
Hashes for Advanced_Descriptors-3.0.3-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5bd3cbce5d0519f93b9b1263427a9aef9baa343da0838c733998454bbb84d8b4 |
|
MD5 | d6c513c041c2a06b5ac19ca0620239ff |
|
BLAKE2b-256 | 8334adbef7a66786728ee8beac5fe94f88dbb2ba34dd1651a452bc9ac67d997a |
Hashes for Advanced_Descriptors-3.0.3-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 527f468f8b5a36cc77fa87975ff34b5274991cf0b65bf402a64d424eccf434b4 |
|
MD5 | e9ac5557e82a2be86181ff3e8055440a |
|
BLAKE2b-256 | 44c16857a4ebcb293dfd9eb247987e424747148de5ef0e6a33388aec9a11a6ef |