summaryrefslogtreecommitdiff
path: root/tools/libdol2asm/builder.py
blob: a927435b57571e094fc384511ffcb5ccb8d04e41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import os
import codecs
import asyncio
import aiofiles

class AsyncBuilder:
    """ Writes code to file asynchronous """
    
    def __init__(self, path):
        self.path = path
        self.new_line = "\n"

    async def write(self, text):
        await self.file.write(text)
        await self.file.write(self.new_line)
    
    async def write_nonewline(self, text):
        await self.file.write(text)

    async def __aenter__(self):
        self.file = await aiofiles.open(self.path, 'w', encoding="utf-8")
        return self

    async def __aexit__(self, type, value, traceback):
        await self.file.close()