<commit_before>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by <NAME>
This file is part of the CernVM File System auxiliary tools.
"""

import ctypes
import tempfile
import zlib
import sqlite3
import subprocess


_REPO_CONFIG_PATH      = "/etc/cvmfs/repositories.d"
_SERVER_CONFIG_NAME    = "server.conf"

_REST_CONNECTOR        = "control"

_MANIFEST_NAME         = ".cvmfspublished"
_LAST_REPLICATION_NAME = ".cvmfs_last_snapshot"
_REPLICATING_NAME      = ".cvmfs_is_snapshotting"


class CvmfsNotInstalled(Exception):
    def __init__(self):
        Exception.__init__(self, "It seems that cvmfs is not installed on this machine!")


class CompressedObject:
    file_ = None

    def __init__(self, compressed_file):
        self._decompress(compressed_file)

    def __del__(self):
        if self.file_:
            self.file_.close()

    def _decompress(self, compressed_file):
        """ Unzip a file to a temporary referenced by self.file_ """
        self.file_ = tempfile.NamedTemporaryFile('w+b')
        self.file_.write(zlib.decompress(compressed_file.read()))
        self.file_.flush()


class DatabaseObject(CompressedObject):
    db_handle_ = None

    def __init__(self, compressed_db_file):
        CompressedObject.__init__(self, compressed_db_file)
        self._open_database()

    def __del__(self):
        if self.db_handle_:
            self.db_handle_.close()

    def _open_database(self):
        """ Create and configure a database handle to the Catalog """
        self.db_handle_ = sqlite3.connect(self.file_.name)
        self.db_handle_.text_factory = str
<commit_msg>CompressedObject() does not close tmp file<commit_after>#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created by <NAME>
This file is part of the CernVM File System auxiliary tools.
"""

import ctypes
import tempfile
import zlib
import sqlite3
import subprocess


_REPO_CONFIG_PATH      = "/etc/cvmfs/repositories.d"
_SERVER_CONFIG_NAME    = "server.conf"

_REST_CONNECTOR        = "control"

_MANIFEST_NAME         = ".cvmfspublished"
_LAST_REPLICATION_NAME = ".cvmfs_last_snapshot"
_REPLICATING_NAME      = ".cvmfs_is_snapshotting"


class CvmfsNotInstalled(Exception):
    def __init__(self):
        Exception.__init__(self, "It seems that cvmfs is not installed on this machine!")


class CompressedObject:
    file_ = None

    def __init__(self, compressed_file):
        self._decompress(compressed_file)

    def _decompress(self, compressed_file):
        """ Unzip a file to a temporary referenced by self.file_ """
        self.file_ = tempfile.NamedTemporaryFile('w+b')
        self.file_.write(zlib.decompress(compressed_file.read()))
        self.file_.flush()
        self.file_.seek(0)

    def _close(self):
        if self.file_:
            self.file_.close()



class DatabaseObject(CompressedObject):
    db_handle_ = None

    def __init__(self, compressed_db_file):
        CompressedObject.__init__(self, compressed_db_file)
        self._open_database()

    def __del__(self):
        if self.db_handle_:
            self.db_handle_.close()
        self._close()

    def _open_database(self):
        """ Create and configure a database handle to the Catalog """
        self.db_handle_ = sqlite3.connect(self.file_.name)
        self.db_handle_.text_factory = str

{'fraction_non_alphanumeric': 0.09867229933614967, 'fraction_numerical': 0.002112251056125528, 'mean_word_length': 3.154135338345865, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '5865373', 'n_tokens_mistral': 1072, 'n_tokens_neox': 1020, 'n_words': 235}