<commit_before>import re
import subprocess
import os
import yaml  # use yaml instead of json to get non unicode


class CompileError(Exception):
    pass


class solc_wrapper(object):

    "wraps solc binary"

    @classmethod
    def compiler_available(cls):
        program = 'solc'

        def is_exe(fpath):
            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

        fpath, fname = os.path.split(program)
        if fpath:
            if is_exe(program):
                return program
        else:
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, program)
                if is_exe(exe_file):
                    return exe_file

        return None

    @classmethod
    def contract_names(cls, code):
        return re.findall(r'^\s*(contract|library) (\S*) ', code, re.MULTILINE)

    @classmethod
    def compile(cls, code, libraries=None, contract_name=''):
        "returns binary of last contract in code"
        sorted_contracts = cls.combined(code)
        if contract_name:
            idx = [x[0] for x in sorted_contracts].index(contract_name)
        else:
            idx = -1
        if libraries:
            for lib_name, lib_address in libraries.iteritems():
                sorted_contracts[idx][1]['bin'] = sorted_contracts[idx][1]['bin'].replace("__{}{}".format(lib_name, "_" * (38-len(lib_name))), lib_address)
        return sorted_contracts[idx][1]['bin'].decode('hex')

    @classmethod
    def mk_full_signature(cls, code, libraries=None, contract_name=''):
        "returns signature of last contract in code"
        sorted_contracts = cls.combined(code)
        if contract_name:
            idx = [x[0] for x in sorted_contracts].index(contract_name)
        else:
            idx = -1
        return sorted_contracts[idx][1]['abi']

    @classmethod
    def combined(cls, code):
        p = subprocess.Popen(['solc', '--add-std', '--optimize', '--combined-json', 'abi,bin,devdoc,userdoc'],<commit_msg>added compiler version check<commit_after>import re
import subprocess
import os
import yaml  # use yaml instead of json to get non unicode


class CompileError(Exception):
    pass


class solc_wrapper(object):

    "wraps solc binary"

    @classmethod
    def compiler_available(cls):
        program = 'solc'

        def is_exe(fpath):
            return os.path.isfile(fpath) and os.access(fpath, os.X_OK)

        fpath, fname = os.path.split(program)
        if fpath:
            if is_exe(program):
                return program
        else:
            for path in os.environ["PATH"].split(os.pathsep):
                path = path.strip('"')
                exe_file = os.path.join(path, program)
                if is_exe(exe_file):
                    return exe_file

        return None

    @classmethod
    def contract_names(cls, code):
        return re.findall(r'^\s*(contract|library) (\S*) ', code, re.MULTILINE)

    @classmethod
    def compile(cls, code, libraries=None, contract_name=''):
        "returns binary of last contract in code"
        sorted_contracts = cls.combined(code)
        if contract_name:
            idx = [x[0] for x in sorted_contracts].index(contract_name)
        else:
            idx = -1
        if libraries:
            if cls.compiler_version() < "0.1.2":
                raise CompileError('Compiler does not support libraries. Please update compiler.')
            for lib_name, lib_address in libraries.iteritems():
                sorted_contracts[idx][1]['bin'] = sorted_contracts[idx][1]['bin'].replace("__{}{}".format(lib_name, "_" * (38-len(lib_name))), lib_address)
        return sorted_contracts[idx][1]['bin'].decode('hex')

    @classmethod
    def mk_full_signature(cls, code, libraries=None, contract_name=''):
        "returns signature of last contract in code"
        sorted_contracts = cls.combined(code)
        if contract_name:
            idx = [x[0] for x in sorted_contracts].index(contract_name)
        else:
            idx = -1
        return sorted_contracts[idx][1]['abi']

    @classmethod
    def combined(cls, code):
        p = subprocess.Popen(['solc', '--add-std', '--optimize', '--combined-json', 'abi,bin,devdoc,userdoc'],
{'fraction_non_alphanumeric': 0.12076617612707312, 'fraction_numerical': 0.005372576500817566, 'mean_word_length': 2.3769716088328074, 'pattern_counts': {'":': 1, '<': 4, '<?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': '4472839', 'n_tokens_mistral': 1324, 'n_tokens_neox': 1283, 'n_words': 310}