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-3.0.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b4446d6a40e72f71c639e020c4170ee0dcef29bb21fa9d5b59ace1eefc704724 |
|
MD5 | e05a5bc42b71a4ccf3235b4898b50f31 |
|
BLAKE2b-256 | 2c526e0937b627095b4322ab1a1209267a2307e24109fe56ef2084c3bfb8a0a5 |
Hashes for Advanced_Descriptors-3.0.6-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efb9087f39d67f2dc703c86b06960233d8546fde5efc1ef145e6ff8f49db09b3 |
|
MD5 | ae7379b9cfc9663f26faaa38ccafe4c8 |
|
BLAKE2b-256 | 472f13a806ca4b56e9dd5448964d604de375b5e0f21453923119e08a4297a032 |
Hashes for Advanced_Descriptors-3.0.6-cp38-cp38-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96f1756e819340272e8af792b8d21e21fe63050996186e2d4f4a1de056984e88 |
|
MD5 | 99a1b02cff8eb0c1569b10bf3966d27c |
|
BLAKE2b-256 | adc791d5f6727d8e3afb11ae9ed67f8870e2264000a315502e3ea2e3c4b4c324 |
Hashes for Advanced_Descriptors-3.0.6-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95f61fae0bc2e48198670c201200fbf996585773f92d9b2618568251a98fd614 |
|
MD5 | 755bab2fa115ff1f31df3947d9503d8b |
|
BLAKE2b-256 | 2e51068ad84b87da3069ddc01b6434a41a60357e3353c274385650248aaeb4cc |
Hashes for Advanced_Descriptors-3.0.6-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 86c6699fa7600eb4be95d27068cf7356ad1cbde212f308d0df49bf9af4a1353c |
|
MD5 | b699b03722fa39a1a79aebec83ec787b |
|
BLAKE2b-256 | 687aea3dc8655a48f01e7069d523694d2cf8c4afebcbde390d677afde836355d |
Hashes for Advanced_Descriptors-3.0.6-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df4d0e82036a4a99dc7082f580b0c5b7baa54514b05884c47d12e6bb8cd7613a |
|
MD5 | 33df05aa0a3468061bbe6f8cd5e22218 |
|
BLAKE2b-256 | deabfe4c28f0f23f2705c565dd0fd7a9ca39e6f5f39389e2f8bad919d0072780 |
Hashes for Advanced_Descriptors-3.0.6-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dc7456c462c9320f5cc24fa8fefd18c308f096b765dbeffaa7ed4dd149615425 |
|
MD5 | 29d94cb63e42d1f1ec63ac40218c5cb2 |
|
BLAKE2b-256 | b2eabc02473c542c01ed7862cc17051437531148d479cd4548d244babf56fa6f |
Hashes for Advanced_Descriptors-3.0.6-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ce95306176b26c5f7ff2f5d91bf7ef8adea7b1192aa6491d4e79cb58ce01653e |
|
MD5 | 7baefa0d8f5634ef5c0e0d34382d35e2 |
|
BLAKE2b-256 | 16643fb100a457daadaa22cc15db52b4cc8eb07ce75cb9659a5b689e54066f40 |
Hashes for Advanced_Descriptors-3.0.6-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99a9c5f62391d7e14aa93aa43a12648753c6a2f96b8d82d9bc6d8462c72b416c |
|
MD5 | 8e1894a5d11a9415bba0d45729e90333 |
|
BLAKE2b-256 | 7ebcee1fc82d822ab84b6dfcb77d7811e289627334c2908b05d3eda5070e3616 |
Hashes for Advanced_Descriptors-3.0.6-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9caf990be084a79d2abd78f348d94bae22079b278f5de28d7d8f8327cbe37d59 |
|
MD5 | 24716eef7456b53c56c1b8fb69b316af |
|
BLAKE2b-256 | a8a762a973c8c6a3f6a4e4cd0b4516eb16941637e896efc18f905f3e7317c8b7 |
Hashes for Advanced_Descriptors-3.0.6-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 083964ba22b8834ae3c2dd521a6f6b037f2ba6b33587f3f9eb5798bdcead1ec4 |
|
MD5 | e7e71c1a3e3e6c588c09bfb82de1b224 |
|
BLAKE2b-256 | 06ce11ce1dc66fac36962c00541d55f84bf6f972a06a6562ae42769096ffec96 |