<commit_before>//: Playground - noun: a place where people can play

import UIKit
import DBNetworkStack
import XCPlayground

XCPlaygroundPage.currentPage.needsIndefiniteExecution = true

protocol MultiparRessource: RessourceModeling {
    var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get }
    var encodingMemoryThreshold: UInt64 { get }
}



protocol UploadAccessProviding {
    func upload(
                request: NetworkRequestRepresening, relativeToBaseURL: NSURL,
                multipartFormData: (MultipartFormDataRepresenting) -> (),
                encodingMemoryThreshold: UInt64,
                callback: (NSData?, NSHTTPURLResponse?, NSError?) -> ()) -> NetworkTask

}

protocol MultiUploadPoviderServiceProviding {
    func upload<T: MultiparRessource>(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask
}

class MultiUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing {
    let uploadAccess: UploadAccessProviding
    
    init(uploadAccess: UploadAccessProviding) {
        self.uploadAccess = uploadAccess
    }
    
    func upload<T: MultiparRessource>(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> ()) -> NetworkTask {
        //TODO: Build baseURL
        let baseURL = NSURL()
        return uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in
            do {
                let parsed = try self.process(response: response, ressource: ressource, data: data, error: error)
                dispatch_async(dispatch_get_main_queue()) {
                    onCompletion(parsed)
                }
            } catch let error as NSError {
                dispatch_async(dispatch_get_main_queue()) {
                    return onError(error)
                }
            }
        })
    }
}



<commit_msg>Alamofire Multipart example implementation<commit_after>//: Playground - noun: a place where people can play

import UIKit
import DBNetworkStack
import XCPlayground
//import Alamofire
//
//XCPlaygroundPage.currentPage.needsIndefiniteExecution = true
//
//protocol MultiparRessource: RessourceModeling {
//    var encodeInMultipartFormData: MultipartFormDataRepresenting -> Void { get }
//    var encodingMemoryThreshold: UInt64 { get }
//}
//
//extension Alamofire.MultipartFormData: MultipartFormDataRepresenting {}
//extension Alamofire.Request: NetworkTask {}
//
//class AlamofireUploadAccess: UploadAccessProviding {
//    func upload(request: NetworkRequestRepresening, relativeToBaseURL: NSURL, multipartFormData: (MultipartFormDataRepresenting) -> (), encodingMemoryThreshold: UInt64, callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) {
//        Alamofire.upload(
//            .POST,
//            NSURL(string: request.path, relativeToURL: relativeToBaseURL)!,
//            multipartFormData: multipartFormData,
//            encodingCompletion: { encodingResult in
//                switch encodingResult {
//                case .Success(let upload, _, _):
//                    onNetworkTaskCreation(upload)
//                    upload.response(completionHandler: { request, response, data, error in
//                        callback(data, response, error)
//                    })
//                case .Failure(let encodingError):
//                    //TODO ErrorHandling
//                    callback(nil, nil, NSError(code: .BadRequest, userInfo: ["err": ""]))
//                }
//            })
//    }
//}
//
//
//
//protocol UploadAccessProviding {
//    func upload(
//                request: NetworkRequestRepresening, relativeToBaseURL: NSURL,
//                multipartFormData: (MultipartFormDataRepresenting) -> (),
//                encodingMemoryThreshold: UInt64,
//                callback: (NSData?, NSHTTPURLResponse?, NSError?) -> (), onNetworkTaskCreation: (NetworkTask) -> ())
//}
//
//protocol MultiUploadPoviderServiceProviding {
//    func upload<T: MultiparRessource>(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ())
//}
//
//class MultiPartUploadPoviderService: MultiUploadPoviderServiceProviding, NetworkResponseProcessing {
//    let uploadAccess: UploadAccessProviding
//    
//    init(uploadAccess: UploadAccessProviding) {
//        self.uploadAccess = uploadAccess
//    }
//    
//    func upload<T: MultiparRessource>(ressource: T, onCompletion: (T.Model) -> (), onError: (NSError) -> (), onNetworkTaskCreation: (NetworkTask) -> ()) {
//        //TODO: Build baseURL
//        let baseURL = NSURL()
//        uploadAccess.upload(ressource.request, relativeToBaseURL: baseURL, multipartFormData: ressource.encodeInMultipartFormData, encodingMemoryThreshold: ressource.encodingMemoryThreshold, callback: { data, response, error in
//            do {
//                let parsed = try self.process(response: response, ressource: ressource, data: data, error: error)
//                dispatch_async(dispatch_get_main_queue()) {
//                    onCompletion(parsed)
//                }
//            } catch let error as NSError {
//                dispatch_async(dispatch_get_main_queue()) {
//                    return onError(error)
//                }
//            }
//        }, onNetworkTaskCreation: onNetworkTaskCreation)
//    }
//}




{'fraction_non_alphanumeric': 0.11281588447653429, 'fraction_numerical': 0.0018050541516245488, 'mean_word_length': 2.616840731070496, 'pattern_counts': {'":': 1, '<': 7, '<?xml version=': 0, '>': 30, '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': '2254908', 'n_tokens_mistral': 1568, 'n_tokens_neox': 1490, 'n_words': 306}