<commit_before>"""
Cloud file storage is a custom file storage object to store files on GCS
"""

import uuid
import random
import string
from datetime import datetime
from django.conf import settings
from django.core.files.storage import Storage
from google_helpers import storage_service
from googleapiclient import http

storage = storage_service.get_storage_resource()

class CloudFileStorage(Storage):

    def __init__(self):
        pass

    def _open(self, name, mode):
        return storage.objects().get(bucket=settings.GCLOUD_BUCKET, object=name).execute()

    def _save(self, name, content):
        media = http.MediaInMemoryUpload(content)
        storage.objects().insert(
            bucket=settings.GCLOUD_BUCKET,
            name=name,
            media_body=media
        ).execute()
        return name

    def get_available_name(self, name):
        name = name.replace("./", "")
        time = datetime.now().strftime('%Y%m%d-%H%M%S%f')
        random_str = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(8))
        name = time + '-' + random_str + '-' + name
        name = settings.MEDIA_FOLDER + name
        return name<commit_msg>Changing storage object to instance variable<commit_after>"""
Cloud file storage is a custom file storage object to store files on GCS
"""

import uuid
import random
import string
from datetime import datetime
from django.conf import settings
from django.core.files.storage import Storage
from google_helpers import storage_service
from googleapiclient import http


class CloudFileStorage(Storage):

    def __init__(self):
        self.storage = storage_service.get_storage_resource()

    def _open(self, name, mode):
        return self.storage.objects().get(bucket=settings.GCLOUD_BUCKET, object=name).execute()

    def _save(self, name, content):
        media = http.MediaInMemoryUpload(content)
        self.storage.objects().insert(
            bucket=settings.GCLOUD_BUCKET,
            name=name,
            media_body=media
        ).execute()
        return name

    def get_available_name(self, name):
        name = name.replace("./", "")
        time = datetime.now().strftime('%Y%m%d-%H%M%S%f')
        random_str = ''.join(random.SystemRandom().choice(string.ascii_letters) for _ in range(8))
        name = time + '-' + random_str + '-' + name
        name = settings.MEDIA_FOLDER + name
        return name
{'fraction_non_alphanumeric': 0.10550268928423666, 'fraction_numerical': 0.0008274720728175424, 'mean_word_length': 3.154639175257732, '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': '2870908', 'n_tokens_mistral': 689, 'n_tokens_neox': 687, 'n_words': 181}