<commit_before>#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Interpreter version: python 2.7
#
# Imports =====================================================================



# Variables ===================================================================



# Functions & classes =========================================================



# Main program ================================================================
if __name__ == '__main__':
    pass<commit_msg>Added process_request().<commit_after>#! /usr/bin/env python
# -*- coding: utf-8 -*-
#
# Interpreter version: python 2.7
#
# Imports =====================================================================
import sys
import base64
import os.path
import tempfile

path = os.path.dirname(__file__)
sys.path.insert(0, os.path.join(path, "../src/edeposit/amqp"))

try:
    from rest import settings
    from rest.database import CacheHandler
    from rest.structures import UploadRequest
except ImportError:
    from edeposit.amqp.rest import settings
    from edeposit.amqp.rest.database import CacheHandler
    from edeposit.amqp.rest.structures import UploadRequest


# Variables ===================================================================



# Functions & classes =========================================================
def send(req):
    pass


def process_request():
    cache_db = CacheHandler()

    if cache_db.is_empty():
        return

    with cache_db.pop_manager() as cached_request:
        fp = cached_request.get_file_obj()

        with tempfile.TemporaryFile() as f:
            base64.encode(fp, f)

            f.seek(0)
            req = UploadRequest(
                username=cached_request.username,
                rest_id=cached_request.rest_id,
                b64_data=f.read(),
                metadata=cached_request.metadata,
            )

        fp.close()
        send(req)


# Main program ================================================================
if __name__ == '__main__':
    process_request()
{'fraction_non_alphanumeric': 0.3326732673267327, 'fraction_numerical': 0.006930693069306931, 'mean_word_length': 3.7777777777777777, 'pattern_counts': {'":': 0, '<': 3, '<?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': '3294202', 'n_tokens_mistral': 539, 'n_tokens_neox': 475, 'n_words': 109}