1
0
mirror of https://github.com/gryf/ebook-converter.git synced 2026-02-27 04:35:58 +01:00
Files
ebook-converter/ebook_converter/ebooks/txt/newlines.py
gryf 48fedea799 Removing unneeded from __future__ import statements.
Since we are on Python 3.6 and up, we don't need those anymore.
2020-04-19 17:39:02 +02:00

31 lines
735 B
Python

import os
__license__ = 'GPL 3'
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
class TxtNewlines(object):
NEWLINE_TYPES = {
'system' : os.linesep,
'unix' : '\n',
'old_mac' : '\r',
'windows' : '\r\n'
}
def __init__(self, newline_type):
self.newline = self.NEWLINE_TYPES.get(newline_type.lower(), os.linesep)
def specified_newlines(newline, text):
# Convert all newlines to \n
text = text.replace('\r\n', '\n')
text = text.replace('\r', '\n')
if newline == '\n':
return text
return text.replace('\n', newline)