# Path: peekaboo/db.py
# DB_SCHEMA_VERSION = 9
# class InFlightSample(Base):
# class SampleInfo(Base):
# class PeekabooDatabase:
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, db_url, instance_id=0,
#                  stale_in_flight_threshold=15*60,
#                  log_level=logging.WARNING,
#                  async_driver=None):
#     def was_transient_error(self, error, attempt, action):
#     async def analysis_add(self, sample):
#     def analysis_update(self, sample):
#     def analysis_journal_fetch_journal(self, sample):
#     async def analysis_retrieve(self, job_id):
#     def mark_sample_in_flight(self, sample, instance_id=None, start_time=None):
#     def clear_sample_in_flight(self, sample, instance_id=None):
#     def clear_in_flight_samples(self, instance_id=None):
#     def clear_stale_in_flight_samples(self):
#         def clear_statement(statement_class):
#     def drop(self):


import asyncio
import email.utils
import logging
import urllib.parse
import sanic
import sanic.headers
import sanic.response
from peekaboo.db import PeekabooDatabaseError
            form_header_value, form_parameters = sanic.headers.parse_content_header(
                form_line[idx:]
            )

            if form_header_field == 'content-disposition':
                field_name = form_parameters.get('name')
                file_name = form_parameters.get('filename')

                # non-ASCII filenames in RFC2231, "filename*" format
                if file_name is None and form_parameters.get('filename*'):
                    encoding, _, value = email.utils.decode_rfc2231(
                        form_parameters['filename*']
                    )
                    file_name = urllib.parse.unquote(value, encoding=encoding)
            elif form_header_field == 'content-type':
                content_type = form_header_value

        if field_name != 'file':
            logger.error('Field file missing from request')
            return sanic.response.json(
                {'message': 'Field "file" missing from request'}, 400)

        file_content = form_part[line_index:-4]
        content_disposition = request.headers.get('x-content-disposition')
        sample = self.sample_factory.make_sample(
            file_content, file_name,
            content_type, content_disposition)

        try:
            await self.db_con.analysis_add(sample)

# Path: peekaboo/db.py
# DB_SCHEMA_VERSION = 9
# class InFlightSample(Base):
# class SampleInfo(Base):
# class PeekabooDatabase:
#     def __str__(self):
#     def __str__(self):
#     def __init__(self, db_url, instance_id=0,
#                  stale_in_flight_threshold=15*60,
#                  log_level=logging.WARNING,
#                  async_driver=None):
#     def was_transient_error(self, error, attempt, action):
#     async def analysis_add(self, sample):
#     def analysis_update(self, sample):
#     def analysis_journal_fetch_journal(self, sample):
#     async def analysis_retrieve(self, job_id):
#     def mark_sample_in_flight(self, sample, instance_id=None, start_time=None):
#     def clear_sample_in_flight(self, sample, instance_id=None):
#     def clear_in_flight_samples(self, instance_id=None):
#     def clear_stale_in_flight_samples(self):
#         def clear_statement(statement_class):
#     def drop(self):


# Path: peekaboo/server.py
import asyncio
import email.utils
import logging
import urllib.parse
import sanic
import sanic.headers
import sanic.response
from peekaboo.db import PeekabooDatabaseError

            form_header_value, form_parameters = sanic.headers.parse_content_header(
                form_line[idx:]
            )

            if form_header_field == 'content-disposition':
                field_name = form_parameters.get('name')
                file_name = form_parameters.get('filename')

                # non-ASCII filenames in RFC2231, "filename*" format
                if file_name is None and form_parameters.get('filename*'):
                    encoding, _, value = email.utils.decode_rfc2231(
                        form_parameters['filename*']
                    )
                    file_name = urllib.parse.unquote(value, encoding=encoding)
            elif form_header_field == 'content-type':
                content_type = form_header_value

        if field_name != 'file':
            logger.error('Field file missing from request')
            return sanic.response.json(
                {'message': 'Field "file" missing from request'}, 400)

        file_content = form_part[line_index:-4]
        content_disposition = request.headers.get('x-content-disposition')
        sample = self.sample_factory.make_sample(
            file_content, file_name,
            content_type, content_disposition)

        try:
            await self.db_con.analysis_add(sample)

        except PeekabooDatabaseError as dberr: