<commit_before>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import elf
import os
import re
import stat
import string
import util

class Magic:
    def __init__(self, path, basedir):
	self.path = path
	self.basedir = basedir
	self.contents = {}
	self.name = self.__class__.__name__


class ELF(Magic):
    def __init__(self, path, basedir='', buffer=''):
	Magic.__init__(self, path, basedir)
        fullpath = basedir+path
	self.contents['stripped'] = elf.stripped(fullpath)
        if self.__class__ is ELF:
            # ar doesn't deal with hasDebug or RPATH
            self.contents['hasDebug'] = elf.hasDebug(fullpath)
            self.contents['RPATH'] = elf.getRPATH(fullpath)
	requires, provides = elf.inspect(fullpath)
        self.contents['requires'] = requires
        self.contents['provides'] = provides
        for req in requires:
            if req[0] == 'abi':
                self.contents['abi'] = req[1:]
        for prov in provides:
            if prov[0] == 'soname':
                self.contents['soname'] = prov[1]

class ar(ELF):
    def __init__(self, path, basedir='', buffer=''):
	ELF.__init__(self, path, basedir)
	# no point in looking for __.SYMDEF because GNU ar always keeps
	# symbol table up to date
        # ar archives, like ELF files, are investigated by our elf module.
        # We do still want to be able to distinguish between them via magic,
        # thus the two classes.


class gzip(Magic):
    def __init__(self, path, basedir='', buffer=''):
	Magic.__init__(self, path, basedir)
	if buffer[3] == '\x08':
	    self.contents['name'] = _string(buffer[10:])
	if buffer[8] == '\x02':
	    self.contents['compression'] = '9'
	else:
	    self.contents['compression'] = '1'

<commit_msg>add magic interface to elf.getType<commit_after>#
# Copyright (c) 2004-2005 rPath, Inc.
#
# This program is distributed under the terms of the Common Public License,
# version 1.0. A copy of this license should have been distributed with this
# source file in a file called LICENSE. If it is not present, the license
# is always available at http://www.opensource.org/licenses/cpl.php.
#
# This program is distributed in the hope that it will be useful, but
# without any waranty; without even the implied warranty of merchantability
# or fitness for a particular purpose. See the Common Public License for
# full details.
#

import elf
import os
import re
import stat
import string
import util

class Magic:
    def __init__(self, path, basedir):
	self.path = path
	self.basedir = basedir
	self.contents = {}
	self.name = self.__class__.__name__


class ELF(Magic):
    def __init__(self, path, basedir='', buffer=''):
	Magic.__init__(self, path, basedir)
        fullpath = basedir+path
	self.contents['stripped'] = elf.stripped(fullpath)
        if self.__class__ is ELF:
            # ar doesn't deal with hasDebug or RPATH
            self.contents['hasDebug'] = elf.hasDebug(fullpath)
            self.contents['RPATH'] = elf.getRPATH(fullpath)
            self.contents['Type'] = elf.getType(fullpath)
	requires, provides = elf.inspect(fullpath)
        self.contents['requires'] = requires
        self.contents['provides'] = provides
        for req in requires:
            if req[0] == 'abi':
                self.contents['abi'] = req[1:]
        for prov in provides:
            if prov[0] == 'soname':
                self.contents['soname'] = prov[1]

class ar(ELF):
    def __init__(self, path, basedir='', buffer=''):
	ELF.__init__(self, path, basedir)
	# no point in looking for __.SYMDEF because GNU ar always keeps
	# symbol table up to date
        # ar archives, like ELF files, are investigated by our elf module.
        # We do still want to be able to distinguish between them via magic,
        # thus the two classes.


class gzip(Magic):
    def __init__(self, path, basedir='', buffer=''):
	Magic.__init__(self, path, basedir)
	if buffer[3] == '\x08':
	    self.contents['name'] = _string(buffer[10:])
	if buffer[8] == '\x02':
	    self.contents['compression'] = '9'
	else:
	    self.contents['compression'] = '1'


{'fraction_non_alphanumeric': 0.11272490786906568, 'fraction_numerical': 0.01040537611099068, 'mean_word_length': 3.1605049594229033, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3161188', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1365, 'n_words': 492}