<commit_before># SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center
#
# 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.
"""
Basic WebDAV implementation

Reason this exists: easywebdav is not Python 3 compatible, webdavclient is
flaky and not compatible with (at least) Beehub.
"""
import requests


def verify(acceptable_statuses, response, message):
    """
    Verify that the request gave an acceptable status_code and raises an
    IOError otherwise.
    """
    if response.status_code not in acceptable_statuses:
        header_str = '\n'.join(['{0}: {1}'.format(k, v)
                                for k, v in response.headers.lower_items()])
        raise IOError('{0}: HTTP status code {1}\nHeaders:\n{2}'
                      .format(message, response.status_code, header_str))


class RestRequests(object):
    """ Rest requests with a base URL. """
    def __init__(self, base_url, auth=None, **kwargs):
        """
        @param base_url: base url of the service
        @param auth: requests authentication tuple
        @param kwargs: kwargs to pass on to the requests.request() function
        """
        self.base_url = base_url.rstrip('/')
        self.auth = auth
        self.kwargs = kwargs

    def exists(self, path, **kwargs):
        """ Whether the path exists. """
        kwargs.update(self.kwargs)
        response = requests.head(self.path_to_url(path), auth=self.auth,
                                 **kwargs)
        return response.status_code == 200

    def put(self, path, data, content_type=None, content_length=None,
            **kwargs):
        """
        Put bytes, dict, or a file pointer.
        If a file pointer is given, the content_length needs to be specified,
        in bytes.
        """
        kwargs.update(self.kwargs)
        if content_type is None:
            headers = None
        else:
            headers = {'content-type': content_type}

        if content_length is None and hasattr(data, 'read'):<commit_msg>Do not accept redirects in dav.exists<commit_after># SIM-CITY client
#
# Copyright 2015 Netherlands eScience Center
#
# 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.
"""
Basic WebDAV implementation

Reason this exists: easywebdav is not Python 3 compatible, webdavclient is
flaky and not compatible with (at least) Beehub.
"""
import requests


def verify(acceptable_statuses, response, message):
    """
    Verify that the request gave an acceptable status_code and raises an
    IOError otherwise.
    """
    if response.status_code not in acceptable_statuses:
        header_str = '\n'.join(['{0}: {1}'.format(k, v)
                                for k, v in response.headers.lower_items()])
        raise IOError('{0}: HTTP status code {1}\nHeaders:\n{2}'
                      .format(message, response.status_code, header_str))


class RestRequests(object):
    """ Rest requests with a base URL. """
    def __init__(self, base_url, auth=None, **kwargs):
        """
        @param base_url: base url of the service
        @param auth: requests authentication tuple
        @param kwargs: kwargs to pass on to the requests.request() function
        """
        self.base_url = base_url.rstrip('/')
        self.auth = auth
        self.kwargs = kwargs

    def exists(self, path, **kwargs):
        """ Whether the path exists. """
        kwargs.update(self.kwargs)
        response = requests.head(self.path_to_url(path), auth=self.auth,
                                 allow_redirects=True, **kwargs)
        return response.status_code == 200

    def put(self, path, data, content_type=None, content_length=None,
            **kwargs):
        """
        Put bytes, dict, or a file pointer.
        If a file pointer is given, the content_length needs to be specified,
        in bytes.
        """
        kwargs.update(self.kwargs)
        if content_type is None:
            headers = None
        else:
            headers = {'content-type': content_type}

        if content_length is None and hasattr(data, 'read'):
{'fraction_non_alphanumeric': 0.09486873508353222, 'fraction_numerical': 0.006762132060461416, 'mean_word_length': 2.6494920174165455, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7007573', 'n_tokens_mistral': 1358, 'n_tokens_neox': 1321, 'n_words': 511}