<commit_before>
from . import Cache
from . import copy_file_or_flo
import os
import logging

logger = logging.getLogger(__name__)


class S3Cache(Cache):

    '''A cache that transfers files to and from an S3 bucket

     '''

    base_priority = 30  # Priority for this class of cache.

    def __init__(self, bucket=None, prefix=None, account=None,
                 upstream=None, cdn=None, options=None, **kwargs):
        '''Init a new S3Cache Cache

        '''
        from boto.s3.connection import S3Connection

        super(S3Cache, self).__init__(upstream=upstream)

        self.is_remote = False
        self.bucket_name = bucket
        self.prefix = prefix

        self.account = account
        self.access_key = account['access']
        self.secret = account['secret']


        self.conn = S3Connection(self.access_key, self.secret, is_secure=False)
        self._bucket = None

        self.options = options

        self.cdn = None
        self.cdn_config = None

        if cdn:
            self._init_cdn(cdn)

    def clone(self):
        from boto.s3.connection import S3Connection

        return S3Cache(
            bucket=self.bucket,
            prefix=self.prefix,
            account=self.account,
            options=self.options,
            upstream=self.upstream,
            cdn=self.cdn,
            **self.args)

    @property
    def bucket(self):
        if not self._bucket:
            self._bucket = self.conn.get_bucket(self.bucket_name)

        return self._bucket

    def _init_cdn(self, config):
        import boto
        import time
        from boto.cloudfront import CloudFrontConnection
        from boto.cloudfront.distribution import Distribution

        self.cdn_config = config

        class _cdn(object):
            conn = CloudFrontConnection(config['access'], config['secret'])
            dist = Distribution(connection=conn, id=config['id'])
            domain_name = config['domain']
            key_pair_id = config['key_pair_id']  # from the AWS accounts page
            priv_key_file = config['key_file']  # your private keypair file<commit_msg>S3 was making connection on object instance, rather than first access<commit_after>
from . import Cache
from . import copy_file_or_flo
import os
import logging

logger = logging.getLogger(__name__)


class S3Cache(Cache):

    '''A cache that transfers files to and from an S3 bucket

     '''

    base_priority = 30  # Priority for this class of cache.

    def __init__(self, bucket=None, prefix=None, account=None,
                 upstream=None, cdn=None, options=None, **kwargs):
        '''Init a new S3Cache Cache

        '''
        from boto.s3.connection import S3Connection

        super(S3Cache, self).__init__(upstream=upstream)

        self.is_remote = False
        self.bucket_name = bucket
        self.prefix = prefix

        self.account = account
        self.access_key = account['access']
        self.secret = account['secret']


        self.conn = S3Connection(self.access_key, self.secret, is_secure=False)
        self._bucket = None

        self.options = options

        self.cdn = None
        self.cdn_config = None

        if cdn:
            self._init_cdn(cdn)

    def clone(self):

        return S3Cache(
            bucket=self.bucket,
            prefix=self.prefix,
            account=self.account,
            options=self.options,
            upstream=self.upstream,
            cdn=self.cdn,
            **self.args)

    @property
    def bucket(self):
        if not self._bucket:
            self._bucket = self.conn.get_bucket(self.bucket_name)

        return self._bucket

    def _init_cdn(self, config):

        import time
        from boto.cloudfront import CloudFrontConnection
        from boto.cloudfront.distribution import Distribution

        self.cdn_config = config

        class _cdn(object):
            conn = CloudFrontConnection(config['access'], config['secret'])
            dist = Distribution(connection=conn, id=config['id'])
            domain_name = config['domain']
            key_pair_id = config['key_pair_id']  # from the AWS accounts page
            priv_key_file = config['key_file']  # your private keypair file
{'fraction_non_alphanumeric': 0.08875739644970414, 'fraction_numerical': 0.00544378698224852, 'mean_word_length': 2.211246200607903, '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': '1943890', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1139, 'n_words': 295}