# Path: evepaste/exceptions.py
# class Unparsable(Exception):
#     """
#     This exception is raised whenever the given text is not parsable.
#     """
#     pass
# 
# Path: evepaste/utils.py
# def regex_match_lines(regex, lines):
#     """
#     Performs a regex search on each line and returns a list of matched groups
#     and a list of lines which didn't match.
# 
#     :param regex regex: String to be split and stripped
#     :param list lines: A list of strings to perform the regex on.
#     """
#     matches = []
#     bad_lines = []
#     for line in lines:
#         match = regex.search(line)
#         if match:
#             matches.append(match.groups())
#         else:
#             bad_lines.append(line)
#     return matches, bad_lines
# 
# Path: evepaste/parsers/listing.py
# def parse_listing(lines):
#     """ Parse Listing and Cargo Scan Results
# 
#     :param string paste_string: A raw string pasted from Eve Online of a cargo
#                          scan result or a human listing
#     """
#     matches, bad_lines = regex_match_lines(LISTING_RE, lines)
#     matches2, bad_lines2 = regex_match_lines(LISTING_RE2, bad_lines)
#     matches3, bad_lines3 = regex_match_lines(LISTING_RE3, bad_lines2)
# 
#     items = defaultdict(int)
# 
#     for count, name in matches:
#         items[name.strip()] += f_int(count) or 1
# 
#     for name, count in matches2:
#         items[name.strip()] += f_int(count) or 1
# 
#     for res in matches3:
#         items[res[0].strip()] += 1
# 
#     results = []
#     for name, quantity in sorted(items.items()):
#         results.append({'name': name, 'quantity': quantity})
# 
#     return results, bad_lines3


import re
from collections import defaultdict
from evepaste.exceptions import Unparsable
from evepaste.utils import regex_match_lines
from evepaste.parsers.listing import parse_listing
~~~~~~~~~~~~~~~~~~~~
Parse EFT blocks.

"""


# [Rifter, Title] | [Rifter,Title]
EFT_LIST_RE = re.compile(r"^([\S ]+), ?([\S ]+)$")
EFT_BLACKLIST = ['[empty high slot]',
                 '[empty low slot]',
                 '[empty medium slot]',
                 '[empty rig slot]',
                 '[empty subsystem slot]']


def parse_eft(lines):
    """ Parse EFT format

    :param string paste_string: An EFT block string
    """
    lines = [line for line in lines if line.lower() not in EFT_BLACKLIST]

    if not lines:
        raise Unparsable('No valid parsable lines')

    if '[' not in lines[0] or ']' not in lines[0]:
        raise Unparsable('Invalid EFT title line')

    title_parts = lines[0].strip('[]').split(',', 1)
    if len(title_parts) != 2:

# Path: evepaste/exceptions.py
# class Unparsable(Exception):
#     """
#     This exception is raised whenever the given text is not parsable.
#     """
#     pass
# 
# Path: evepaste/utils.py
# def regex_match_lines(regex, lines):
#     """
#     Performs a regex search on each line and returns a list of matched groups
#     and a list of lines which didn't match.
# 
#     :param regex regex: String to be split and stripped
#     :param list lines: A list of strings to perform the regex on.
#     """
#     matches = []
#     bad_lines = []
#     for line in lines:
#         match = regex.search(line)
#         if match:
#             matches.append(match.groups())
#         else:
#             bad_lines.append(line)
#     return matches, bad_lines
# 
# Path: evepaste/parsers/listing.py
# def parse_listing(lines):
#     """ Parse Listing and Cargo Scan Results
# 
#     :param string paste_string: A raw string pasted from Eve Online of a cargo
#                          scan result or a human listing
#     """
#     matches, bad_lines = regex_match_lines(LISTING_RE, lines)
#     matches2, bad_lines2 = regex_match_lines(LISTING_RE2, bad_lines)
#     matches3, bad_lines3 = regex_match_lines(LISTING_RE3, bad_lines2)
# 
#     items = defaultdict(int)
# 
#     for count, name in matches:
#         items[name.strip()] += f_int(count) or 1
# 
#     for name, count in matches2:
#         items[name.strip()] += f_int(count) or 1
# 
#     for res in matches3:
#         items[res[0].strip()] += 1
# 
#     results = []
#     for name, quantity in sorted(items.items()):
#         results.append({'name': name, 'quantity': quantity})
# 
#     return results, bad_lines3


# Path: evepaste/parsers/eft.py
import re
from collections import defaultdict
from evepaste.exceptions import Unparsable
from evepaste.utils import regex_match_lines
from evepaste.parsers.listing import parse_listing

~~~~~~~~~~~~~~~~~~~~
Parse EFT blocks.

"""


# [Rifter, Title] | [Rifter,Title]
EFT_LIST_RE = re.compile(r"^([\S ]+), ?([\S ]+)$")
EFT_BLACKLIST = ['[empty high slot]',
                 '[empty low slot]',
                 '[empty medium slot]',
                 '[empty rig slot]',
                 '[empty subsystem slot]']


def parse_eft(lines):
    """ Parse EFT format

    :param string paste_string: An EFT block string
    """
    lines = [line for line in lines if line.lower() not in EFT_BLACKLIST]

    if not lines:
        raise Unparsable('No valid parsable lines')

    if '[' not in lines[0] or ']' not in lines[0]:
        raise Unparsable('Invalid EFT title line')

    title_parts = lines[0].strip('[]').split(',', 1)
    if len(title_parts) != 2:

        raise Unparsable('Invalid EFT title line')