<commit_before># Minimal Object Storage Library, (C) 2015 Minio, Inc.
#
# 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.

from .helpers import get_target_url
from .parsers import parse_list_objects, parse_error, parse_incomplete_uploads, parse_uploaded_parts
from .signer import sign_v4

__author__ = 'minio'


class ListObjectsIterator:
    def __init__(self, client, scheme, location, bucket, prefix, recursive, access_key, secret_key):
        self._http = client
        self._scheme = scheme
        self._location = location
        self._bucket = bucket
        self._prefix = prefix
        self._recursive = recursive
        self._results = []
        self._complete = False
        self._access_key = access_key
        self._secret_key = secret_key
        self._is_truncated = True
        self._marker = None

    def __iter__(self):
        return self

    def next(self):
        return self.__next__()

    def __next__(self):
        # if complete, end iteration
        if self._complete:
            raise StopIteration
        # if not truncated and we've emitted everything, end iteration
        if len(self._results) == 0 and self._is_truncated is False:
            self._complete = True
            raise StopIteration
        # perform another fetch
        if len(self._results) == 0:
            self._results, self._is_truncated, self._marker = self._fetch()
        # if fetch results in no elements, end iteration
        if len(self._results) == 0:
            self._complete = True
            raise StopIteration
        # return result
        return self._results.pop(0)

    def _fetch(self):
        query = {}
        if self._prefix is not None:
            query['prefix'] = self._prefix
        if not self._recursive:
            query['delimiter'] = '%2F'
        if self._marker is not None:
            query['marker'] = self._marker

        url = get_target_url(self._scheme, self._location, bucket=self._bucket, query=query)

        method = 'GET'
        headers = {}

        headers = sign_v4(method=method, url=url, headers=headers, access_key=self._access_key,
                          secret_key=self._secret_key)

        response = self._http.request(method, url, headers=headers)

        if response.status != 200:<commit_msg>Fix delimiter being double encoded. Fixes #199.<commit_after># Minimal Object Storage Library, (C) 2015 Minio, Inc.
#
# 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.

from .helpers import get_target_url
from .parsers import parse_list_objects, parse_error, parse_incomplete_uploads, parse_uploaded_parts
from .signer import sign_v4

__author__ = 'minio'


class ListObjectsIterator:
    def __init__(self, client, scheme, location, bucket, prefix, recursive, access_key, secret_key):
        self._http = client
        self._scheme = scheme
        self._location = location
        self._bucket = bucket
        self._prefix = prefix
        self._recursive = recursive
        self._results = []
        self._complete = False
        self._access_key = access_key
        self._secret_key = secret_key
        self._is_truncated = True
        self._marker = None

    def __iter__(self):
        return self

    def next(self):
        return self.__next__()

    def __next__(self):
        # if complete, end iteration
        if self._complete:
            raise StopIteration
        # if not truncated and we've emitted everything, end iteration
        if len(self._results) == 0 and self._is_truncated is False:
            self._complete = True
            raise StopIteration
        # perform another fetch
        if len(self._results) == 0:
            self._results, self._is_truncated, self._marker = self._fetch()
        # if fetch results in no elements, end iteration
        if len(self._results) == 0:
            self._complete = True
            raise StopIteration
        # return result
        return self._results.pop(0)

    def _fetch(self):
        query = {}
        if self._prefix is not None:
            query['prefix'] = self._prefix
        if not self._recursive:
            query['delimiter'] = '/'
        if self._marker is not None:
            query['marker'] = self._marker

        url = get_target_url(self._scheme, self._location, bucket=self._bucket, query=query)

        method = 'GET'
        headers = {}

        headers = sign_v4(method=method, url=url, headers=headers, access_key=self._access_key,
                          secret_key=self._secret_key)

        response = self._http.request(method, url, headers=headers)

        if response.status != 200:
{'fraction_non_alphanumeric': 0.08125, 'fraction_numerical': 0.0067857142857142855, 'mean_word_length': 2.500625, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4898745', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1464, 'n_words': 502}