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.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2df092f1bad64bc9c22bbc0a045f5054fb71faeda5d713d5fe7ef6e2794d53d9 |
|
MD5 | da73c0a720d239d67e47c47f78e5918c |
|
BLAKE2b-256 | e21074e98e1d2549a10290187254dd6e8936521fb61c8eba8b07e9ba10a04259 |
Hashes for Advanced_Descriptors-3.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3cff3fae846089f20044fd9e23f2a703a395402e2ce8e2dd6373a19d7d9cc743 |
|
MD5 | 5d618bf7a4698986d0eaa5c438141848 |
|
BLAKE2b-256 | fd8caddfee43eeb12c8c483e51fddbd6111d863b85d2c93107b84cb271124aa4 |
Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 752b30646268903e875c985d468d83c82336a450f4dff91527640a072ab21fa0 |
|
MD5 | 1b4c714466e183609ececf1d49120df5 |
|
BLAKE2b-256 | 3088b281c0a4004fec84d73ac9cbf4f7504adfecb7f146ec38b21021885ec99e |
Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67557d42f80e459678eeb838d368cf506fc6837f307fa3dc2a210f55f55ff226 |
|
MD5 | 0210c2f3a611370b023e996ddffea806 |
|
BLAKE2b-256 | ec1efa3fd3c11f3737d7098295b0833f73a5a03f2567fe808512654bac7f6631 |
Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2bf4d1f24df3119a997046b299efd3e6637df131f386c2cdc70f2f81971526fc |
|
MD5 | c919321085ab29cb0fee8ac0d283a017 |
|
BLAKE2b-256 | 297cd229d1899d509d1e48de2708f506a08236556f66c54695178178b0e8ce27 |
Hashes for Advanced_Descriptors-3.0.0-cp37-cp37m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ed2e6d42557a6d527a0c7e5df87fbe64d7ac1d2db00ed09a542b914d99a2149 |
|
MD5 | f7fcb9de227be01be6e446ca7f280860 |
|
BLAKE2b-256 | 0be87de5b35e809fde3a19964289aabfdb88a826263b407cffdf74ca585fbd9b |
Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 199969a260ced746f67757652d8f789b55779f23d18e88231ad997026440733e |
|
MD5 | c758bdbaf5b8aa55ec13f02e3590c394 |
|
BLAKE2b-256 | 6d18ca696bda448c4c6b4e0fb7d75a6b874f79a9617394e9b55db48a52844c27 |
Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a493a0d5c15e948a36abc303193f352fef003889d98a46eb8d1150bc3a6c73f1 |
|
MD5 | abe3a773fca62f90a701e7434925bb2c |
|
BLAKE2b-256 | 9bfee5995dd5dd1bc805d6715e6a29f2efa13c384d2ae4c051269b5d82c2f736 |
Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b92bfafec0a058f04a413a53bc3dac4340c85c1bb15beb448052df96d4455042 |
|
MD5 | a7d47feda3ef6bbcb53e3462e18ce7c1 |
|
BLAKE2b-256 | 4c6e781249c558a7540731bdd1b1ac60c2a7fc348179364cca81b0ffb4f99d77 |
Hashes for Advanced_Descriptors-3.0.0-cp36-cp36m-manylinux1_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd409e57cbffd7a336de6dbe90a146ee996ee5beb28470bc0500abf13193bd6c |
|
MD5 | fcd48a6a4fb6b68f943459de5893605f |
|
BLAKE2b-256 | 7df7ef426835c38bd786691d9166c00d0fea8cda7035f6a18b207f9fa5ef0e9f |