<commit_before># -*- coding: utf-8 -*-
import asyncio
import logging
from grapheneapi.exceptions import NumRetriesReached

from grapheneapi.api import Api as SyncApi
from .websocket import Websocket
from .http import Http

log = logging.getLogger(__name__)


class Api(SyncApi):
    def __init__(self, *args, **kwargs):
        # We're need to keep class init synchronous, so we're skipping connect()
        super().__init__(connect=False, *args, **kwargs)
        self._chain_props = None

    def updated_connection(self):
        if self.url[:2] == "ws":
            return Websocket(self.url, **self._kwargs)
        elif self.url[:4] == "http":
            return Http(self.url, **self._kwargs)
        else:
            raise ValueError("Only support http(s) and ws(s) connections!")

    @property
    def chain_params(self):
        return self.get_network()

    def get_network(self):
        return self._chain_props

    async def cache_chain_properties(self):
        """ Cache chain properties to prevent turning lots of methods into async
        """
        self._chain_props = await self.get_chain_properties()

    def get_cached_chain_properties(self):
        return self._chain_props

    async def connect(self):
        try:
            await self.connection.connect()
        except Exception as e:
            log.warning(str(e))
            self.error_url()
            await self.next()
        self.register_apis()
        await self.cache_chain_properties()

    async def disconnect(self):
        await self.connection.disconnect()

    async def next(self):
        await self.connection.disconnect()
        self.url = self.find_next()
        await self.connect()

    async def find_next(self):
        """ Find the next url in the list
        """
        if int(self.num_retries) < 0:  # pragma: no cover
            self._cnt_retries += 1
            sleeptime = (self._cnt_retries - 1) * 2 if self._cnt_retries < 10 else 10
            if sleeptime:
                log.warning(<commit_msg>Fix calling of coroutine function<commit_after># -*- coding: utf-8 -*-
import asyncio
import logging
from grapheneapi.exceptions import NumRetriesReached

from grapheneapi.api import Api as SyncApi
from .websocket import Websocket
from .http import Http

log = logging.getLogger(__name__)


class Api(SyncApi):
    def __init__(self, *args, **kwargs):
        # We're need to keep class init synchronous, so we're skipping connect()
        super().__init__(connect=False, *args, **kwargs)
        self._chain_props = None

    def updated_connection(self):
        if self.url[:2] == "ws":
            return Websocket(self.url, **self._kwargs)
        elif self.url[:4] == "http":
            return Http(self.url, **self._kwargs)
        else:
            raise ValueError("Only support http(s) and ws(s) connections!")

    @property
    def chain_params(self):
        return self.get_network()

    def get_network(self):
        return self._chain_props

    async def cache_chain_properties(self):
        """ Cache chain properties to prevent turning lots of methods into async
        """
        self._chain_props = await self.get_chain_properties()

    def get_cached_chain_properties(self):
        return self._chain_props

    async def connect(self):
        try:
            await self.connection.connect()
        except Exception as e:
            log.warning(str(e))
            self.error_url()
            await self.next()
        self.register_apis()
        await self.cache_chain_properties()

    async def disconnect(self):
        await self.connection.disconnect()

    async def next(self):
        await self.connection.disconnect()
        self.url = await self.find_next()
        await self.connect()

    async def find_next(self):
        """ Find the next url in the list
        """
        if int(self.num_retries) < 0:  # pragma: no cover
            self._cnt_retries += 1
            sleeptime = (self._cnt_retries - 1) * 2 if self._cnt_retries < 10 else 10
            if sleeptime:
                log.warning(
{'fraction_non_alphanumeric': 0.09887420460107685, 'fraction_numerical': 0.0053842388644150755, 'mean_word_length': 2.3776859504132233, 'pattern_counts': {'":': 4, '<': 7, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1166772', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1144, 'n_words': 328}