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-2.2.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e98d2412b3b0788197a8ea7b6b5071dc8a1bebf9f3b802b431981c46ea3a57b |
|
MD5 | 412859ce8df13b0b8e52d4ad781b80e5 |
|
BLAKE2b-256 | 2b8aa65ffcee34b19c49b28139493ac3a66c558f06c0ea35769b84d8cc065a3e |
Hashes for Advanced_Descriptors-2.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cd966f2c13a3788749e456d266bbc79addde1dbc98e085671a7775ed9bd66157 |
|
MD5 | 3514a84f5c7ca2cc4286cdc6c47b8a8c |
|
BLAKE2b-256 | 494a33171cc2e0782b5cbeaa5b1969a170afb6c65d8c9616996455877a1459b0 |
Hashes for Advanced_Descriptors-2.2.5-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6aa3d1fa534f31ef7fd73036a24a6855eac9bcc44284c3b9356f05a627774d0b |
|
MD5 | 4c0eec1035571521ac5fa2171511deb3 |
|
BLAKE2b-256 | d47447dd8c4fbc6334129761443dab2b82ff795f289d01f25f203865f4517a53 |
Hashes for Advanced_Descriptors-2.2.5-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5368b7a296f484935ff328c316cb33dd8c148be6c4db13f1662c6a51b0541732 |
|
MD5 | 78b48b02516f198025f62605426bf050 |
|
BLAKE2b-256 | 5200a4213b4fcb9797e61e9f8e4b8500d887b9b594c4b97b91c50fbae3c2a7d0 |
Hashes for Advanced_Descriptors-2.2.5-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7dfd5b093910bc213db93efa86d055f03199685408fe32c7e80e4e32b70d6ef |
|
MD5 | 666253de6a510a6baeb14e4c4f1ce192 |
|
BLAKE2b-256 | 81de8f7872061f0f4d4894cfc260dbc103702d9e8bae3709bce358d880121c51 |
Hashes for Advanced_Descriptors-2.2.5-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01d9c6dbb53c25e1bcbe4edb1fbd07d53778eb2a7cec79f4f6fd67723a3b8487 |
|
MD5 | e0506d8826efd6fcb7016c8b2c1922d6 |
|
BLAKE2b-256 | fa734fede71d35be152853338b40c8845657c1e10b1f64f0e28a1879a9447d7d |
Hashes for Advanced_Descriptors-2.2.5-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59a41166069f15cad3f2ec6f7223c062a37f42a8512a62444b31bb5857cd6cf6 |
|
MD5 | d798b0db1ed025990e754e5dcca66ca2 |
|
BLAKE2b-256 | d214b36f0263a5ee0e46f0477cbfc8cce20581f7d6e3ddc39d3556b21ef5e196 |
Hashes for Advanced_Descriptors-2.2.5-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0fb9f7fc0d9cc69791b88184a7a5368e44f5c02b4ecd09a20628cea8f15c1a0f |
|
MD5 | e2ee194b03a2d41a3a5764039d7adbd0 |
|
BLAKE2b-256 | fccf0256a5f21c4e2520491a6eb4d4f8bc03f950a2d928500f9f9f074d782c78 |