<commit_before>"""
.. module:: python-etcd
   :synopsis: A python etcd client.

.. moduleauthor:: <NAME> <<EMAIL>>


"""
import urllib3
import json
import ssl

import etcd


class Client(object):
    """
    Client for etcd, the distributed log service using raft.
    """
    def __init__(
            self,
            host='127.0.0.1',
            port=4001,
            read_timeout=60,
            allow_redirect=True,
            protocol='http',
            cert = None,
            ca_cert = None,
    ):
        """
        Initialize the client.

        Args:
            host (str):  IP to connect to.

            port (int):  Port used to connect to etcd.

            read_timeout (int):  max seconds to wait for a read.

            allow_redirect (bool): allow the client to connect to other nodes.

            protocol (str):  Protocol used to connect to etcd.

            cert (mixed):   If a string, the whole ssl client certificate;
                            if a tuple, the cert and key file names.

            ca_cert (str): The ca certificate. If pressent it will enable validation.

        """
        self._host = host
        self._port = port
        self._protocol = protocol
        self._base_uri = "%s://%s:%d" % (protocol, host, port)
        self.version_prefix = '/v1'

        self._read_timeout = read_timeout
        self._allow_redirect = allow_redirect

        self._MGET = 'GET'
        self._MPOST = 'POST'
        self._MDELETE = 'DELETE'

        # Dictionary of exceptions given an etcd return code.
        # 100: Key not found.
        # 101: The given PrevValue is not equal to the value of the key
        # 102: Not a file  if the /foo = Node(bar) exists,
        #      setting /foo/foo = Node(barbar)
        # 103: Reached the max number of machines in the cluster
        # 300: Raft Internal Error
        # 301: During Leader Election
        # 500: Watcher is cleared due to etcd recovery
        self.error_codes = {
            100: KeyError,
            101: ValueError,
            102: KeyError,
            103: Exception,
            300: Exception,
            301: Exception,
            500: etcd.EtcdException,
            999: etcd.EtcdException}

        # SSL Client certificate support

        kw = {}

        if protocol == 'https':
            kw['ssl_version'] = ssl.PROTOCOL_TLSv1

            if cert:
                if isinstance(cert, tuple):
                    # Key and cert are separate
                    kw['cert_file'] = cert[0]
                    kw['key_file'] = cert[1]
                else:
                    #combined certificate
                    kw['cert_file'] = cert

            if ca_cert:
                kw['ca_certs'] = ca_cert
                kw['cert_reqs'] = ssl.CERT_REQUIRED
                kw['ssl_version'] = ssl.PROTOCOL_SSLv3

        self.http = urllib3.PoolManager(num_pools=10, **kw)

    @property
    def base_uri(self):
        """URI used by the client to connect to etcd."""
        return self._base_uri

    @property
    def host(self):
        """Node to connect  etcd."""
        return self._host

    @property
    def port(self):
        """Port to connect etcd."""
        return self._port

    @property
    def protocol(self):
        """Protocol used to connect etcd."""
        return self._protocol

    @property
    def read_timeout(self):
        """Max seconds to wait for a read."""
        return self._read_timeout
<commit_msg>Removed incorrect SSLv3 protocol support<commit_after>"""
.. module:: python-etcd
   :synopsis: A python etcd client.

.. moduleauthor:: <NAME> <<EMAIL>>


"""
import urllib3
import json
import ssl

import etcd


class Client(object):
    """
    Client for etcd, the distributed log service using raft.
    """
    def __init__(
            self,
            host='127.0.0.1',
            port=4001,
            read_timeout=60,
            allow_redirect=True,
            protocol='http',
            cert = None,
            ca_cert = None,
    ):
        """
        Initialize the client.

        Args:
            host (str):  IP to connect to.

            port (int):  Port used to connect to etcd.

            read_timeout (int):  max seconds to wait for a read.

            allow_redirect (bool): allow the client to connect to other nodes.

            protocol (str):  Protocol used to connect to etcd.

            cert (mixed):   If a string, the whole ssl client certificate;
                            if a tuple, the cert and key file names.

            ca_cert (str): The ca certificate. If pressent it will enable validation.

        """
        self._host = host
        self._port = port
        self._protocol = protocol
        self._base_uri = "%s://%s:%d" % (protocol, host, port)
        self.version_prefix = '/v1'

        self._read_timeout = read_timeout
        self._allow_redirect = allow_redirect

        self._MGET = 'GET'
        self._MPOST = 'POST'
        self._MDELETE = 'DELETE'

        # Dictionary of exceptions given an etcd return code.
        # 100: Key not found.
        # 101: The given PrevValue is not equal to the value of the key
        # 102: Not a file  if the /foo = Node(bar) exists,
        #      setting /foo/foo = Node(barbar)
        # 103: Reached the max number of machines in the cluster
        # 300: Raft Internal Error
        # 301: During Leader Election
        # 500: Watcher is cleared due to etcd recovery
        self.error_codes = {
            100: KeyError,
            101: ValueError,
            102: KeyError,
            103: Exception,
            300: Exception,
            301: Exception,
            500: etcd.EtcdException,
            999: etcd.EtcdException}

        # SSL Client certificate support

        kw = {}

        if protocol == 'https':
            kw['ssl_version'] = ssl.PROTOCOL_TLSv1

            if cert:
                if isinstance(cert, tuple):
                    # Key and cert are separate
                    kw['cert_file'] = cert[0]
                    kw['key_file'] = cert[1]
                else:
                    #combined certificate
                    kw['cert_file'] = cert

            if ca_cert:
                kw['ca_certs'] = ca_cert
                kw['cert_reqs'] = ssl.CERT_REQUIRED

        self.http = urllib3.PoolManager(num_pools=10, **kw)

    @property
    def base_uri(self):
        """URI used by the client to connect to etcd."""
        return self._base_uri

    @property
    def host(self):
        """Node to connect  etcd."""
        return self._host

    @property
    def port(self):
        """Port to connect etcd."""
        return self._port

    @property
    def protocol(self):
        """Protocol used to connect etcd."""
        return self._protocol

    @property
    def read_timeout(self):
        """Max seconds to wait for a read."""
        return self._read_timeout

{'fraction_non_alphanumeric': 0.092560553633218, 'fraction_numerical': 0.01903114186851211, 'mean_word_length': 1.5952113729891508, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '6136239', 'n_tokens_mistral': 2025, 'n_tokens_neox': 1870, 'n_words': 630}