<commit_before>"""
Eureka Client Library.

Eureka is a service discovery and registration service
built by Netflix and used in the Spring Cloud stack.
"""
import asyncio
import atexit
import enum
import uuid
from typing import Optional, Dict, Any

from aiohttp import ClientSession

try:
    import ujson as json
except ImportError:
    import json

_SESSION = ClientSession(headers={
    # They default to using XML.
    'Accept': 'application/json',
    'Content-Type': 'application/json',
})
atexit.register(_SESSION.close)


class StatusType(enum.Enum):
    """
    Available status types with eureka, these can be used
    for any `EurekaClient.register` call to pl
    """
    UP = 'UP'
    DOWN = 'DOWN'
    STARTING = 'STARTING'
    OUT_OF_SERVICE = 'OUT_OF_SERVICE'
    UNKNOWN = 'UNKNOWN'


class EurekaClient:
    __slots__ = ('_loop', '_eureka_url', '_app_name', '_port', '_hostname',
                 '_ip_addr', '_instance_id', '_health_check_url',
                 '_status_page_url',)

    """
    A really naive eureka client.
    """

    def __init__(self, app_name: str, port: int, ip_addr: str, *,
                 hostname: Optional[str] = None,
                 eureka_url: str = 'http://localhost:8765/eureka/',
                 loop: Optional[asyncio.BaseEventLoop] = None,
                 instance_id: Optional[str] = None,
                 health_check_url: Optional[str] = None,
                 status_page_url: Optional[str] = None):
        """
        Naive eureka client, only supports the base operations.

        :param app_name: Application name, this is used to register/find
                         by name.
        :param port: Application port that is accessible
        :param ip_addr: IP Address the server is available on
        :param hostname: Host name of the machine, if not reachable by
                         DNS, use the IP. If not provided, the IP is
                         used by default.
        :param eureka_url: Eureka server url, including path.
        :param loop: Event loop to operate on
        :param instance_id: Server instance ID, you should only really
                            set this if you need to operate on an existing
                            registered service.
        :param health_check_url: Health check URL if available, not required. But
                                 if included it should return 2xx.
        :param status_page_url: URL for server status (info route?), It's required
                                to not crash the Spring Eureka UI, but otherwise
                                not required. If not included - we will just use
                                the server IP with '/info'.
        """
        self._loop = loop or asyncio.get_event_loop()
        if eureka_url.endswith('/'):
            eureka_url = eureka_url[:-1]
        self._eureka_url = eureka_url
        self._app_name = app_name
        self._port = port
        self._hostname = hostname or ip_addr
        self._ip_addr = ip_addr
        self._health_check_url = health_check_url
        # Not including this seems to crash the Eureka UI,
        # it's just a link from eureka over so if none is
        # given we just give it a sane default. It being
        # a 404 doesn't seem to matter.
        if status_page_url is None:
            status_page_url = ip_addr + '/info'
        self._status_page_url = status_page_url

        # unique id for the application, only really required
        # if this instance wants to register with Eureka instead
        # of just being a consumer.
        self._instance_id = instance_id or '{}:{}:{}'.format(
            str(uuid.uuid4()), app_name, port
        )
<commit_msg>Minor pep8 fixes linting caught in travis<commit_after>"""
Eureka Client Library.

Eureka is a service discovery and registration service
built by Netflix and used in the Spring Cloud stack.
"""
import asyncio
import atexit
import enum
import uuid
from typing import Optional, Dict, Any

from aiohttp import ClientSession

try:
    import ujson as json
except ImportError:
    import json

_SESSION = ClientSession(headers={
    # They default to using XML.
    'Accept': 'application/json',
    'Content-Type': 'application/json',
})
atexit.register(_SESSION.close)


class StatusType(enum.Enum):
    """
    Available status types with eureka, these can be used
    for any `EurekaClient.register` call to pl
    """
    UP = 'UP'
    DOWN = 'DOWN'
    STARTING = 'STARTING'
    OUT_OF_SERVICE = 'OUT_OF_SERVICE'
    UNKNOWN = 'UNKNOWN'


class EurekaClient:
    __slots__ = ('_loop', '_eureka_url', '_app_name', '_port', '_hostname',
                 '_ip_addr', '_instance_id', '_health_check_url',
                 '_status_page_url',)

    """
    A really naive eureka client.
    """

    def __init__(self, app_name: str, port: int, ip_addr: str, *,
                 hostname: Optional[str] = None,
                 eureka_url: str = 'http://localhost:8765/eureka/',
                 loop: Optional[asyncio.BaseEventLoop] = None,
                 instance_id: Optional[str] = None,
                 health_check_url: Optional[str] = None,
                 status_page_url: Optional[str] = None):
        """
        Naive eureka client, only supports the base operations.

        :param app_name: Application name, this is used to register/find
                         by name.
        :param port: Application port that is accessible
        :param ip_addr: IP Address the server is available on
        :param hostname: Host name of the machine, if not reachable by
                         DNS, use the IP. If not provided, the IP is
                         used by default.
        :param eureka_url: Eureka server url, including path.
        :param loop: Event loop to operate on
        :param instance_id: Server instance ID, you should only really
                            set this if you need to operate on an existing
                            registered service.
        :param health_check_url: Health check URL if available, not required.
                                 But if included it should return 2xx.
        :param status_page_url: URL for server status (info route?), It's
                                required to not crash the Spring Eureka UI,
                                but otherwise not required. If not included -
                                we will just use the server IP with '/info'.
        """
        self._loop = loop or asyncio.get_event_loop()
        if eureka_url.endswith('/'):
            eureka_url = eureka_url[:-1]
        self._eureka_url = eureka_url
        self._app_name = app_name
        self._port = port
        self._hostname = hostname or ip_addr
        self._ip_addr = ip_addr
        self._health_check_url = health_check_url
        # Not including this seems to crash the Eureka UI,
        # it's just a link from eureka over so if none is
        # given we just give it a sane default. It being
        # a 404 doesn't seem to matter.
        if status_page_url is None:
            status_page_url = ip_addr + '/info'
        self._status_page_url = status_page_url

        # unique id for the application, only really required
        # if this instance wants to register with Eureka instead
        # of just being a consumer.
        self._instance_id = instance_id or '{}:{}:{}'.format(
            str(uuid.uuid4()), app_name, port
        )

{'fraction_non_alphanumeric': 0.07589165996245642, 'fraction_numerical': 0.0028157683024939663, 'mean_word_length': 2.0235103364410216, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2795820', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2016, 'n_words': 746}