示例#1
0
async def hash_handler(request):
    input_val = request.match_info['input_str']
    output_val = sha512(
        input_val.encode('utf-8')).hexdigest() if input_val is not None else ''
    async with aioopen(LOG_FILE, 'a') as f:
        await f.write('in: "{}", out: "{}" \n'.format(input_val, output_val))
    return web.json_response({'output_str': output_val})
示例#2
0
async def dump(path: str, data: str):
    """
    Asynchronous file dumper.

    :param path: file's relative path concernedly the project's root
    :param data: string data to be written
    """
    async with aioopen(join(BASE_DIR, path), 'w+') as stream:
        await stream.write(data)
示例#3
0
async def load(path: str) -> str:
    """
    Asynchronous file loader.

    :param path: file's relative path concernedly the project's root
    :return: file's content
    """
    async with aioopen(join(BASE_DIR, path)) as stream:
        return await stream.read()
async def _create_main_file_in_workflow_dir(workflow_components: dict,
                                            dir_path: str):
    main_file_path = path.join(dir_path,
                               BUILDER.get("MAIN_FILE_NAME", "main.py"))

    async with aioopen(main_file_path, mode="w") as nf:
        async with aioopen(BUILDER.get("TEMPLATE_FILE"), mode="r") as f:
            async for line in f:
                if BUILDER.get("IMPORTS_COMMENT", "IMPORT") in line:
                    await nf.write("\n".join(
                        workflow_components.get("imports", [])))
                elif BUILDER.get("MAIN_COMMENT", "MAIN") in line:
                    await nf.write("\n".join(
                        workflow_components.get("calls", [])))
                else:
                    await nf.write(line)

    workflow_components["files"].append(main_file_path)
async def _create_requirements_file_in_workflow_dir(workflow_components: dict,
                                                    dir_path: str):
    requirements_file_path = path.join(
        dir_path, BUILDER.get("REQUIREMENTS_FILE_NAME", "requirements.txt"))

    async with aioopen(requirements_file_path, mode="w") as requirements_file:
        await requirements_file.write("\n".join(
            workflow_components.get("requirements", [])))

    workflow_components["files"].append(requirements_file_path)
示例#6
0
async def load(file="./wire-nio.json"):
    async with aioopen(file, "r") as f:
        string = await f.read()
        return ClientState.parse_raw(string)
示例#7
0
async def save(client_config: ClientState, file="./wire-nio.json"):
    async with aioopen(file, "w") as f:
        json = client_config.json()
        await f.write(json)