def write(self, text): """ Write the file (after acquiring a lock). :param text: string to write to the file. """ with lock(self.path, 'w') as fp: fp.write(text)
def read(self, convert=False): """ Read the file (after acquiring a lock). :param convert: if the content is Markdown or reST (based on the file extension) attempt to convert it first. :return: string containing file contents. """ with lock(self.path, 'r') as fp: content = fp.read() if convert: if self.ext[1:] in ['md', 'mdown', 'markdown', 'mdwn']: return markdown_to_html(content) elif self.ext[1:] == 'rst': return rst_to_html(content) return content