Package grizzled :: Module misc :: Class ReadOnly
[hide private]
[frames] | no frames]

Class ReadOnly

source code

object --+
         |
        ReadOnly

A ReadOnly object wraps another object and prevents all the contained object's fields from being written. Example use:

from grizzled.misc import ReadOnly
from grizzled.config import Configuration

config = Configuration()
config.read('/path/to/some/file')
roConfig = ReadOnly(config)

Any attempt to set fields within roConfig will cause a ReadOnlyObjectError to be raised.

The __class__ member of the instantiate ReadOnly class will be the class of the contained object, rather than ReadOnly (Configuration in the example). Similarly, the isinstance() built-in function will compare against the contained object's class. However, the type() built-in will return the ReadOnly class object.

Instance Methods [hide private]
 
__init__(self, wrapped)
Create a new ReadOnly object that wraps the wrapped object and enforces read-only access to it.
source code
 
__getattribute__(self, thing)
x.__getattribute__('name') <==> x.name
source code
 
__setattr__(self, thing, value)
x.__setattr__('name', value) <==> x.name = value
source code

Inherited from object: __delattr__, __format__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, wrapped)
(Constructor)

source code 
Create a new ReadOnly object that wraps the wrapped object and enforces read-only access to it.
Parameters:
  • wrapped (object) - the object to wrap
Overrides: object.__init__

__getattribute__(self, thing)

source code 

x.__getattribute__('name') <==> x.name

Overrides: object.__getattribute__
(inherited documentation)

__setattr__(self, thing, value)

source code 

x.__setattr__('name', value) <==> x.name = value

Overrides: object.__setattr__
(inherited documentation)