pyzfile package

Module contents

class pyzfile.ZFile(filename: str, mode: str, encoding: Optional[str] = None)[source]

Bases: object

amrc()[source]

Returns the __amrc structure defined in stdio.h to help you determine errors resulting from an I/O operation. See the z/OS C/C++ programming guide for documentation on the content of this stucture.

{'amrc_noseek_to_seek': 'NOSWITCH',
 'code': {
     'abend': {'rc': 0, 'syscode': 0},
     'alloc': {'svc_error': 0, 'svc_info': 0},
     'error': 0,
     'feedback': {'fdbk': 0, 'rc': 0, 'rtncd': 0}
  },
 'last_op': 'VSAM_OPEN_KSDS',
 'msg': {'len': 0, 'parmr0': 0, 'parmr1': 0, 'str': '', 'xrba': 0},
 'rba': 0
}
Returns:

a dict containing fields from the __amrc structure.

close()[source]

Closes the file.

eof()[source]

Determines if the file has reached end-of-file.

Returns:

True if the file has reaced end-of-file, otherwise False.

error()[source]

Determines if the file error indicator is set.

Returns:

True if the file error indicator is set, otherwise False.

getpos()[source]

Returns the current file position.

Returns:

The current file position.

info()[source]

Returns a dict with information about the file. See the z/OS C/C++ runtime reference for the fldata() function and the fldata_t structure.

{'access_method': 'UNSPEC',
 'blksize': 32756,
 'device': 'DISK',
 'dsname': 'TS8004.TXC.REGISTER',
 'dsorgConcat': False,
 'dsorgHFS': False,
 'dsorgHiper': False,
 'dsorgMem': False,
 'dsorgPDE': False,
 'dsorgPDSdir': False,
 'dsorgPDSmem': False,
 'dsorgPO': False,
 'dsorgPS': False,
 'dsorgTemp': False,
 'dsorgVSAM': True,
 'maxreclen': 32756,
 'mode': {'append': False, 'read': True, 'update': False, 'write': False},
 'noseek_to_seek': 'NOSWITCH',
 'openmode': 'RECORD',
 'recfmASA': False,
 'recfmB': False,
 'recfmBlk': False,
 'recfmF': False,
 'recfmM': False,
 'recfmS': False,
 'recfmU': True,
 'recfmV': False,
 'vsamRKP': 0,
 'vsamRLS': 'NORLS',
 'vsamkeylen': 64,
 'vsamtype': 'KSDS'}
Returns:

A dict containing information from the fldata_t structure.

locate(rec: str | bytes, option: str, length: Optional[int] = None) bool[source]

Locates a record in a VSAM file.

Parameters:
  • rec – The record to locate

  • option – An option from the following list: key_first, key_last, key_eq, key_eq_bwd, key_ge, rba_eq, rba_eq_bwd

  • length – The length of the record. If this argument is not specified the length of record is used.

Returns:

True if the record was located, otherwise False.

rba()[source]

Returns the current RBA (relative byte address) for the VSAM file.

Returns:

The current RBA for the VSAM file.

read(length: Optional[int] = None) None | str | bytes[source]

Reads a record from the file.

Parameters:

length – The number of bytes to read. If this argument is not specified then the length is set to the maximum buffer size of 65536.

Returns:

If encoding has been specified then a UTF-8 string is returned, otherwise a bytes record. If end-of-file has been reached None is returned.

readlines()[source]

Reads the entire file into a list of strings.

Returns:

A list of strings containing the contents of the file.

reads()[source]

Reads the entire file into a string

Returns:

A string containing the content of the file

seek(offset: int, whence: str)[source]

Sets the file position.

Parameters:
  • offset – The offset to position to

  • whence – The start position: SEEK_SET, SEEK_CUR, SEEK_END.

setpos(pos)[source]

Sets the current file position to pos. The position must have been previously obtained by calling `getpos`

Parameters:

pos

Returns:

update(rec, length: Optional[int] = None)[source]

Replaces the last record read from a VSAM file with the contents of rec.

Parameters:
  • rec – The record to replace.

  • length – The length of the record. If this argument is not specified then the length of rec is used implicitly.

Returns:

True if the record was updated, otherwise False.

write(rec, length: Optional[int] = None)[source]

Writes a record to the file.

Parameters:
  • rec – The number of bytes to write. If encoding has been specified the record is encoded using the codeset.

  • length – The number of bytes to write. If this argument is not specified then the length is set to the length of rec.

Raises:

ZFileError if an error occurs writing the record.

exception pyzfile.ZFileError(message: str, amrc: Optional[dict] = None)[source]

Bases: Exception

ZFile exception

amrc()[source]

Returns the amrc dict at the time of error. Refer to the z/OS C/C++ programming guide for a description of the fields in the __amrc structure.

Returns:

The __amrc structure at the time of error.

pyzfile.open_zfile(filename: str, mode: str, encoding: Optional[str] = None) ZFile[source]

Factory function to instantiate and open a ZFile.

Parameters:
  • filename – The name of the file to open

  • mode – The open mode. For example, r, rb, w, wb

  • encoding – The file encoding

Returns:

A new ZFile