File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -131,20 +131,26 @@ def write(self, data):
131131 todo = (datalen / 3 )* 3
132132 data = self .data [:todo ]
133133 self .data = self .data [todo :]
134+ if not data :
135+ return
134136 self .hqxdata = self .hqxdata + binascii .b2a_hqx (data )
135- while len (self .hqxdata ) > self .linelen :
136- self .ofp .write (self .hqxdata [:self .linelen ]+ '\n ' )
137- self .hqxdata = self .hqxdata [self .linelen :]
137+ self ._flush (0 )
138+
139+ def _flush (self , force ):
140+ first = 0
141+ while first <= len (self .hqxdata )- self .linelen :
142+ last = first + self .linelen
143+ self .ofp .write (self .hqxdata [first :last ]+ '\n ' )
138144 self .linelen = LINELEN
145+ first = last
146+ self .hqxdata = self .hqxdata [first :]
147+ if force :
148+ self .ofp .write (self .hqxdata + ':\n ' )
139149
140150 def close (self ):
141151 if self .data :
142152 self .hqxdata = self .hqxdata + binascii .b2a_hqx (self .data )
143- while self .hqxdata :
144- self .ofp .write (self .hqxdata [:self .linelen ])
145- self .hqxdata = self .hqxdata [self .linelen :]
146- self .linelen = LINELEN
147- self .ofp .write (':\n ' )
153+ self ._flush (1 )
148154 self .ofp .close ()
149155 del self .ofp
150156
@@ -290,7 +296,6 @@ def read(self, totalwtd):
290296 while 1 :
291297 try :
292298 decdatacur , self .eof = binascii .a2b_hqx (data )
293- if self .eof : print 'EOF'
294299 break
295300 except binascii .Incomplete :
296301 pass
You can’t perform that action at this time.
0 commit comments