def convert_changelog(lxml_path, changelog_file_path, rst2html_script, stylesheet_url): f = open_file(os.path.join(lxml_path, 'CHANGES.txt'), 'r', encoding='utf-8') try: content = f.read() finally: f.close() links = dict(LP='`%s <https://bugs.launchpad.net/lxml/+bug/%s>`_', GH='`%s <https://github.com/lxml/lxml/issues/%s>`_') replace_tracker_links = re.compile('((LP|GH)#([0-9]+))').sub def insert_link(match): text, ref_type, ref_id = match.groups() return links[ref_type] % (text, ref_id) content = replace_tracker_links(insert_link, content) command = [sys.executable, rst2html_script] + RST2HTML_OPTIONS.split() + [ '--link-stylesheet', '--stylesheet', stylesheet_url ] out_file = open(changelog_file_path, 'wb') try: rst2html = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=out_file) rst2html.communicate(content.encode('utf8')) finally: out_file.close()
def read_prediction(self): file_handle = io.open_file(self.predicted_file) for line in file_handle: self.predicted_labels.append(line.strip()) logger.i('read label successfully') return self.predicted_labels
def read_label(self): file_handle = io.open_file(self.label_file) for line in file_handle: self.gold_labels.append(line.strip()) logger.i('read label successfully') return self.gold_labels
def safe_open(filename, mode="rt", encoding=None, errors=None, newline=None, safe=True): truncated_write = "w" in mode and "+" not in mode if safe and truncated_write and not isinstance(filename, int): open_file = TemporarySaveFile else: from io import open as open_file return open_file(filename, mode, encoding=encoding, errors=errors, newline=newline)