vmsobj__membuf object

(PYVMS LOGO) Python on OpenVMS

(go to: table of contents, index, list of VMS objects, prev: vmsobj_xabsum)

The vmsobj__membuf object is used to provide writeable(!) storage to other vmsobj objects (e. g. a RAB). This is necessary, because Python string objects are immutable (their contents must not be changed).


Attributes:
buffer
Returns the contents of the buffer as a Python string object. WARNING! The buffer can contain control characters (including \0).

It is (currently) not possible to store new data into the buffer with the setattr mechanism (you cannot do 'membuf.buffer = data').

size
Returns the size of the buffer in bytes.

It is not possible (and will not be) to resize the buffer by assigning a new value to the 'size' attribute. The reason is that the buffer address and its length is very likely used by/ stored inside another object (e. g. vmsobj_rab).


Methods:
zero
Immediately overwrites the contents of the buffer with \0.

Any arguments to zero() are ignored.

>>> # create a new object with pre-defined content
>>> membuf = pyvms.vmsobj__membuf ('abc123')
>>> # show contents
>>> membuf.buffer
'abc123'
>>> # overwrite contents
>>> membuf.zero()
>>> # show updated contents
>>> membuf.buffer
'\000\000\000\000\000\000'
>>>

>>> # any arguments are simply ignored
>>> membuf.zero('XYZ', 123)
>>>

>>> print membuf.zero.__doc__
None = vmsobj__membuf.zero()
Overwrite contents of buffer with NULs.
>>>

Creation:

For now the 'pyvms' module contains a function to explicitly create a vmsobj__membuf object within Python. Note that other objects - e. g. vmsobj_rab - can implicitly create a vmsobj__membuf object! See the description of its "RBF" and "UBF" attributes.

Examples:

>>> import pyvms

>>> # create a zero-filled buffer
>>>
>>> membuf = pyvms.vmsobj__membuf (5)
>>> type (membuf)
<type 'vmsobj__membuf'>
>>> membuf
<vmsobj__membuf, buffer at 0x00213f78>
>>> membuf.size
5
>>> membuf.buffer
'\000\000\000\000\000'
>>>


>>> # create a string-filled buffer
>>>
>>> membuf = pyvms.vmsobj__membuf ('data')
>>> type (membuf)
<type 'vmsobj__membuf'>
>>> membuf
<vmsobj__membuf, buffer at 0x00214628>
>>> membuf.size
4
>>> membuf.buffer
'data'
>>>


>>> # invalid attribute access
>>> membuf.bad_attr
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: non-existing vmsobj__membuf attribute
>>>
>>> membuf.size = 9
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: non-existing or readonly vmsobj__membuf attribute
>>> membuf.buffer = 'x'
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: non-existing or readonly vmsobj__membuf attribute
>>> membuf.no_attr = 0
Traceback (innermost last):
  File "<stdin>", line 1, in ?
AttributeError: non-existing or readonly vmsobj__membuf attribute
>>>
... @@
(go to: table of contents, index, list of VMS objects, prev: vmsobj_xabsum)

03-MAR-1999 ZE.