<commit_before>""" Store packages in GCS """
import posixpath
from datetime import timedelta

import logging
from google.cloud import storage

from .object_store import ObjectStoreStorage
from pypicloud.models import Package


LOG = logging.getLogger(__name__)


class GoogleCloudStorage(ObjectStoreStorage):

    """ Storage backend that uses GCS """
    test = False

    def __init__(self, request, **kwargs):
        super(GoogleCloudStorage, self).__init__(request=request, **kwargs)

        if self.public_url:
            # TODO
            raise NotImplementedError(
                'GoogleCloudStorage backend does not yet support public URLs')

        if self.sse:
            raise NotImplementedError(
                'GoogleCloudStorage backend does not yet support customized '
                'server-side encryption')

    @classmethod
    def get_bucket(cls, bucket_name, settings):
        client = storage.Client()

        bucket = client.bucket(bucket_name)

        if not bucket.exists():
            LOG.info("Creating GCS bucket %s", bucket_name)
            bucket.location = settings.get('storage.region_name')
            bucket.create()

        return bucket

    @classmethod
    def package_from_object(cls, blob, factory):
        """ Create a package from a GCS object """
        filename = posixpath.basename(blob.name)
        name = blob.metadata.get('name')
        version = blob.metadata.get('version')
        summary = blob.metadata.get('summary')

        return factory(name, version, filename, blob.updated, summary,
                       path=blob.name)<commit_msg>remove TODO comment string<commit_after>""" Store packages in GCS """
import posixpath
from datetime import timedelta

import logging
from google.cloud import storage

from .object_store import ObjectStoreStorage
from pypicloud.models import Package


LOG = logging.getLogger(__name__)


class GoogleCloudStorage(ObjectStoreStorage):

    """ Storage backend that uses GCS """
    test = False

    def __init__(self, request, **kwargs):
        super(GoogleCloudStorage, self).__init__(request=request, **kwargs)

        if self.public_url:
            raise NotImplementedError(
                'GoogleCloudStorage backend does not yet support public URLs')

        if self.sse:
            raise NotImplementedError(
                'GoogleCloudStorage backend does not yet support customized '
                'server-side encryption')

    @classmethod
    def get_bucket(cls, bucket_name, settings):
        client = storage.Client()

        bucket = client.bucket(bucket_name)

        if not bucket.exists():
            LOG.info("Creating GCS bucket %s", bucket_name)
            bucket.location = settings.get('storage.region_name')
            bucket.create()

        return bucket

    @classmethod
    def package_from_object(cls, blob, factory):
        """ Create a package from a GCS object """
        filename = posixpath.basename(blob.name)
        name = blob.metadata.get('name')
        version = blob.metadata.get('version')
        summary = blob.metadata.get('summary')

        return factory(name, version, filename, blob.updated, summary,
                       path=blob.name)
{'fraction_non_alphanumeric': 0.08839950372208437, 'fraction_numerical': 0.0, 'mean_word_length': 2.6235955056179776, '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': '5968966', 'n_tokens_mistral': 838, 'n_tokens_neox': 798, 'n_words': 237}