<commit_before>//
//  XCTestAlertViewCommand.swift
//  XCTestWebdriver
//
//  Created by zhaoy on 21/4/17.
//  Copyright © 2017 XCTestWebdriver. All rights reserved.
//

import Foundation
import Swifter
import SwiftyJSON

internal class XCTestWDSourceController: Controller {
    
    //MARK: Controller - Protocol
    static func routes() -> [(RequestRoute, RoutingCall)] {
        return [(RequestRoute("/session/:sessionId/source", "get"), source),
                (RequestRoute("/source", "get"), sourceWithoutSession),
                (RequestRoute("/session/:sessionId/accessibleSource", "get"), accessiblitySource),
                (RequestRoute("/accessibleSource", "get"), accessiblitySourceWithoutSession)]
    }
    
    static func shouldRegisterAutomatically() -> Bool {
        return false
    }
    
    //MARK: Routing Logic Specification
    internal static func source(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = request.session?.application.tree()
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
    
    internal static func sourceWithoutSession(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = XCTestWDSession.activeApplication()?.tree()
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
    
    internal static func accessiblitySource(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = request.session?.application.accessibilityTree()
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
    
    internal static func accessiblitySourceWithoutSession(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = XCTestWDSession.activeApplication()?.accessibilityTree()
        XCTestWDXPath.findMatchesIn(XCTestWDSession.activeApplication()?.lastSnapshot() as! XCElementSnapshot, "//Other")
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
}<commit_msg>bug fix<commit_after>//
//  XCTestAlertViewCommand.swift
//  XCTestWebdriver
//
//  Created by zhaoy on 21/4/17.
//  Copyright © 2017 XCTestWebdriver. All rights reserved.
//

import Foundation
import Swifter
import SwiftyJSON

internal class XCTestWDSourceController: Controller {
    
    //MARK: Controller - Protocol
    static func routes() -> [(RequestRoute, RoutingCall)] {
        return [(RequestRoute("/session/:sessionId/source", "get"), source),
                (RequestRoute("/source", "get"), sourceWithoutSession),
                (RequestRoute("/session/:sessionId/accessibleSource", "get"), accessiblitySource),
                (RequestRoute("/accessibleSource", "get"), accessiblitySourceWithoutSession)]
    }
    
    static func shouldRegisterAutomatically() -> Bool {
        return false
    }
    
    //MARK: Routing Logic Specification
    internal static func source(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = request.session?.application.tree()
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
    
    internal static func sourceWithoutSession(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = XCTestWDSession.activeApplication()?.tree()
        return XCTestWDResponse.response(session: request.session, value: JSON(JSON(temp!).rawString() ?? ""))
    }
    
    internal static func accessiblitySource(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = request.session?.application.accessibilityTree()
        return XCTestWDResponse.response(session: request.session, value: JSON(temp!))
    }
    
    internal static func accessiblitySourceWithoutSession(request: Swifter.HttpRequest) -> Swifter.HttpResponse {
        let temp = XCTestWDSession.activeApplication()?.accessibilityTree()
        return XCTestWDResponse.response(session: request.session, value: JSON(JSON(temp!).rawString() ?? "")
    }
}
{'fraction_non_alphanumeric': 0.11405041177938607, 'fraction_numerical': 0.004492138757174944, 'mean_word_length': 3.5597269624573378, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, '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': '1375317', 'n_tokens_mistral': 1125, 'n_tokens_neox': 1080, 'n_words': 229}