summaryrefslogtreecommitdiffstats
path: root/Lib/binhex.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1996-03-25 18:54:33 (GMT)
committerGuido van Rossum <guido@python.org>1996-03-25 18:54:33 (GMT)
commitcce074e2730809aa1178135e1a0b2bdfba491611 (patch)
treecc4f3c04d39fcdbfeae91a73893aaa900b673f26 /Lib/binhex.py
parent975aa22bddeb096fdad8d8e00de018fa45f18ad2 (diff)
downloadcpython-cce074e2730809aa1178135e1a0b2bdfba491611.zip
cpython-cce074e2730809aa1178135e1a0b2bdfba491611.tar.gz
cpython-cce074e2730809aa1178135e1a0b2bdfba491611.tar.bz2
new binhex from Jack (much faster)
Diffstat (limited to 'Lib/binhex.py')
-rw-r--r--Lib/binhex.py23
1 files changed, 14 insertions, 9 deletions
diff --git a/Lib/binhex.py b/Lib/binhex.py
index 9e20d87..cdb961e 100644
--- a/Lib/binhex.py
+++ b/Lib/binhex.py
@@ -131,20 +131,26 @@ class _Hqxcoderengine:
todo = (datalen/3)*3
data = self.data[:todo]
self.data = self.data[todo:]
+ if not data:
+ return
self.hqxdata = self.hqxdata + binascii.b2a_hqx(data)
- while len(self.hqxdata) > self.linelen:
- self.ofp.write(self.hqxdata[:self.linelen]+'\n')
- self.hqxdata = self.hqxdata[self.linelen:]
+ self._flush(0)
+
+ def _flush(self, force):
+ first = 0
+ while first <= len(self.hqxdata)-self.linelen:
+ last = first + self.linelen
+ self.ofp.write(self.hqxdata[first:last]+'\n')
self.linelen = LINELEN
+ first = last
+ self.hqxdata = self.hqxdata[first:]
+ if force:
+ self.ofp.write(self.hqxdata + ':\n')
def close(self):
if self.data:
self.hqxdata = self.hqxdata + binascii.b2a_hqx(self.data)
- while self.hqxdata:
- self.ofp.write(self.hqxdata[:self.linelen])
- self.hqxdata = self.hqxdata[self.linelen:]
- self.linelen = LINELEN
- self.ofp.write(':\n')
+ self._flush(1)
self.ofp.close()
del self.ofp
@@ -290,7 +296,6 @@ class _Hqxdecoderengine:
while 1:
try:
decdatacur, self.eof = binascii.a2b_hqx(data)
- if self.eof: print 'EOF'
break
except binascii.Incomplete:
pass