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.8.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 176c790c4f88dae8475706972d957b674a665409c16db6560c85b8153c0387c5 |
|
MD5 | ccb3af5972ed11663c55cbef1b9e90be |
|
BLAKE2b-256 | 6e98be453984042d66d6bcc1d1371c7dd7b2f02173b9a0f0f6eef2f524fcc314 |
Hashes for Advanced_Descriptors-2.2.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 88b10ac0eded5928525400b8a204dcc6d76296289ae127a5f12d30ed431e9925 |
|
MD5 | 13a3291406e5d89e326f64eafc73b9ab |
|
BLAKE2b-256 | 9933dc3fa55e7b9a6a6fc92a0354b117772093f32d16059b7258e56416cc50f2 |
Hashes for Advanced_Descriptors-2.2.8-cp35-cp35m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | be694f7f4b72684623b7354ea0313f48de33905679874974905add804ddef4ae |
|
MD5 | 10b9d25dcf581afabd3e91b8fbbccfb0 |
|
BLAKE2b-256 | 5bcad668bbf8777223359db6873ddc082222c0ba893881c7e27d25a8a3d2523b |
Hashes for Advanced_Descriptors-2.2.8-cp35-cp35m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12976a15804e09612026a8b78d14edac6316ce8458c3f8a8d86da91da8b544d3 |
|
MD5 | 145fc9e9703fbdd3ee9777b04c4c9022 |
|
BLAKE2b-256 | b9d831361aa90a5d3c792afa8801ef840889de625aabcf632040c81c0b405f94 |
Hashes for Advanced_Descriptors-2.2.8-cp35-cp35m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac373c3f3c55086aaf2ba02016f1b11540e3bc2abb768d7b7c011c4049823663 |
|
MD5 | ac0081c83174314fabf6b578723d7ba9 |
|
BLAKE2b-256 | e15906c97069856105e916955b5861afc750bdd262d0b076cade8063a8789659 |
Hashes for Advanced_Descriptors-2.2.8-cp35-cp35m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5af6205d3ab180af35dd6794cec9a1ce32ea08f2c25e18c8832e35f2eb42b665 |
|
MD5 | 028b29e9e70c740c9a6d2b2cd7943ac8 |
|
BLAKE2b-256 | 82711ed6d6a187a1c69bda587298cd305617e54ab98c7cd1f644f4ce54eaa7f5 |
Hashes for Advanced_Descriptors-2.2.8-cp34-cp34m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a29163012ee0b8d79000272cf872fd34dc38ce712231e62a0816a464c6cab3d1 |
|
MD5 | 059922011bde663e79807121d1d28fea |
|
BLAKE2b-256 | 03e3bd1f4dcbc263751cad25b07c62a4ffe535827d7609f46ea217a55d8cf702 |
Hashes for Advanced_Descriptors-2.2.8-cp34-cp34m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98d41c0ee7e00725efdb84be78a40a1133fbbda75a7bbc2f44a35aa7c69263c3 |
|
MD5 | 6bdd3af85012f1540a7a8516f6a5ec3f |
|
BLAKE2b-256 | b066c6b80a50a62995df8fc20e0558154c61d45e1965d70a80ff8061be891f35 |