<commit_before>import io
import os
import base64
import urllib
import aiohttp
import asyncio
import hashlib
import tarfile
import json
import datetime as dt
import ssl

from .channel import Channel
from .utils import identical
from .multiplexed import MultiplexedResult
from .jsonstream import JsonStreamResult


class Docker:
    def __init__(self,
                 url=os.environ.get('DOCKER_HOST', "/run/docker.sock"),
                 connector=None,
                 session=None,
                 ssl_context=None):
        self.url = url
        self.events = DockerEvents(self)
        self.containers = DockerContainers(self)
        self.images = DockerImages(self)
        self.volumes = DockerVolumes(self)
        if connector is None:
            if url.startswith('http://'):
                connector = aiohttp.TCPConnector()
            elif url.startswith('https://'):
                connector = aiohttp.TCPConnector(ssl_context=ssl_context)
            elif url.startswith('unix://'):
                connector = aiohttp.connector.UnixConnector(url[8:])
                self.url = "http://docker" #aiohttp treats this as a proxy
            elif url.startswith('/'):
                connector = aiohttp.connector.UnixConnector(url)
                self.url = "http://docker" #aiohttp treats this as a proxy
            else:
                connector = aiohttp.connector.UnixConnector(url)
        self.connector = connector
        if session is None:
            session = aiohttp.ClientSession(connector=self.connector)
        self.session = session

    @asyncio.coroutine
    def auth(self, **credentials):
        response = yield from self._query_json(
            "auth", "POST",
            data=credentials,
            headers={"content-type": "application/json",},
        )
        return response

    @asyncio.coroutine
    def pull(self, image, stream=False):
        response = yield from self._query(
            "images/create", "POST",
            params={"fromImage": image},
            headers={"content-type": "application/json",},
        )
        json_stream = yield from self._json_stream_result(response, stream=stream)
        return json_stream<commit_msg>Add docker.version API.<commit_after>import io
import os
import base64
import urllib
import aiohttp
import asyncio
import hashlib
import tarfile
import json
import datetime as dt
import ssl

from .channel import Channel
from .utils import identical
from .multiplexed import MultiplexedResult
from .jsonstream import JsonStreamResult


class Docker:
    def __init__(self,
                 url=os.environ.get('DOCKER_HOST', "/run/docker.sock"),
                 connector=None,
                 session=None,
                 ssl_context=None):
        self.url = url
        self.events = DockerEvents(self)
        self.containers = DockerContainers(self)
        self.images = DockerImages(self)
        self.volumes = DockerVolumes(self)
        if connector is None:
            if url.startswith('http://'):
                connector = aiohttp.TCPConnector()
            elif url.startswith('https://'):
                connector = aiohttp.TCPConnector(ssl_context=ssl_context)
            elif url.startswith('unix://'):
                connector = aiohttp.connector.UnixConnector(url[8:])
                self.url = "http://docker" #aiohttp treats this as a proxy
            elif url.startswith('/'):
                connector = aiohttp.connector.UnixConnector(url)
                self.url = "http://docker" #aiohttp treats this as a proxy
            else:
                connector = aiohttp.connector.UnixConnector(url)
        self.connector = connector
        if session is None:
            session = aiohttp.ClientSession(connector=self.connector)
        self.session = session

    @asyncio.coroutine
    def auth(self, **credentials):
        response = yield from self._query_json(
            "auth", "POST",
            data=credentials,
            headers={"content-type": "application/json",},
        )
        return response

    @asyncio.coroutine
    def version(self):
        data = yield from self._query_json("version")
        return data

    @asyncio.coroutine
    def pull(self, image, stream=False):
        response = yield from self._query(
            "images/create", "POST",
            params={"fromImage": image},
            headers={"content-type": "application/json",},
        )
        json_stream = yield from self._json_stream_result(response, stream=stream)
        return json_stream
{'fraction_non_alphanumeric': 0.09742687486254674, 'fraction_numerical': 0.0013195513525401364, 'mean_word_length': 2.1804195804195805, 'pattern_counts': {'":': 6, '<': 3, '<?xml version=': 0, '>': 3, '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': '6230758', 'n_tokens_mistral': 1252, 'n_tokens_neox': 1208, 'n_words': 300}