def parse_files(files, options):
    """Build datastructures from lines"""
    lines = []
    for line in finput(files, openhook=compr):
        lines.append(line.rstrip().split("|"))

    db = {}
    db['rp'], db['users'], db['msgprof'], db['logins'] = {}, {}, {}, 0

    login_string = "sso"
    fields_position = [3, 4, 8]

    if options.shibidpv4:
        login_string = "success"
        fields_position = [4, 17, 3]

    # Audit log format we're trying to parse below:
    # datetime|req_bind|req_id|rp|msg_profile|idp|resp_bind|resp_id|user|authn_mech|attribs|name_id|assert_id|ip

    for event in lines:
        try:
            rp, msg_profile, user = list(event[i] for i in fields_position)
        except ValueError:
            print(linesep.join([
                "ERROR: Unsupported log file format or compressed logs with Python < 2.5",
                "See the documentation."]))
            term(-1)

        if rp:
            if msg_profile.lower().find(login_string) > -1:
                db['logins'] += 1

                # we almost always need to count rps:
                if len(rp) > 0:
                    if rp in db['rp']:
                        db['rp'][rp] += 1
                    else:
                        db['rp'][rp] = 1

                # only count users if asked to
                if len(user) > 0:
                    if options.uniqusers or options.xml or options.rrd or options.json:
                        if user in db['users']:
                            db['users'][user] += 1
                        else:
                            db['users'][user] = 1

        # only count message profiles and rps if asked to
        if options.msgprofiles:
            if msg_profile in db['msgprof']:
                if rp in db['msgprof'][msg_profile]:
                    db['msgprof'][msg_profile][rp] += 1
                else:
                    db['msgprof'][msg_profile][rp] = 1
            else:
                db['msgprof'][msg_profile] = {}
                db['msgprof'][msg_profile][rp] = 1
    return db
Beispiel #2
0
from collections import deque
from itertools import islice


def parse(deck):
    q = deque()
    for line in deck.splitlines():
        try:
            i = int(line)
            q.append(int(line))
        except:
            k = line[:-1]
    return k, q


fi = "".join(finput())
decks = dict([parse(deck) for deck in fi.split("\n\n")])


def combat(decks):
    p1 = decks["Player 1"]
    p2 = decks["Player 2"]
    while p1 and p2:
        p1c = p1.popleft()
        p2c = p2.popleft()
        if p1c > p2c:
            p1.append(p1c)
            p1.append(p2c)
        else:
            p2.append(p2c)
            p2.append(p1c)
Beispiel #3
0
def main(argv):
    write_output(convert(finput()))
Beispiel #4
0
    head, n, m = linkify(order)
    n.next = head.next
    return head.next, m


def parse_part2(order, upto):
    head, n, m = linkify(order)
    for i in range(max(m.keys()) + 1, upto + 1):
        n.next = Node(i)
        m[n.next.val] = n.next
        n = n.next
    n.next = head.next
    return head.next, m


lines = "".join(finput())
labeling = "".join(lines.splitlines())


def remove_k_nodes(node, k):
    head = node
    nodes = set()
    for _ in range(k):
        node = node.next
        nodes.add(node.val)
    detached = head.next
    head.next, node.next = node.next, None
    return detached, nodes


def append_after(node, l):