<commit_before># Copyright (c) 2010 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import os
from contextlib import contextmanager
from tempfile import NamedTemporaryFile

from swift.common import internal_proxy
from swift.stats import log_processor


@contextmanager
def tmpfile(content):
    with NamedTemporaryFile('w', delete=False) as f:
        file_name = f.name
        f.write(str(content))
    try:
        yield file_name
    finally:
        os.unlink(file_name)


class FakeUploadApp(object):
    def __init__(self, *args, **kwargs):
        pass


class DumbLogger(object):
    def __getattr__(self, n):
        return self.foo

    def foo(self, *a, **kw):
        pass

class DumbInternalProxy(object):
    def get_container_list(self, account, container, marker=None):
        n = '2010/03/14/13/obj1'
        if marker is None or n > marker:
            return [{'name': n}]
        else:
            return []

    def get_object(self, account, container, object_name):
        code = 200
        if object_name.endswith('.gz'):
            # same data as below, compressed with gzip -9
            def data():
                yield '\x1f\x8b\x08'
                yield '\x08"\xd79L'
                yield '\x02\x03te'
                yield 'st\x00\xcbO'
                yield '\xca\xe2JI,I'
                yield '\xe4\x02\x00O\xff'
                yield '\xa3Y\t\x00\x00\x00'
        else:
            def data():
                yield 'obj\n'<commit_msg>fixed unit test to include knowledge of end_marker<commit_after># Copyright (c) 2010 OpenStack, LLC.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import unittest
import os
from contextlib import contextmanager
from tempfile import NamedTemporaryFile

from swift.common import internal_proxy
from swift.stats import log_processor


@contextmanager
def tmpfile(content):
    with NamedTemporaryFile('w', delete=False) as f:
        file_name = f.name
        f.write(str(content))
    try:
        yield file_name
    finally:
        os.unlink(file_name)


class FakeUploadApp(object):
    def __init__(self, *args, **kwargs):
        pass


class DumbLogger(object):
    def __getattr__(self, n):
        return self.foo

    def foo(self, *a, **kw):
        pass

class DumbInternalProxy(object):
    def get_container_list(self, account, container, marker=None,
                           end_marker=None):
        n = '2010/03/14/13/obj1'
        if marker is None or n > marker:
            if end_marker and n <= end_marker:
                return [{'name': n}]
            elif end_marker:
                return []
            return [{'name': n}]
        return []

    def get_object(self, account, container, object_name):
        code = 200
        if object_name.endswith('.gz'):
            # same data as below, compressed with gzip -9
            def data():
                yield '\x1f\x8b\x08'
                yield '\x08"\xd79L'
                yield '\x02\x03te'
                yield 'st\x00\xcbO'
                yield '\xca\xe2JI,I'
                yield '\xe4\x02\x00O\xff'
                yield '\xa3Y\t\x00\x00\x00'
        else:
            def data():
                yield 'obj\n'
{'fraction_non_alphanumeric': 0.09289099526066351, 'fraction_numerical': 0.023696682464454975, 'mean_word_length': 2.2619783616692426, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 5, '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': '5510328', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1211, 'n_words': 413}