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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5a099e8cde204046b614cb8f0bd2f0b8248e47483d8cd45bd370b7c0010245e |
|
MD5 | cf18067c0bf8186d93a9fcc3ad3079ea |
|
BLAKE2b-256 | aa201d35a1a5072ac831e30bf2ca28583937195abd0b7f0eca4f5537101c83c7 |
Hashes for Advanced_Descriptors-3.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9126bf6ba197d2e597abc19dc0a87111b128d99e30638b943bdd253c8afb4afd |
|
MD5 | e1a04f8084c3cc6d86d1b2bc2e204dec |
|
BLAKE2b-256 | e860acd5c226499716aeb7025fd16878321712d023f73dded21415ac05373979 |
Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc84a845a2e1035cafca7d0f620fec9532562ece6dffb583e9a9474bbd391384 |
|
MD5 | 8a8f4ba11e9bd7f718a0b72ad58de82b |
|
BLAKE2b-256 | 4c0b16af4a518423e44cfeaa3a5d89080de8689151c22765eedd551a465a64c8 |
Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0ec7c322577d0bddbf709252ec5de2927bf3b40325f6a8cd18d639c8d885f48 |
|
MD5 | 5bd80b2b033eb4edda0197bcc4bcbcac |
|
BLAKE2b-256 | 7ebe247826407d462df1dcf3a9b99efe65711e97350d2e9e9d8f4a806c08efd6 |
Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4dd21c0a6fe47de2c7f45ddd3d2adc9871e6c43e26666e2f3f9fc495b4088f9d |
|
MD5 | 510d37db690ab112a09571aa644d5736 |
|
BLAKE2b-256 | 41c7b989a8adb0bd4dc4e4de6542a0f977f0e6225c3f030cc8831ce307184d5f |
Hashes for Advanced_Descriptors-3.0.1-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3585f8cac1eb9d3ee243294336c5931bdc230b2e7632b4f2447411e0f36ffa5c |
|
MD5 | d283d376a305fc945a30add1ef3f000a |
|
BLAKE2b-256 | 23a74a3c387678e9d85bb5dfb65d15b7c2a67c68935a4ded4ce31fe358f57635 |
Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 087d7eabd75ddaed812e51c1b7f441cdad1924dd1a2261b5359f7e093f974b0b |
|
MD5 | 2e110fc43f23e62c2af625612b032f28 |
|
BLAKE2b-256 | be4fe75a51f362329a592e0512dcfed401ec8d95f1e309d21f7efff60f159206 |
Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd462e8dea6ea92d835c155ac8f13252de766b9f0db5827a7f05fef5129f90bd |
|
MD5 | 5a27a4d130a8e465e645bb55bf8f84dc |
|
BLAKE2b-256 | 2fce35d783d7e618601c3aa05f8899357980b51219539c9bcbed70b79b14f448 |
Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c48bd730a5611dcaf79e5fbb768f6779cd45757ce7355dafd60abe35c210b4c9 |
|
MD5 | d520c72d8d8cd79a68ba50e8d375e6ec |
|
BLAKE2b-256 | 969557b6283670f79f1f3bc83a5932f4bc3ee6bcf6679e0e3934af47c9b617d5 |
Hashes for Advanced_Descriptors-3.0.1-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06539ba08868e260243f849cef190ea4c82e7aa8f36abdcfea16c1d0c241e1cc |
|
MD5 | ee883ffeb739c17ef313a753806086af |
|
BLAKE2b-256 | 9ab6a57baf4b182b4fe915be38f81f7f62fa04c6ef5a4d1fd1f40df5981730c4 |