示例#1
0
def parse_time_data(lines, offset):
    for i, line in enumerate(lines[offset:]):
        if i == 0:
            if not TIME_RE.search(line):
                raise Unparsable('Missing datetime.')

            yield 'time', line
        else:
            yield 'state_change', (parse_victim_data, offset + i)

    raise Unparsable('Failed to parse past time.')
示例#2
0
def parse_involved_data(lines, offset):
    player = {}
    transition = None
    for line in lines[offset:]:
        offset += 1
        transition = common_transitions(line)
        if player and line.startswith('Name:'):
            offset -= 1
            transition = parse_involved_data

        if transition:
            break

        match = INVOLVED_RE.search(line)
        if match:
            key, val, killing_blow = match.groups()
            player[format_key(key)] = val
            if killing_blow:
                player['killing_blow'] = True
        else:
            raise Unparsable('Failed parsing at line %s: %s' % (offset, line))

    if player:
        player['killing_blow'] = player.get('killing_blow', False)
        player['damage_done'] = int(player.get('damage_done', 0))
        yield 'involved', player
    yield 'state_change', (transition, offset)
示例#3
0
文件: eft.py 项目: Blackout76/eva
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')

    ship = title_parts[0].strip()
    eft_name = title_parts[1].strip()
    modules = []

    # Match "Module, Ammo"
    matches, bad_lines = regex_match_lines(EFT_LIST_RE, lines[1:])
    matches2, bad_lines2 = parse_listing(bad_lines)

    module_w_ammo = defaultdict(int)
    for module, ammo in matches:
        module_w_ammo[(module, ammo)] += 1

    for (name, ammo), quantity in sorted(module_w_ammo.items()):
        modules.append({'name': name, 'ammo': ammo, 'quantity': quantity})

    for item in matches2:
        modules.append(item)

    result = {
        'ship': ship,
        'name': eft_name,
        'modules': [res for res in modules]
    }
    return result, bad_lines2
示例#4
0
def parse_fitting(lines):
    """ Parse Fitting List

    :param string paste_string: A new-line separated list of items
    """

    if any([True for line in lines if line in FITTING_BLACKLIST]):
        lines = [line for line in lines if line not in FITTING_BLACKLIST]
    else:
        raise Unparsable('Not a fitting list')

    return parse_listing(lines)
示例#5
0
def parse_dropped_items(lines, offset):
    for line in lines[offset:]:
        offset += 1
        match = ITEM_RE.search(line)
        if match:
            name, _, quantity, _, location = match.groups()
            yield 'dropped', {
                'name': name,
                'quantity': f_int(quantity) or 1,
                'location': location
            }
        else:
            raise Unparsable('Failed parsing at line %s: %s' % (offset, line))

    yield 'state_change', (None, offset)
示例#6
0
def parse_victim_data(lines, offset):
    victim_data = {}
    transition = None
    for line in lines[offset:]:
        offset += 1
        transition = common_transitions(line)
        if transition:
            break

        match = PLAYER_RE.search(line)
        if match:
            key, val = match.groups()
            victim_data[format_key(key)] = val
        else:
            raise Unparsable('Failed parsing at line %s: %s' % (offset, line))

    yield 'victim', victim_data
    yield 'state_change', (transition, offset)
示例#7
0
def parse_destroyed_items(lines, offset):
    transition = None
    for line in lines[offset:]:
        offset += 1
        transition = common_transitions(line)
        if transition:
            break

        match = ITEM_RE.search(line)
        if match:
            name, _, quantity, _, location = match.groups()
            yield 'destroyed', {
                'name': name,
                'quantity': f_int(quantity) or 1,
                'location': location
            }
        else:
            raise Unparsable('Failed parsing at line %s: %s' % (offset, line))

    yield 'state_change', (transition, offset)