/usr/share/pyshared/rwproperty.py is in python-rwproperty 1.0-2ubuntu5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | # Read & write properties
#
# Copyright (c) 2006 by Philipp "philiKON" von Weitershausen
# philikon@philikon.de
#
# Freely distributable under the terms of the Zope Public License, v2.1.
#
# See rwproperty.txt for detailed explanations
#
import sys
__all__ = ['getproperty', 'setproperty', 'delproperty']
class rwproperty(object):
def __new__(cls, func):
name = func.__name__
# ugly, but common hack
frame = sys._getframe(1)
locals = frame.f_locals
if name not in locals:
return cls.createProperty(func)
oldprop = locals[name]
if isinstance(oldprop, property):
return cls.enhanceProperty(oldprop, func)
raise TypeError("read & write properties cannot be mixed with "
"other attributes except regular property objects.")
# this might not be particularly elegant, but it's easy on the eyes
@staticmethod
def createProperty(func):
raise NotImplementedError
@staticmethod
def enhanceProperty(oldprop, func):
raise NotImplementedError
class getproperty(rwproperty):
@staticmethod
def createProperty(func):
return property(func)
@staticmethod
def enhanceProperty(oldprop, func):
return property(func, oldprop.fset, oldprop.fdel)
class setproperty(rwproperty):
@staticmethod
def createProperty(func):
return property(None, func)
@staticmethod
def enhanceProperty(oldprop, func):
return property(oldprop.fget, func, oldprop.fdel)
class delproperty(rwproperty):
@staticmethod
def createProperty(func):
return property(None, None, func)
@staticmethod
def enhanceProperty(oldprop, func):
return property(oldprop.fget, oldprop.fset, func)
if __name__ == "__main__":
import doctest
doctest.testfile('rwproperty.txt')
|