<commit_before>import commands
import tempfile
import logging
import signal
import subprocess
import sys, os
import urlparse

import windmill	

logger = logging.getLogger(__name__)

import safari

class Chrome(safari.Safari):
	
	def __init__(self):
	    self.chrome_binary = windmill.settings['CHROME_BINARY']
	    self.test_url = windmill.settings['TEST_URL']
	
    # def create_redirect(self):
    #     self.redirection_page = tempfile.mktemp(suffix='.html')
    #     f = open(self.redirection_page, 'w') 
    #     test_url = windmill.get_test_url(windmill.settings['TEST_URL']) 
    #     f.write( html_redirection.replace('{replace}', test_url) )
    #     f.flush() ; f.close()
	    
    # def set_proxy_mac(self):
    #     """Set local Proxy"""
    #     self.netsetup_binary = windmill.settings['NETWORKSETUP_BINARY']
    #     interface_name = find_default_interface_name()
    #     uri = urlparse.urlparse(self.test_url)
    #     set_proxy_command = ' '.join([ self.netsetup_binary, 
    #                                    '-setwebproxy', 
    #                                    '"'+interface_name+'"', 
    #                                    'localhost', 
    #                                    str(windmill.settings['SERVER_HTTP_PORT'])
    #                                  ])
    #     commands.getoutput(set_proxy_command)
    #     enable_proxy_command = ' '.join([ self.netsetup_binary,
    #                                       '-setwebproxystate',
    #                                       '"'+interface_name+'"',
    #                                       'on'
    #                                     ])
    #     commands.getoutput(enable_proxy_command)      
    #     self.create_redirect()
    #     self.interface_name = interface_name
    # 
    # def unset_proxy_mac(self):
    #     commands.getoutput(' '.join([self.netsetup_binary, '-setwebproxystate', '"'+self.interface_name+'"', 'off']))
	
	def set_proxy_windows(self):
	    import ie
	    self.ie_obj = ie.InternetExplorer()
	    self.ie_obj.set_proxy()
    # 
    # def unset_proxy_windows(self):
    #     self.ie_obj.unset_proxy()
	    
	def start(self):
	    """Start Chrome"""
        # if sys.platform == 'darwin':
        #     self.set_proxy_mac()
	    if os.name == 'nt' or sys.platform == 'cygwin':
	        self.set_proxy_windows()
	    
	    kwargs = {'stdout':sys.stdout ,'stderr':sys.stderr, 'stdin':sys.stdin}
	    command = [self.chrome_binary, '--homepage', self.test_url+'/windmill-serv/start.html']
	    self.p_handle = subprocess.Popen(command, **kwargs)
	    logger.info(command)

	def kill(self, kill_signal=None):
	    """Stop Chrome"""
	    if not sys.version.startswith('2.6'):
	        raise Exception("Kill doesn't work for Chrome on Python version pre-2.6")
	    
	    if os.name == 'nt' or sys.platform == 'cygwin':
	        self.unset_proxy_windows()
	        
	    try:<commit_msg>Adding popup blocking flag.<commit_after>import commands
import tempfile
import logging
import signal
import subprocess
import sys, os
import urlparse

import windmill	

logger = logging.getLogger(__name__)

import safari

class Chrome(safari.Safari):
	
	def __init__(self):
	    self.chrome_binary = windmill.settings['CHROME_BINARY']
	    self.test_url = windmill.settings['TEST_URL']
	
    # def create_redirect(self):
    #     self.redirection_page = tempfile.mktemp(suffix='.html')
    #     f = open(self.redirection_page, 'w') 
    #     test_url = windmill.get_test_url(windmill.settings['TEST_URL']) 
    #     f.write( html_redirection.replace('{replace}', test_url) )
    #     f.flush() ; f.close()
	    
    # def set_proxy_mac(self):
    #     """Set local Proxy"""
    #     self.netsetup_binary = windmill.settings['NETWORKSETUP_BINARY']
    #     interface_name = find_default_interface_name()
    #     uri = urlparse.urlparse(self.test_url)
    #     set_proxy_command = ' '.join([ self.netsetup_binary, 
    #                                    '-setwebproxy', 
    #                                    '"'+interface_name+'"', 
    #                                    'localhost', 
    #                                    str(windmill.settings['SERVER_HTTP_PORT'])
    #                                  ])
    #     commands.getoutput(set_proxy_command)
    #     enable_proxy_command = ' '.join([ self.netsetup_binary,
    #                                       '-setwebproxystate',
    #                                       '"'+interface_name+'"',
    #                                       'on'
    #                                     ])
    #     commands.getoutput(enable_proxy_command)      
    #     self.create_redirect()
    #     self.interface_name = interface_name
    # 
    # def unset_proxy_mac(self):
    #     commands.getoutput(' '.join([self.netsetup_binary, '-setwebproxystate', '"'+self.interface_name+'"', 'off']))
	
	def set_proxy_windows(self):
	    import ie
	    self.ie_obj = ie.InternetExplorer()
	    self.ie_obj.set_proxy()
    # 
    # def unset_proxy_windows(self):
    #     self.ie_obj.unset_proxy()
	    
	def start(self):
	    """Start Chrome"""
        # if sys.platform == 'darwin':
        #     self.set_proxy_mac()
	    if os.name == 'nt' or sys.platform == 'cygwin':
	        self.set_proxy_windows()
	    
	    kwargs = {'stdout':sys.stdout ,'stderr':sys.stderr, 'stdin':sys.stdin}
	    command = [self.chrome_binary, '--homepage', self.test_url+'/windmill-serv/start.html', '-disable-popup-blocking']
	    self.p_handle = subprocess.Popen(command, **kwargs)
	    logger.info(command)

	def kill(self, kill_signal=None):
	    """Stop Chrome"""
	    if not sys.version.startswith('2.6'):
	        raise Exception("Kill doesn't work for Chrome on Python version pre-2.6")
	    
	    if os.name == 'nt' or sys.platform == 'cygwin':
	        self.unset_proxy_windows()
	        
	    try:
{'fraction_non_alphanumeric': 0.12748936170212766, 'fraction_numerical': 0.0013617021276595745, 'mean_word_length': 1.9964303926568077, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 32, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '91517', 'n_tokens_mistral': 1870, 'n_tokens_neox': 1760, 'n_words': 287}