# Path: newsreap/Utils.py
# def strsize_to_bytes(strsize):
#     """
#     This function returns the byte size equivalent (as an integer) that best
#     represents the string passed in.  the string passed in is intended to be
#     in the format as:
#         value <unit>
# 
#         example: 4TB, 3GB, 10MB, 25KB, etc
# 
#     """
#     if isinstance(strsize, int):
#         # Nothing further to do
#         return strsize
# 
#     try:
#         strsize_re = re.match(
#             r'\s*(?P<size>(0|[1-9][0-9]*)(\.(0+|[1-9][0-9]*))?)\s*'
#             r'((?P<unit>.)(?P<type>[bB])?)?\s*',
#             strsize,
#         )
#     except TypeError:
#         return None
# 
#     if not strsize_re:
#         # Not good
#         return None
# 
#     size = int(strsize_re.group('size'))
#     unit = strsize_re.group('unit')
#     use_bytes = strsize_re.group('type') != 'b'
# 
#     if not unit:
#         return size
# 
#     # convert unit to uppercase
#     unit = unit.upper()
# 
#     if use_bytes:
#         if unit == 'B':
#             # We're going to assume bytes and return now
#             return size
# 
#         elif unit == 'K':
#             # We're dealing with Kilobytes
#             return size * 1024
# 
#         elif unit == 'M':
#             # We're dealing with Megabytes
#             return size * 1048576
# 
#         elif unit == 'G':
#             # We're dealing with Gigabytes
#             return size * 1073741824
# 
#         elif unit == 'T':
#             # We're dealing with Terabytes
#             return size * 1073741824 * 1024
# 
#     # In Bits
#     if unit == 'K':
#         # We're dealing with Kilobytes
#         return size * 1e3
# 
#     elif unit == 'M':
#         # We're dealing with Megabytes
#         return size * 1e6
# 
#     elif unit == 'G':
#         # We're dealing with Gigabytes
#         return size * 1e9
# 
#     elif unit == 'T':
#         # We're dealing with Terabytes
#         return size * 1e12
# 
#     # Unsupported Type
#     return None
# 
# Path: newsreap/NNTPSimpleFilter.py
# class NNTPSimpleFilter(NNTPFilterBase):
#     """
#     A simple filter that extends the FilterBase. This filter applies
#     some basic filters we can search against.
#     """
# 
#     def __init__(self):
#         """
#         Initialize Simple Filter
#         """
#         super(NNTPSimpleFilter, self).__init__()
# 
#         self._blacklist = {
#             '.*': [{
#                 FilterDirectives.DESCRIPTION: "Dangerous file types.",
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(exe|sc(f|r)|vb(e|s)?|pif|application|gadget|ms(c|h|i|p)|hta' +\
#                     '|jar|bat|c(md|om|pl)|jse?|ws(f|c|h)?|lnk|inf|reg|' +\
#                     'psc?(1|2)(xml)?|ms(h(1|2)(xml)?|1|2|))[\s"\'].*',
#                 re.IGNORECASE),
#             }],
#         }
# 
#         self._scorelist = {
#             'alt.bin.*' : [{
#                 FilterDirectives.DESCRIPTION: "Video Content",
#                 FilterDirectives.SCORE: 25,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(avi|m(p(4|eg|g)|kv|ov)|asf|ogg|iso|rm)(\.[0-9]{3})?[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Image Content",
#                 FilterDirectives.SCORE: 15,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(jpe?g|png|bmp|gif)[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Compressed Content",
#                 FilterDirectives.SCORE: 25,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(r(ar|[0-9]{2})|7z|z(ip|[0-9]{2})|tgz|tar\.gz)(\.[0-9]{3})?[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Recovery Content",
#                 FilterDirectives.SCORE: 10,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(par2?)[\s"\'].*',
#                 re.IGNORECASE),
#             }],
#         }


import sys
import gevent.monkey
import pytz
from os.path import abspath
from os.path import dirname
from datetime import datetime
from copy import deepcopy as copy
    from tests.TestBase import TestBase
    from tests.TestBase import TestBase
from newsreap.Utils import strsize_to_bytes
from newsreap.NNTPSimpleFilter import NNTPSimpleFilter
        Test that we correctly score video files
        """

        sf = NNTPSimpleFilter()
        entry = copy(self.template_entry)

        # Expected Score
        score = 25

        # Test against video files:
        for e in [ 'avi', 'mpeg', 'mpg', 'mp4', 'mov', 'mkv', 'asf',
                  'ogg', 'iso', 'rm' ]:

            entry['subject'] = 'What.A.Great.Show (1/1) ' +\
                    '"what.a.great.show.%s" Yenc (1/1)' % e

            assert sf.score(**entry) == score

            # now test that we can support .??? extensions after
            # the initial one
            for i in range(1000):
                entry['subject'] = 'What.A.Great.Show (1/1) ' +\
                        '"what.a.great.show.%s.%.3d" Yenc (1/1)' % (e, i)
                assert sf.score(**entry) == score

    def test_scoring_image_files(self):
        """
        Test that we correctly score image files
        """


# Path: newsreap/Utils.py
# def strsize_to_bytes(strsize):
#     """
#     This function returns the byte size equivalent (as an integer) that best
#     represents the string passed in.  the string passed in is intended to be
#     in the format as:
#         value <unit>
# 
#         example: 4TB, 3GB, 10MB, 25KB, etc
# 
#     """
#     if isinstance(strsize, int):
#         # Nothing further to do
#         return strsize
# 
#     try:
#         strsize_re = re.match(
#             r'\s*(?P<size>(0|[1-9][0-9]*)(\.(0+|[1-9][0-9]*))?)\s*'
#             r'((?P<unit>.)(?P<type>[bB])?)?\s*',
#             strsize,
#         )
#     except TypeError:
#         return None
# 
#     if not strsize_re:
#         # Not good
#         return None
# 
#     size = int(strsize_re.group('size'))
#     unit = strsize_re.group('unit')
#     use_bytes = strsize_re.group('type') != 'b'
# 
#     if not unit:
#         return size
# 
#     # convert unit to uppercase
#     unit = unit.upper()
# 
#     if use_bytes:
#         if unit == 'B':
#             # We're going to assume bytes and return now
#             return size
# 
#         elif unit == 'K':
#             # We're dealing with Kilobytes
#             return size * 1024
# 
#         elif unit == 'M':
#             # We're dealing with Megabytes
#             return size * 1048576
# 
#         elif unit == 'G':
#             # We're dealing with Gigabytes
#             return size * 1073741824
# 
#         elif unit == 'T':
#             # We're dealing with Terabytes
#             return size * 1073741824 * 1024
# 
#     # In Bits
#     if unit == 'K':
#         # We're dealing with Kilobytes
#         return size * 1e3
# 
#     elif unit == 'M':
#         # We're dealing with Megabytes
#         return size * 1e6
# 
#     elif unit == 'G':
#         # We're dealing with Gigabytes
#         return size * 1e9
# 
#     elif unit == 'T':
#         # We're dealing with Terabytes
#         return size * 1e12
# 
#     # Unsupported Type
#     return None
# 
# Path: newsreap/NNTPSimpleFilter.py
# class NNTPSimpleFilter(NNTPFilterBase):
#     """
#     A simple filter that extends the FilterBase. This filter applies
#     some basic filters we can search against.
#     """
# 
#     def __init__(self):
#         """
#         Initialize Simple Filter
#         """
#         super(NNTPSimpleFilter, self).__init__()
# 
#         self._blacklist = {
#             '.*': [{
#                 FilterDirectives.DESCRIPTION: "Dangerous file types.",
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(exe|sc(f|r)|vb(e|s)?|pif|application|gadget|ms(c|h|i|p)|hta' +\
#                     '|jar|bat|c(md|om|pl)|jse?|ws(f|c|h)?|lnk|inf|reg|' +\
#                     'psc?(1|2)(xml)?|ms(h(1|2)(xml)?|1|2|))[\s"\'].*',
#                 re.IGNORECASE),
#             }],
#         }
# 
#         self._scorelist = {
#             'alt.bin.*' : [{
#                 FilterDirectives.DESCRIPTION: "Video Content",
#                 FilterDirectives.SCORE: 25,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(avi|m(p(4|eg|g)|kv|ov)|asf|ogg|iso|rm)(\.[0-9]{3})?[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Image Content",
#                 FilterDirectives.SCORE: 15,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(jpe?g|png|bmp|gif)[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Compressed Content",
#                 FilterDirectives.SCORE: 25,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(r(ar|[0-9]{2})|7z|z(ip|[0-9]{2})|tgz|tar\.gz)(\.[0-9]{3})?[\s"\'].*',
#                 re.IGNORECASE),
#             },{
#                 FilterDirectives.DESCRIPTION: "Recovery Content",
#                 FilterDirectives.SCORE: 10,
#                 FilterDirectives.SUBJECT_MATCHES_REGEX: re.compile(
#                     '.*\.(par2?)[\s"\'].*',
#                 re.IGNORECASE),
#             }],
#         }


# Path: tests/NNTPSimpleFilter_Test.py
import sys
import gevent.monkey
import pytz
from os.path import abspath
from os.path import dirname
from datetime import datetime
from copy import deepcopy as copy
    from tests.TestBase import TestBase
    from tests.TestBase import TestBase
from newsreap.Utils import strsize_to_bytes
from newsreap.NNTPSimpleFilter import NNTPSimpleFilter

        Test that we correctly score video files
        """

        sf = NNTPSimpleFilter()
        entry = copy(self.template_entry)

        # Expected Score
        score = 25

        # Test against video files:
        for e in [ 'avi', 'mpeg', 'mpg', 'mp4', 'mov', 'mkv', 'asf',
                  'ogg', 'iso', 'rm' ]:

            entry['subject'] = 'What.A.Great.Show (1/1) ' +\
                    '"what.a.great.show.%s" Yenc (1/1)' % e

            assert sf.score(**entry) == score

            # now test that we can support .??? extensions after
            # the initial one
            for i in range(1000):
                entry['subject'] = 'What.A.Great.Show (1/1) ' +\
                        '"what.a.great.show.%s.%.3d" Yenc (1/1)' % (e, i)
                assert sf.score(**entry) == score

    def test_scoring_image_files(self):
        """
        Test that we correctly score image files
        """


        sf = NNTPSimpleFilter()