# Path: honeyterm_asciinema/asciinema/asciinema/http_adapter.py
# class HTTPConnectionError(Exception):
#     pass


import codecs
import mimetypes
import sys
import uuid
import io
import base64
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
from .http_adapter import HTTPConnectionError
        for chunk, chunk_len in self.iter(fields, files):
            body.write(chunk)
        return self.content_type, body.getvalue()


class URLLibHttpAdapter:

    def post(self, url, fields={}, files={}, headers={}, username=None, password=None):
        content_type, body = MultipartFormdataEncoder().encode(fields, files)

        headers = headers.copy()
        headers["Content-Type"] = content_type

        if password:
            auth = "%s:%s" % (username, password)
            encoded_auth = base64.encodestring(auth.encode('utf-8'))[:-1]
            headers["Authorization"] = b"Basic %" + encoded_auth

        request = Request(url, data=body, headers=headers, method="POST")

        try:
            response = urlopen(request)
            status = response.status
            headers = self._parse_headers(response)
            body = response.read().decode('utf-8')
        except HTTPError as e:
            status = e.code
            headers = {}
            body = e.read().decode('utf-8')
        except URLError as e:

# Path: honeyterm_asciinema/asciinema/asciinema/http_adapter.py
# class HTTPConnectionError(Exception):
#     pass


# Path: honeyterm_asciinema/asciinema/asciinema/urllib_http_adapter.py
import codecs
import mimetypes
import sys
import uuid
import io
import base64
from urllib.request import Request, urlopen
from urllib.error import HTTPError, URLError
from .http_adapter import HTTPConnectionError

        for chunk, chunk_len in self.iter(fields, files):
            body.write(chunk)
        return self.content_type, body.getvalue()


class URLLibHttpAdapter:

    def post(self, url, fields={}, files={}, headers={}, username=None, password=None):
        content_type, body = MultipartFormdataEncoder().encode(fields, files)

        headers = headers.copy()
        headers["Content-Type"] = content_type

        if password:
            auth = "%s:%s" % (username, password)
            encoded_auth = base64.encodestring(auth.encode('utf-8'))[:-1]
            headers["Authorization"] = b"Basic %" + encoded_auth

        request = Request(url, data=body, headers=headers, method="POST")

        try:
            response = urlopen(request)
            status = response.status
            headers = self._parse_headers(response)
            body = response.read().decode('utf-8')
        except HTTPError as e:
            status = e.code
            headers = {}
            body = e.read().decode('utf-8')
        except URLError as e:

            raise HTTPConnectionError(str(e))