Skip to content

Commit e722a59

Browse files
committed
curses module moved into no yEnc check (refs #1); some pep8 fixes too
1 parent df6c9d9 commit e722a59

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

newsreap/lib/codecs/CodecYenc.py

+26-30
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
'crc32_1': 'crc32', 'crc32_2': 'crc32',
6363
}
6464

65+
6566
class YencError(Exception):
6667
""" Class for specific yEnc errors
6768
"""
@@ -91,30 +92,31 @@ def __str__(self):
9192
# the below code was based on the yEnc libraries. But
9293
# the part that is blisterily fast (Written in C) will
9394
# be writting in python (a much slower solution)
94-
9595
FAST_YENC_SUPPORT = False
9696

97-
YENC42 = ''.join(map(lambda x: chr((x-42) & 255), range(256)))
98-
99-
# a map that identifies all of the special keywords used by
100-
# yEnc which need a special conversion done to them before
101-
# We use the curses.ascii table to make our code easier to read
102-
from curses import ascii
103-
YENC_DECODE_SPECIAL_MAP = dict([('=%s' % chr(k+64), chr(k)) for k in (
104-
# Non-Printable
105-
ascii.NUL, ascii.LF, ascii.CR, ascii.SP, ascii.TAB,
106-
107-
# Printable
108-
ord('.'), ord('='),
109-
)] + [
110-
# Ignore Types (we simply ignore these types if they are found)
111-
(chr(ascii.LF), ''), (chr(ascii.CR), ''),
112-
])
113-
114-
# Compile our map into a decode table
115-
YENC_DECODE_SPECIAL_RE = re.compile(
116-
r'(' + r'|'.join(YENC_DECODE_SPECIAL_MAP.keys()) + r')',
117-
)
97+
# A Translation Map
98+
YENC42 = ''.join(map(lambda x: chr((x-42) & 255), range(256)))
99+
100+
# a map that identifies all of the special keywords used by
101+
# yEnc which need a special conversion done to them before
102+
# We use the curses.ascii table to make our code easier to read
103+
from curses import ascii
104+
YENC_DECODE_SPECIAL_MAP = dict([('=%s' % chr(k+64), chr(k)) for k in (
105+
# Non-Printable
106+
ascii.NUL, ascii.LF, ascii.CR, ascii.SP, ascii.TAB,
107+
108+
# Printable
109+
ord('.'), ord('='),
110+
)] + [
111+
# Ignore Types (we simply ignore these types if they are found)
112+
(chr(ascii.LF), ''), (chr(ascii.CR), ''),
113+
])
114+
115+
# Compile our map into a decode table
116+
YENC_DECODE_SPECIAL_RE = re.compile(
117+
r'(' + r'|'.join(YENC_DECODE_SPECIAL_MAP.keys()) + r')',
118+
)
119+
118120

119121
class CodecYenc(CodecBase):
120122

@@ -133,7 +135,6 @@ def __init__(self, descriptor=None, tmp_dir=None, *args, **kwargs):
133135
# content
134136
self.decoded = None
135137

136-
137138
def detect(self, line, relative=True):
138139
"""
139140
A Simple function that can be used to determine if there is
@@ -186,7 +187,6 @@ def detect(self, line, relative=True):
186187

187188
return f_map
188189

189-
190190
def decode(self, stream):
191191
""" Decode some data and decode the data
192192
to descriptor identified (by the stream)
@@ -290,7 +290,7 @@ def decode(self, stream):
290290
except YencError:
291291
logger.warning(
292292
"Corruption on line %d." % \
293-
self._lines,
293+
self._lines,
294294
)
295295

296296
# Line Tracking
@@ -334,14 +334,13 @@ def decode(self, stream):
334334
# Reset part information
335335
self._part_no = 1
336336

337-
if self.decoded:
337+
if self.decoded:
338338
# close article when complete
339339
self.decoded.close()
340340

341341
# Return what we do have
342342
return self.decoded
343343

344-
345344
def reset(self):
346345
"""
347346
Reset our decoded content
@@ -359,14 +358,12 @@ def reset(self):
359358
# content
360359
self.decoded = None
361360

362-
363361
def __lt__(self, other):
364362
"""
365363
Sorts by part number
366364
"""
367365
return self._part_no < other._part_no
368366

369-
370367
def __str__(self):
371368
"""
372369
Return a printable version of the file being read
@@ -382,7 +379,6 @@ def __str__(self):
382379
fname
383380
)
384381

385-
386382
def __repr__(self):
387383
"""
388384
Return a printable object

0 commit comments

Comments
 (0)