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

Class ReadOnly

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
 
__init__(self, wrapped)
Create a new ReadOnly object that wraps the wrapped object and enforces read-only access to it.
 
__getattribute__(self, thing)
x.__getattribute__('name') <==> x.name
 
__setattr__(self, thing, value)
x.__setattr__('name', value) <==> x.name = value

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

Properties

Inherited from object: __class__

Method Details

__init__(self, wrapped)
(Constructor)

 
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)

 
x.__getattribute__('name') <==> x.name
Overrides: object.__getattribute__
(inherited documentation)

__setattr__(self, thing, value)

 
x.__setattr__('name', value) <==> x.name = value
Overrides: object.__setattr__
(inherited documentation)