mirror of
https://github.com/python/cpython.git
synced 2025-08-31 14:07:50 +00:00
Merged in Jack's fixes. This brings some lines beyond 79 chars again;
I'll clean that up later. Also corrected a mistake introduced by the previous reformatting: an 'else' belonging to a 'for' was accidentally reindented to belong to the 'if' inside the 'for'. Note that the module uses inconsistent indentation -- most code is indented with 8 spaces, but some of the reformatted code uses 4 spaces. I'll fix this later in the promised cleanup pass.
This commit is contained in:
parent
838cb28290
commit
50b82e8e18
1 changed files with 32 additions and 17 deletions
|
@ -93,7 +93,7 @@ else:
|
||||||
if not c in string.whitespace \
|
if not c in string.whitespace \
|
||||||
and (c<' ' or ord(c) > 0177):
|
and (c<' ' or ord(c) > 0177):
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
finfo.Type = 'TEXT'
|
finfo.Type = 'TEXT'
|
||||||
fp.seek(0, 2)
|
fp.seek(0, 2)
|
||||||
dsize = fp.tell()
|
dsize = fp.tell()
|
||||||
|
@ -336,28 +336,36 @@ class _Rledecoderengine:
|
||||||
return rv
|
return rv
|
||||||
|
|
||||||
def _fill(self, wtd):
|
def _fill(self, wtd):
|
||||||
#
|
self.pre_buffer = self.pre_buffer + self.ifp.read(wtd+4)
|
||||||
# Obfuscated code ahead. We keep at least one byte in the
|
|
||||||
# pre_buffer, so we don't stumble over an orphaned RUNCHAR
|
|
||||||
# later on. If the last or second-last char is a RUNCHAR
|
|
||||||
# we keep more bytes.
|
|
||||||
#
|
|
||||||
self.pre_buffer = self.pre_buffer + self.ifp.read(wtd+2)
|
|
||||||
if self.ifp.eof:
|
if self.ifp.eof:
|
||||||
self.post_buffer = self.post_buffer + \
|
self.post_buffer = self.post_buffer + \
|
||||||
binascii.rledecode_hqx(self.pre_buffer)
|
binascii.rledecode_hqx(self.pre_buffer)
|
||||||
self.pre_buffer = ''
|
self.pre_buffer = ''
|
||||||
return
|
return
|
||||||
|
|
||||||
lastrle = string.rfind(self.pre_buffer, RUNCHAR)
|
#
|
||||||
if lastrle > 0 and lastrle == len(self.pre_buffer)-1:
|
# Obfuscated code ahead. We have to take care that we don't
|
||||||
# Last byte is an RLE, keep two bytes
|
# end up with an orphaned RUNCHAR later on. So, we keep a couple
|
||||||
mark = len(self.pre_buffer)-2
|
# of bytes in the buffer, depending on what the end of
|
||||||
elif lastrle > 0 and lastrle == len(self.pre_buffer)-2:
|
# the buffer looks like:
|
||||||
# second-last byte is an RLE. Decode all.
|
# '\220\0\220' - Keep 3 bytes: repeated \220 (escaped as \220\0)
|
||||||
mark = len(self.pre_buffer)
|
# '?\220' - Keep 2 bytes: repeated something-else
|
||||||
|
# '\220\0' - Escaped \220: Keep 2 bytes.
|
||||||
|
# '?\220?' - Complete repeat sequence: decode all
|
||||||
|
# otherwise: keep 1 byte.
|
||||||
|
#
|
||||||
|
mark = len(self.pre_buffer)
|
||||||
|
if self.pre_buffer[-3:] == RUNCHAR + '\0' + RUNCHAR:
|
||||||
|
mark = mark - 3
|
||||||
|
elif self.pre_buffer[-1] == RUNCHAR:
|
||||||
|
mark = mark - 2
|
||||||
|
elif self.pre_buffer[-2:] == RUNCHAR + '\0':
|
||||||
|
mark = mark - 2
|
||||||
|
elif self.pre_buffer[-2] == RUNCHAR:
|
||||||
|
pass # Decode all
|
||||||
else:
|
else:
|
||||||
mark = len(self.pre_buffer)-1
|
mark = mark - 1
|
||||||
|
|
||||||
self.post_buffer = self.post_buffer + \
|
self.post_buffer = self.post_buffer + \
|
||||||
binascii.rledecode_hqx(self.pre_buffer[:mark])
|
binascii.rledecode_hqx(self.pre_buffer[:mark])
|
||||||
self.pre_buffer = self.pre_buffer[mark:]
|
self.pre_buffer = self.pre_buffer[mark:]
|
||||||
|
@ -376,6 +384,10 @@ class HexBin:
|
||||||
ch = ifp.read(1)
|
ch = ifp.read(1)
|
||||||
if not ch:
|
if not ch:
|
||||||
raise Error, "No binhex data found"
|
raise Error, "No binhex data found"
|
||||||
|
# Cater for \r\n terminated lines (which show up as \n\r, hence
|
||||||
|
# all lines start with \r)
|
||||||
|
if ch == '\r':
|
||||||
|
continue
|
||||||
if ch == ':':
|
if ch == ':':
|
||||||
break
|
break
|
||||||
if ch != '\n':
|
if ch != '\n':
|
||||||
|
@ -429,8 +441,11 @@ class HexBin:
|
||||||
n = min(n, self.dlen)
|
n = min(n, self.dlen)
|
||||||
else:
|
else:
|
||||||
n = self.dlen
|
n = self.dlen
|
||||||
|
rv = ''
|
||||||
|
while len(rv) < n:
|
||||||
|
rv = rv + self._read(n-len(rv))
|
||||||
self.dlen = self.dlen - n
|
self.dlen = self.dlen - n
|
||||||
return self._read(n)
|
return rv
|
||||||
|
|
||||||
def close_data(self):
|
def close_data(self):
|
||||||
if self.state != _DID_HEADER:
|
if self.state != _DID_HEADER:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue