Skip to content

Commit

Permalink
curses module moved into no yEnc check (refs #1); some pep8 fixes too
Browse files Browse the repository at this point in the history
  • Loading branch information
caronc committed Jul 25, 2016
1 parent df6c9d9 commit e722a59
Showing 1 changed file with 26 additions and 30 deletions.
56 changes: 26 additions & 30 deletions newsreap/lib/codecs/CodecYenc.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
'crc32_1': 'crc32', 'crc32_2': 'crc32',
}


class YencError(Exception):
""" Class for specific yEnc errors
"""
Expand Down Expand Up @@ -91,30 +92,31 @@ def __str__(self):
# the below code was based on the yEnc libraries. But
# the part that is blisterily fast (Written in C) will
# be writting in python (a much slower solution)

FAST_YENC_SUPPORT = False

YENC42 = ''.join(map(lambda x: chr((x-42) & 255), range(256)))

# a map that identifies all of the special keywords used by
# yEnc which need a special conversion done to them before
# We use the curses.ascii table to make our code easier to read
from curses import ascii
YENC_DECODE_SPECIAL_MAP = dict([('=%s' % chr(k+64), chr(k)) for k in (
# Non-Printable
ascii.NUL, ascii.LF, ascii.CR, ascii.SP, ascii.TAB,

# Printable
ord('.'), ord('='),
)] + [
# Ignore Types (we simply ignore these types if they are found)
(chr(ascii.LF), ''), (chr(ascii.CR), ''),
])

# Compile our map into a decode table
YENC_DECODE_SPECIAL_RE = re.compile(
r'(' + r'|'.join(YENC_DECODE_SPECIAL_MAP.keys()) + r')',
)
# A Translation Map
YENC42 = ''.join(map(lambda x: chr((x-42) & 255), range(256)))

# a map that identifies all of the special keywords used by
# yEnc which need a special conversion done to them before
# We use the curses.ascii table to make our code easier to read
from curses import ascii
YENC_DECODE_SPECIAL_MAP = dict([('=%s' % chr(k+64), chr(k)) for k in (
# Non-Printable
ascii.NUL, ascii.LF, ascii.CR, ascii.SP, ascii.TAB,

# Printable
ord('.'), ord('='),
)] + [
# Ignore Types (we simply ignore these types if they are found)
(chr(ascii.LF), ''), (chr(ascii.CR), ''),
])

# Compile our map into a decode table
YENC_DECODE_SPECIAL_RE = re.compile(
r'(' + r'|'.join(YENC_DECODE_SPECIAL_MAP.keys()) + r')',
)


class CodecYenc(CodecBase):

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


def detect(self, line, relative=True):
"""
A Simple function that can be used to determine if there is
Expand Down Expand Up @@ -186,7 +187,6 @@ def detect(self, line, relative=True):

return f_map


def decode(self, stream):
""" Decode some data and decode the data
to descriptor identified (by the stream)
Expand Down Expand Up @@ -290,7 +290,7 @@ def decode(self, stream):
except YencError:
logger.warning(
"Corruption on line %d." % \
self._lines,
self._lines,
)

# Line Tracking
Expand Down Expand Up @@ -334,14 +334,13 @@ def decode(self, stream):
# Reset part information
self._part_no = 1

if self.decoded:
if self.decoded:
# close article when complete
self.decoded.close()

# Return what we do have
return self.decoded


def reset(self):
"""
Reset our decoded content
Expand All @@ -359,14 +358,12 @@ def reset(self):
# content
self.decoded = None


def __lt__(self, other):
"""
Sorts by part number
"""
return self._part_no < other._part_no


def __str__(self):
"""
Return a printable version of the file being read
Expand All @@ -382,7 +379,6 @@ def __str__(self):
fname
)


def __repr__(self):
"""
Return a printable object
Expand Down

0 comments on commit e722a59

Please sign in to comment.