<commit_before>//
//  WebLoadAction.swift
//  Pods
//
//  Created by <NAME> on 2/10/16.
//
//

import Foundation
import StartAppsKitLogger

let session = URLSession(
    configuration: URLSessionConfiguration.default,
    delegate: nil,
    delegateQueue: OperationQueue.main
)

public enum WebLoadError: Error, LocalizedError {
    case noInternet, emptyResponse
    public var errorDescription: String? {
        switch self {
        case .noInternet:
            return NSLocalizedString("No internet connection.", comment: "")
        case .emptyResponse:
            return NSLocalizedString("Empty response.", comment: "")
        }
    }
}

open class WebLoadAction: LoadAction<Data> {
    
    open var urlRequest: URLRequest
    
    fileprivate func loadInner(completion: @escaping LoadResultClosure) {
        print(owner: "LoadAction[Web]", items: "Load Began (Url: \(urlRequest.url?.absoluteString ?? "-"))", level: .verbose)
        session.dataTask(with: urlRequest, completionHandler: { (loadedData, urlResponse, error) -> Void in
            if let error = error {
                switch (error as NSError).code {
                case -1001, -1003, -1009:
                    let newError = WebLoadError.noInternet
                    print(owner: "LoadAction[Web]", items: "Load failure, \(newError) (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                    completion(.failure(newError))
                    return
                default:
                    print(owner: "LoadAction[Web]", items: "Load failure, \(error) (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                    completion(.failure(error))
                    return
                }
            }
            guard let loadedData = loadedData else {
                print(owner: "LoadAction[Web]", items: "Load failure, empty response (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                let error = WebLoadError.emptyResponse
                completion(.failure(error))
                return
            }
            print(owner: "LoadAction[Web]", items: "Load success (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .verbose)
            completion(.success(loadedData))
        }).resume()<commit_msg>Improved session creation<commit_after>//
//  WebLoadAction.swift
//  Pods
//
//  Created by <NAME> on 2/10/16.
//
//

import Foundation
import StartAppsKitLogger

public enum WebLoadError: Error, LocalizedError {
    case noInternet, emptyResponse
    public var errorDescription: String? {
        switch self {
        case .noInternet:
            return NSLocalizedString("No internet connection.", comment: "")
        case .emptyResponse:
            return NSLocalizedString("Empty response.", comment: "")
        }
    }
}

open class WebLoadAction: LoadAction<Data> {
    
    open var urlRequest: URLRequest
    
    open var session: URLSession {
        return URLSession.shared
    }
    
    fileprivate func loadInner(completion: @escaping LoadResultClosure) {
        print(owner: "LoadAction[Web]", items: "Load Began (Url: \(urlRequest.url?.absoluteString ?? "-"))", level: .verbose)
        session.dataTask(with: urlRequest, completionHandler: { (loadedData, urlResponse, error) -> Void in
            if let error = error {
                switch (error as NSError).code {
                case -1001, -1003, -1009:
                    let newError = WebLoadError.noInternet
                    print(owner: "LoadAction[Web]", items: "Load failure, \(newError) (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                    completion(.failure(newError))
                    return
                default:
                    print(owner: "LoadAction[Web]", items: "Load failure, \(error) (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                    completion(.failure(error))
                    return
                }
            }
            guard let loadedData = loadedData else {
                print(owner: "LoadAction[Web]", items: "Load failure, empty response (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .error)
                let error = WebLoadError.emptyResponse
                completion(.failure(error))
                return
            }
            print(owner: "LoadAction[Web]", items: "Load success (Url: \(self.urlRequest.url?.absoluteString ?? "-"))", level: .verbose)
            completion(.success(loadedData))
        }).resume()
{'fraction_non_alphanumeric': 0.12472647702407003, 'fraction_numerical': 0.007439824945295405, 'mean_word_length': 2.1329677861549006, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '1850395', 'n_tokens_mistral': 1239, 'n_tokens_neox': 1163, 'n_words': 298}