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.7.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 795cf575413249b7708c1856bc0498f35783fb5af5149c20116c1010fb1c9a6c |
|
MD5 | 0fa49d14840ffb985d1dbae3191a1d37 |
|
BLAKE2b-256 | 757bacbc1474f70d4f68d7310ceb0143319a5e5e4208c98201435ab93fbadc2c |
Hashes for Advanced_Descriptors-2.2.7-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5235f8265c627ec57234b24c7451fa295fc7369c044a0021655c8e2287785037 |
|
MD5 | 9b7d65a7c25db51a6750da97f88d2552 |
|
BLAKE2b-256 | 9c597daef91c68f42a276c5b8428321dcfe8c910fc7ac6178a1ba54f3ac2e8a3 |
Hashes for Advanced_Descriptors-2.2.7-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bb9dff0ac333850e04921f06b0ec17d625a14d37faf6cf69a813a97d5095361a |
|
MD5 | 29c9aeba4e5ba6a4d63e6a1209446b36 |
|
BLAKE2b-256 | 3383d52a92a66ec39fe2e4eca89986f48e533ef656d0432952cc6759561d1720 |
Hashes for Advanced_Descriptors-2.2.7-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06ef8d10446b34d92e54e7133886778ec6c3b8d9de0a0416a57cb588d1a3e67e |
|
MD5 | ec5d044a11c883ff3b52ccfb578ff4c4 |
|
BLAKE2b-256 | 5c313dda1dd33952c944149c1e92342ecebaa790df9899bc9f8ae85cf2fe4e8b |
Hashes for Advanced_Descriptors-2.2.7-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30b15d9512402ba6e9e3167d330800cc16f252d830c77f5a4edfaf3254b2bbe2 |
|
MD5 | 09ef93206377751d4dc1e6fde36a6d8a |
|
BLAKE2b-256 | 12af58bc63b5568af5a51fb4eedfc1d521e9e02e342aca884a6fa1fd4fa53aec |
Hashes for Advanced_Descriptors-2.2.7-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b1ecd227a048c614fca6a423ab5d3751d2b369afca072974c88646c13d807987 |
|
MD5 | a8376cbbd79ca31e36786d74cb6f544d |
|
BLAKE2b-256 | badbf354eb88d982daef2916a19abb62dbd11e5a3a0ba12e3b12e13a7c94172f |
Hashes for Advanced_Descriptors-2.2.7-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ecfa7fd46a48f7effa43d12b6f5543ac724019ada0055ea2e7414d3e69606fa4 |
|
MD5 | 6a604e0be80035ed2057d0e854ad71ad |
|
BLAKE2b-256 | ae648309d2fee319c17a79a30054199d5aa17c5a0aa4544be552e03f7d134beb |
Hashes for Advanced_Descriptors-2.2.7-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 682d421eb82d5240dae90ecbabe7d3c53db70966610dc127a6de87000621e2df |
|
MD5 | c12e28c9b143d60af304530323ceeac3 |
|
BLAKE2b-256 | bfee45457bebd9112aec3c645d06bc13c0dc4e0b299495ce6ef8981217551a3b |