# Path: newsreap/NNTPSettings.py
# DEFAULT_TMP_DIR = expanduser(join('~', '.config', 'newsreap', 'var', 'tmp'))
# 
# Path: newsreap/Utils.py
# def mkdir(name, perm=0775):
#     """
#     A more contained wrapper to directory management
#     """
#     attempt = 3
#     if isdir(name):
#         return True
# 
#     while attempt > 0:
#         try:
#             makedirs(name, perm)
#             logger.debug('Created directory: %s' % name)
#             return True
# 
#         except OSError, e:
#             if e[0] == errno.EEXIST:
#                 # directory exists; this is okay
#                 return isdir(name)
# 
#             logger.debug('Created directory %s exception: %s' % (
#                 name, e,
#             ))
# 
#         # racing condition; just try again
#         attempt -= 1
# 
#     # To many attempts... fail
#     # ... fall through...
#     return False
# 
# Path: newsreap/Logging.py
# NEWSREAP_CODEC = '%s.codec' % NEWSREAP_LOGGER


import errno
import logging
from binascii import crc32
from os.path import isdir
from os.path import abspath
from os.path import expanduser
from newsreap.NNTPSettings import DEFAULT_TMP_DIR
from newsreap.Utils import mkdir
from gevent import sleep
from newsreap.Logging import NEWSREAP_CODEC
# -*- coding: utf-8 -*-
#
# A Base Codec Class for deciphering data read from the an NNTP Server
#
# Copyright (C) 2015-2016 Chris Caron <lead2gold@gmail.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.



# Logging
logger = logging.getLogger(NEWSREAP_CODEC)

# Adapted from python-yenc but following suite to make everything behave the
# same way
E_ERROR = 64
E_CRC32 = 65

# The mask to apply to all CRC checking
BIN_MASK = 0xffffffffL



# Path: newsreap/NNTPSettings.py
# DEFAULT_TMP_DIR = expanduser(join('~', '.config', 'newsreap', 'var', 'tmp'))
# 
# Path: newsreap/Utils.py
# def mkdir(name, perm=0775):
#     """
#     A more contained wrapper to directory management
#     """
#     attempt = 3
#     if isdir(name):
#         return True
# 
#     while attempt > 0:
#         try:
#             makedirs(name, perm)
#             logger.debug('Created directory: %s' % name)
#             return True
# 
#         except OSError, e:
#             if e[0] == errno.EEXIST:
#                 # directory exists; this is okay
#                 return isdir(name)
# 
#             logger.debug('Created directory %s exception: %s' % (
#                 name, e,
#             ))
# 
#         # racing condition; just try again
#         attempt -= 1
# 
#     # To many attempts... fail
#     # ... fall through...
#     return False
# 
# Path: newsreap/Logging.py
# NEWSREAP_CODEC = '%s.codec' % NEWSREAP_LOGGER


# Path: newsreap/codecs/CodecBase.py
import errno
import logging
from binascii import crc32
from os.path import isdir
from os.path import abspath
from os.path import expanduser
from newsreap.NNTPSettings import DEFAULT_TMP_DIR
from newsreap.Utils import mkdir
from gevent import sleep
from newsreap.Logging import NEWSREAP_CODEC

# -*- coding: utf-8 -*-
#
# A Base Codec Class for deciphering data read from the an NNTP Server
#
# Copyright (C) 2015-2016 Chris Caron <lead2gold@gmail.com>
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Lesser General Public License for more details.



# Logging
logger = logging.getLogger(NEWSREAP_CODEC)

# Adapted from python-yenc but following suite to make everything behave the
# same way
E_ERROR = 64
E_CRC32 = 65

# The mask to apply to all CRC checking
BIN_MASK = 0xffffffffL



class CodecBase(object):