Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Private Member Functions
binhex.BinHex Class Reference

List of all members.

Public Member Functions

def __init__
def write
def close_data
def write_rsrc
def close

Public Attributes

 ofp
 crc
 dlen
 rlen
 state

Private Member Functions

def _writeinfo
def _write
def _writecrc

Detailed Description

Definition at line 139 of file binhex.py.


Constructor & Destructor Documentation

def binhex.BinHex.__init__ (   self,
  name_finfo_dlen_rlen,
  ofp 
)

Definition at line 140 of file binhex.py.

00140 
00141     def __init__(self, name_finfo_dlen_rlen, ofp):
00142         name, finfo, dlen, rlen = name_finfo_dlen_rlen
00143         close_on_error = False
00144         if isinstance(ofp, str):
00145             ofname = ofp
00146             ofp = io.open(ofname, 'wb')
00147             close_on_error = True
00148         try:
00149             ofp.write(b'(This file must be converted with BinHex 4.0)\r\r:')
00150             hqxer = _Hqxcoderengine(ofp)
00151             self.ofp = _Rlecoderengine(hqxer)
00152             self.crc = 0
00153             if finfo is None:
00154                 finfo = FInfo()
00155             self.dlen = dlen
00156             self.rlen = rlen
00157             self._writeinfo(name, finfo)
00158             self.state = _DID_HEADER
00159         except:
00160             if close_on_error:
00161                 ofp.close()
00162             raise

Here is the caller graph for this function:


Member Function Documentation

def binhex.BinHex._write (   self,
  data 
) [private]

Definition at line 182 of file binhex.py.

00182 
00183     def _write(self, data):
00184         self.crc = binascii.crc_hqx(data, self.crc)
00185         self.ofp.write(data)

Here is the caller graph for this function:

def binhex.BinHex._writecrc (   self) [private]

Definition at line 186 of file binhex.py.

00186 
00187     def _writecrc(self):
00188         # XXXX Should this be here??
00189         # self.crc = binascii.crc_hqx('\0\0', self.crc)
00190         if self.crc < 0:
00191             fmt = '>h'
00192         else:
00193             fmt = '>H'
00194         self.ofp.write(struct.pack(fmt, self.crc))
00195         self.crc = 0

Here is the caller graph for this function:

def binhex.BinHex._writeinfo (   self,
  name,
  finfo 
) [private]

Definition at line 163 of file binhex.py.

00163 
00164     def _writeinfo(self, name, finfo):
00165         nl = len(name)
00166         if nl > 63:
00167             raise Error('Filename too long')
00168         d = bytes([nl]) + name.encode("latin-1") + b'\0'
00169         tp, cr = finfo.Type, finfo.Creator
00170         if isinstance(tp, str):
00171             tp = tp.encode("latin-1")
00172         if isinstance(cr, str):
00173             cr = cr.encode("latin-1")
00174         d2 = tp + cr
00175 
00176         # Force all structs to be packed with big-endian
00177         d3 = struct.pack('>h', finfo.Flags)
00178         d4 = struct.pack('>ii', self.dlen, self.rlen)
00179         info = d + d2 + d3 + d4
00180         self._write(info)
00181         self._writecrc()

Here is the call graph for this function:

def binhex.BinHex.close (   self)

Definition at line 216 of file binhex.py.

00216 
00217     def close(self):
00218         if self.state < _DID_DATA:
00219             self.close_data()
00220         if self.state != _DID_DATA:
00221             raise Error('Close at the wrong time')
00222         if self.rlen != 0:
00223             raise Error("Incorrect resource-datasize, diff=%r" % (self.rlen,))
00224         self._writecrc()
00225         self.ofp.close()
00226         self.state = None
00227         del self.ofp

Here is the call graph for this function:

def binhex.BinHex.close_data (   self)

Definition at line 202 of file binhex.py.

00202 
00203     def close_data(self):
00204         if self.dlen != 0:
00205             raise Error('Incorrect data size, diff=%r' % (self.rlen,))
00206         self._writecrc()
00207         self.state = _DID_DATA

Here is the call graph for this function:

Here is the caller graph for this function:

def binhex.BinHex.write (   self,
  data 
)

Definition at line 196 of file binhex.py.

00196 
00197     def write(self, data):
00198         if self.state != _DID_HEADER:
00199             raise Error('Writing data at the wrong time')
00200         self.dlen = self.dlen - len(data)
00201         self._write(data)

Here is the call graph for this function:

def binhex.BinHex.write_rsrc (   self,
  data 
)

Definition at line 208 of file binhex.py.

00208 
00209     def write_rsrc(self, data):
00210         if self.state < _DID_DATA:
00211             self.close_data()
00212         if self.state != _DID_DATA:
00213             raise Error('Writing resource data at the wrong time')
00214         self.rlen = self.rlen - len(data)
00215         self._write(data)

Here is the call graph for this function:


Member Data Documentation

Definition at line 151 of file binhex.py.

Definition at line 154 of file binhex.py.

Definition at line 150 of file binhex.py.

Definition at line 155 of file binhex.py.

Definition at line 157 of file binhex.py.


The documentation for this class was generated from the following file: