<commit_before>//
//  Context.swift
//  Kunugi
//
//  Created by ito on 1/3/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import HTTP

public protocol ContextBox: class, CustomStringConvertible, CustomDebugStringConvertible {
    var context: [ContextType] { get set }
    var request: Request { get set }
    func get<T: ContextType>() throws -> T
    func set(ctx: ContextType) throws
}

public protocol ContextType { }

public extension ContextBox {
    func get<T: ContextType>() throws -> T {
        if let box = self as? T {
            return box
        }
        for c in context {
            if let cc = c as? T {
                return cc
            }
        }
        throw MiddlewareError.NoContextType("\(T.self)")
    }
    func set(ctx: ContextType) throws {
        for c in context {
            if c.dynamicType == ctx.dynamicType {
                throw MiddlewareError.AlreadyHasContextType("\(c.dynamicType)")
            }
        }
        context.insert(ctx, atIndex: 0)
    }
}

public extension ContextBox {
    var description: String {
        return "\(context.map({ return $0.dynamicType.self }))"
    }
    var debugDescription: String {
        return "\(context)"
    }
}<commit_msg>change func name<commit_after>//
//  Context.swift
//  Kunugi
//
//  Created by ito on 1/3/16.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import HTTP

public protocol ContextBox: class, CustomStringConvertible, CustomDebugStringConvertible {
    var context: [ContextType] { get set }
    var request: Request { get set }
    func get<T: ContextType>() throws -> T
    func put(ctx: ContextType) throws
}

public protocol ContextType { }

public extension ContextBox {
    func get<T: ContextType>() throws -> T {
        if let box = self as? T {
            return box
        }
        for c in context {
            if let cc = c as? T {
                return cc
            }
        }
        throw MiddlewareError.NoContextType("\(T.self)")
    }
    func put(ctx: ContextType) throws {
        for c in context {
            if c.dynamicType == ctx.dynamicType {
                throw MiddlewareError.AlreadyHasContextType("\(c.dynamicType)")
            }
        }
        context.insert(ctx, atIndex: 0)
    }
}

public extension ContextBox {
    var description: String {
        return "\(context.map({ return $0.dynamicType.self }))"
    }
    var debugDescription: String {
        return "\(context)"
    }
}
{'fraction_non_alphanumeric': 0.10854597002835156, 'fraction_numerical': 0.008100445524503848, 'mean_word_length': 1.9866989117291414, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3178758', 'n_tokens_mistral': 731, 'n_tokens_neox': 707, 'n_words': 214}