<commit_before># -*- coding: utf-8 -*-
"""Connection to InfluxDB"""
import json
import sys
try:
    from urlparse import urlparse
except ImportError:  # pragma: no cover
    from urllib.parse import urlparse    # pragma: no cover
if sys.version_info[0] >= 3:
    basestring = str  # pragma: no cover
else:
    basestring = basestring  # pragma: no cover

from tornado import gen, httpclient, httputil, ioloop

from asyncflux import clusteradmin, database
from asyncflux.errors import AsyncfluxError
from asyncflux.util import asyncflux_coroutine


class AsyncfluxClient(object):

    HOST = 'localhost'
    PORT = 8086
    USERNAME = 'root'
    PASSWORD = '<PASSWORD>'

    def __init__(self, host=None, port=None, username=None, password=<PASSWORD>,
                 is_secure=False, io_loop=None, **kwargs):
        scheme = 'https' if is_secure else 'http'
        host = host or self.HOST
        port = port or self.PORT
        username = username or self.USERNAME
        password = password or self.PASSWORD
        if not isinstance(port, int):
            raise TypeError("port must be an instance of int")

        if '://' in host:
            if host.startswith(('http://', 'https://')):
                result = urlparse(host)
                scheme = result.scheme
                host = result.hostname
                port = result.port or port
                username = result.username or username
                password = result.password or password
            else:
                index = host.find("://")
                raise ValueError('Invalid URL scheme: %s' % host[:index])

        self.__scheme = scheme
        self.__host = host
        self.__port = port
        self.__username = username
        self.__password = password

        self.__json = kwargs.get('json_module', json)
        self.io_loop = io_loop or ioloop.IOLoop.current()
        self.http_client = httpclient.AsyncHTTPClient(self.io_loop)

    @property
    def host(self):
        return self.__host

    @property
    def port(self):
        return self.__port

    @property
    def base_url(self):
        return '%s://%s:%s' % (self.__scheme, self.host, self.port, )

    @property
    def username(self):
        return self.__username

    @username.setter
    def username(self, value):
        self.__username = value

    @property
    def password(self):
        return self.__password

    @password.setter
    def password(self, value):
        self.__password = value

    def __getattr__(self, name):
        return database.Database(self, name)

    def __getitem__(self, name):
        return self.__getattr__(name)

    @asyncflux_coroutine
    def request(self, path, path_params=None, qs=None, body=None,
                method='GET'):
        try:
            path_params = path_params or {}
            qs = qs or {}

            url = (self.base_url + path) % path_params
            if isinstance(body, dict):
                body = self.__json.dumps(body)
            response = yield self.http_client.fetch(
                httputil.url_concat(url, qs), body=body, method=method,
                auth_username=self.username, auth_password=self.password)
            if hasattr(response, 'body') and response.body:
                raise gen.Return(self.__json.loads(response.body))<commit_msg>Username and password could be sent now on request method.<commit_after># -*- coding: utf-8 -*-
"""Connection to InfluxDB"""
import json
import sys
try:
    from urlparse import urlparse
except ImportError:  # pragma: no cover
    from urllib.parse import urlparse    # pragma: no cover
if sys.version_info[0] >= 3:
    basestring = str  # pragma: no cover
else:
    basestring = basestring  # pragma: no cover

from tornado import gen, httpclient, httputil, ioloop

from asyncflux import clusteradmin, database
from asyncflux.errors import AsyncfluxError
from asyncflux.util import asyncflux_coroutine


class AsyncfluxClient(object):

    HOST = 'localhost'
    PORT = 8086
    USERNAME = 'root'
    PASSWORD = '<PASSWORD>'

    def __init__(self, host=None, port=None, username=None, password=<PASSWORD>,
                 is_secure=False, io_loop=None, **kwargs):
        scheme = 'https' if is_secure else 'http'
        host = host or self.HOST
        port = port or self.PORT
        username = username or self.USERNAME
        password = password or self.PASSWORD
        if not isinstance(port, int):
            raise TypeError("port must be an instance of int")

        if '://' in host:
            if host.startswith(('http://', 'https://')):
                result = urlparse(host)
                scheme = result.scheme
                host = result.hostname
                port = result.port or port
                username = result.username or username
                password = result.password or password
            else:
                index = host.find("://")
                raise ValueError('Invalid URL scheme: %s' % host[:index])

        self.__scheme = scheme
        self.__host = host
        self.__port = port
        self.__username = username
        self.__password = password

        self.__json = kwargs.get('json_module', json)
        self.io_loop = io_loop or ioloop.IOLoop.current()
        self.http_client = httpclient.AsyncHTTPClient(self.io_loop)

    @property
    def host(self):
        return self.__host

    @property
    def port(self):
        return self.__port

    @property
    def base_url(self):
        return '%s://%s:%s' % (self.__scheme, self.host, self.port, )

    @property
    def username(self):
        return self.__username

    @username.setter
    def username(self, value):
        self.__username = value

    @property
    def password(self):
        return self.__password

    @password.setter
    def password(self, value):
        self.__password = value

    def __getattr__(self, name):
        return database.Database(self, name)

    def __getitem__(self, name):
        return self.__getattr__(name)

    @asyncflux_coroutine
    def request(self, path, path_params=None, qs=None, body=None,
                method='GET', auth_username=None, auth_password=None):
        try:
            path_params = path_params or {}
            qs = qs or {}
            auth_username = auth_username or self.username
            auth_password = auth_password or self.password

            url = (self.base_url + path) % path_params
            if isinstance(body, dict):
                body = self.__json.dumps(body)
            response = yield self.http_client.fetch(
                httputil.url_concat(url, qs), body=body, method=method,
                auth_username=auth_username, auth_password=<PASSWORD>)
            if hasattr(response, 'body') and response.body:
                raise gen.Return(self.__json.loads(response.body))
{'fraction_non_alphanumeric': 0.09777842736042093, 'fraction_numerical': 0.0020461853259280912, 'mean_word_length': 2.217207334273625, 'pattern_counts': {'":': 2, '<': 8, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '1413731', 'n_tokens_mistral': 1962, 'n_tokens_neox': 1879, 'n_words': 532}