Back to index

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

List of all members.

Public Member Functions

def __init__
def read
def close_data
def read_rsrc
def close

Public Attributes

 ifp
 crc
 dlen
 rlen
 FName
 FInfo
 state

Private Member Functions

def _read
def _checkcrc
def _readheader

Detailed Description

Definition at line 346 of file binhex.py.


Constructor & Destructor Documentation

def binhex.HexBin.__init__ (   self,
  ifp 
)

Definition at line 347 of file binhex.py.

00347 
00348     def __init__(self, ifp):
00349         if isinstance(ifp, str):
00350             ifp = io.open(ifp, 'rb')
00351         #
00352         # Find initial colon.
00353         #
00354         while True:
00355             ch = ifp.read(1)
00356             if not ch:
00357                 raise Error("No binhex data found")
00358             # Cater for \r\n terminated lines (which show up as \n\r, hence
00359             # all lines start with \r)
00360             if ch == b'\r':
00361                 continue
00362             if ch == b':':
00363                 break
00364 
00365         hqxifp = _Hqxdecoderengine(ifp)
00366         self.ifp = _Rledecoderengine(hqxifp)
00367         self.crc = 0
00368         self._readheader()

Here is the caller graph for this function:


Member Function Documentation

def binhex.HexBin._checkcrc (   self) [private]

Definition at line 374 of file binhex.py.

00374 
00375     def _checkcrc(self):
00376         filecrc = struct.unpack('>h', self.ifp.read(2))[0] & 0xffff
00377         #self.crc = binascii.crc_hqx('\0\0', self.crc)
00378         # XXXX Is this needed??
00379         self.crc = self.crc & 0xffff
00380         if filecrc != self.crc:
00381             raise Error('CRC error, computed %x, read %x'
00382                         % (self.crc, filecrc))
00383         self.crc = 0

Here is the caller graph for this function:

def binhex.HexBin._read (   self,
  len 
) [private]

Definition at line 369 of file binhex.py.

00369 
00370     def _read(self, len):
00371         data = self.ifp.read(len)
00372         self.crc = binascii.crc_hqx(data, self.crc)
00373         return data

Here is the caller graph for this function:

def binhex.HexBin._readheader (   self) [private]

Definition at line 384 of file binhex.py.

00384 
00385     def _readheader(self):
00386         len = self._read(1)
00387         fname = self._read(ord(len))
00388         rest = self._read(1 + 4 + 4 + 2 + 4 + 4)
00389         self._checkcrc()
00390 
00391         type = rest[1:5]
00392         creator = rest[5:9]
00393         flags = struct.unpack('>h', rest[9:11])[0]
00394         self.dlen = struct.unpack('>l', rest[11:15])[0]
00395         self.rlen = struct.unpack('>l', rest[15:19])[0]
00396 
00397         self.FName = fname
00398         self.FInfo = FInfo()
00399         self.FInfo.Creator = creator
00400         self.FInfo.Type = type
00401         self.FInfo.Flags = flags
00402 
00403         self.state = _DID_HEADER

Here is the call graph for this function:

def binhex.HexBin.close (   self)

Definition at line 439 of file binhex.py.

00439 
00440     def close(self):
00441         if self.rlen:
00442             dummy = self.read_rsrc(self.rlen)
00443         self._checkcrc()
00444         self.state = _DID_RSRC
00445         self.ifp.close()

Here is the call graph for this function:

def binhex.HexBin.close_data (   self)

Definition at line 418 of file binhex.py.

00418 
00419     def close_data(self):
00420         if self.state != _DID_HEADER:
00421             raise Error('close_data at wrong time')
00422         if self.dlen:
00423             dummy = self._read(self.dlen)
00424         self._checkcrc()
00425         self.state = _DID_DATA

Here is the call graph for this function:

Here is the caller graph for this function:

def binhex.HexBin.read (   self,
  n 
)

Definition at line 404 of file binhex.py.

00404 
00405     def read(self, *n):
00406         if self.state != _DID_HEADER:
00407             raise Error('Read data at wrong time')
00408         if n:
00409             n = n[0]
00410             n = min(n, self.dlen)
00411         else:
00412             n = self.dlen
00413         rv = b''
00414         while len(rv) < n:
00415             rv = rv + self._read(n-len(rv))
00416         self.dlen = self.dlen - n
00417         return rv

Here is the call graph for this function:

Here is the caller graph for this function:

def binhex.HexBin.read_rsrc (   self,
  n 
)

Definition at line 426 of file binhex.py.

00426 
00427     def read_rsrc(self, *n):
00428         if self.state == _DID_HEADER:
00429             self.close_data()
00430         if self.state != _DID_DATA:
00431             raise Error('Read resource data at wrong time')
00432         if n:
00433             n = n[0]
00434             n = min(n, self.rlen)
00435         else:
00436             n = self.rlen
00437         self.rlen = self.rlen - n
00438         return self._read(n)

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 366 of file binhex.py.

Definition at line 393 of file binhex.py.

Definition at line 397 of file binhex.py.

Definition at line 396 of file binhex.py.

Definition at line 365 of file binhex.py.

Definition at line 394 of file binhex.py.

Definition at line 402 of file binhex.py.


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