<commit_before>//
//  PreventSleep.swift
//  PreventSleep
//
//  Created by <NAME> on 12/07/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import IOKit.pwr_mgt

public class PreventSleep {
    var sleepAssertionID: IOPMAssertionID? = IOPMAssertionID(0)
    var sleepAssertionType: String?
    var sleepAssertion: IOReturn?
    
    let sleepAssertionMsg: String?
    
    public init?(sleepAssertionMsg: String, sleepAssertionType: String) {
        // Check if the assertion type is valid
        if sleepAssertionType != kIOPMAssertionTypeNoIdleSleep &&
           sleepAssertionType != kIOPMAssertionTypeNoDisplaySleep {
           return nil
        }
        
        self.sleepAssertionMsg  = sleepAssertionMsg
        self.sleepAssertionType = sleepAssertionType
    }
    
    deinit {
        self.allowSleep()
    }
    
    // MARK: Power assertion handling
    
    // Prevent the computer going to sleep
    // Returns whether the power assertion was successful or not.
    func preventSleep() -> Bool {
        self.sleepAssertion = IOPMAssertionCreateWithName(
            self.sleepAssertionType,
            IOPMAssertionLevel(kIOPMAssertionLevelOn),
            sleepAssertionMsg,
            &sleepAssertionID!
        )
        
        if self.sleepAssertion == kIOReturnSuccess {
            return true
        } else {
            return false
        }
    }
    
    // Allow the computer to go to sleep
    // Returns whether the power assertion was successful or not.
    func allowSleep() -> Bool {
        let sleepAssertionRelease = IOPMAssertionRelease(self.sleepAssertionID!)
        
        if sleepAssertionRelease == kIOReturnSuccess {
            return true
        } else {
            return false
        }
    }
    
    // Can the computer go to sleep, or is it being prevented?
    func canSleep() -> Bool {
        // Check if the assertion already exists
        if sleepAssertion == kIOReturnSuccess {
            return false
        } else {
            return true
        }
    }
}<commit_msg>Correct function access.<commit_after>//
//  PreventSleep.swift
//  PreventSleep
//
//  Created by <NAME> on 12/07/2016.
//  Copyright © 2016 <NAME>. All rights reserved.
//

import Foundation
import IOKit.pwr_mgt

public class PreventSleep {
    var sleepAssertionID: IOPMAssertionID? = IOPMAssertionID(0)
    var sleepAssertionType: String?
    var sleepAssertion: IOReturn?
    
    let sleepAssertionMsg: String?
    
    public init?(sleepAssertionMsg: String, sleepAssertionType: String) {
        // Check if the assertion type is valid
        if sleepAssertionType != kIOPMAssertionTypeNoIdleSleep &&
           sleepAssertionType != kIOPMAssertionTypeNoDisplaySleep {
           return nil
        }
        
        self.sleepAssertionMsg  = sleepAssertionMsg
        self.sleepAssertionType = sleepAssertionType
    }
    
    deinit {
        self.allowSleep()
    }
    
    // MARK: Power assertion handling
    
    // Prevent the computer going to sleep
    // Returns whether the power assertion was successful or not.
    public func preventSleep() -> Bool {
        self.sleepAssertion = IOPMAssertionCreateWithName(
            self.sleepAssertionType,
            IOPMAssertionLevel(kIOPMAssertionLevelOn),
            sleepAssertionMsg,
            &sleepAssertionID!
        )
        
        if self.sleepAssertion == kIOReturnSuccess {
            return true
        } else {
            return false
        }
    }
    
    // Allow the computer to go to sleep
    // Returns whether the power assertion was successful or not.
    public func allowSleep() -> Bool {
        let sleepAssertionRelease = IOPMAssertionRelease(self.sleepAssertionID!)
        
        if sleepAssertionRelease == kIOReturnSuccess {
            return true
        } else {
            return false
        }
    }
    
    // Can the computer go to sleep, or is it being prevented?
    public func canSleep() -> Bool {
        // Check if the assertion already exists
        if sleepAssertion == kIOReturnSuccess {
            return false
        } else {
            return true
        }
    }
}
{'fraction_non_alphanumeric': 0.06811663479923519, 'fraction_numerical': 0.00621414913957935, 'mean_word_length': 1.9744136460554371, 'pattern_counts': {'":': 0, '<': 7, '<?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': '485768', 'n_tokens_mistral': 1211, 'n_tokens_neox': 1142, 'n_words': 313}