<commit_before>import os
import subprocess
import tempfile
import json
from pkg_resources import resource_filename


default_settings = {
    'loadImages': False,
    'resourceTimeout': 60000,
}


phantomjs_js = os.path.abspath(resource_filename(__name__, 'phantomjs.js'))
cmd = ['phantomjs', phantomjs_js]


def request_using_phantomjs(url, method, session=None, **kw):
    phantomjs = subprocess.Popen(cmd, stdin=subprocess.PIPE)
    fifo_path = mkfifo(phantomjs)
    settings = dict(default_settings)
    url_without_fragment = url.partition('#')[0]
    request = {
        'timeout': 60000,
        'url': url_without_fragment,
        'wex_url': url,
        'wexout': fifo_path,
        'settings': settings,
        'evaluate': [],
    }

    for evaluate in method.args.get('evaluate', []):
        filename = resource_filename(*evaluate)
        request['evaluate'].append(filename)

    request_line = json.dumps(request) + '\n'
    phantomjs.stdin.write(request_line.encode('utf-8'))<commit_msg>Use settings from method args<commit_after>import os
import subprocess
import tempfile
import json
from pkg_resources import resource_filename


default_settings = {
    'loadImages': False,
    'resourceTimeout': 60000,
}


phantomjs_js = os.path.abspath(resource_filename(__name__, 'phantomjs.js'))
cmd = ['phantomjs', phantomjs_js]


def request_using_phantomjs(url, method, session=None, **kw):
    phantomjs = subprocess.Popen(cmd, stdin=subprocess.PIPE)
    fifo_path = mkfifo(phantomjs)
    settings = dict(default_settings)
    settings.update(method.args.get('settings', {}))
    url_without_fragment = url.partition('#')[0]
    request = {
        'timeout': 60000,
        'url': url_without_fragment,
        'wex_url': url,
        'wexout': fifo_path,
        'settings': settings,
        'evaluate': [],
    }

    for evaluate in method.args.get('evaluate', []):
        filename = resource_filename(*evaluate)
        request['evaluate'].append(filename)

    request_line = json.dumps(request) + '\n'
    phantomjs.stdin.write(request_line.encode('utf-8'))
{'fraction_non_alphanumeric': 0.13070639115809707, 'fraction_numerical': 0.011532916866890917, 'mean_word_length': 3.864485981308411, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5584576', 'n_tokens_mistral': 703, 'n_tokens_neox': 646, 'n_words': 124}