Selfie
Loading...
Searching...
No Matches
ConvertToWindowsNewlines.py
Go to the documentation of this file.
2 def __init__(self, sink):
3 self.sink = sink
4
5 def append(self, value, start_index=None, end_index=None):
6 # If value is a single character
7 if isinstance(value, str) and len(value) == 1:
8 if value != "\n":
9 self.sink.write(value)
10 else:
11 self.sink.write("\r\n")
12 # If value is a CharSequence (in Python, a str)
13 elif isinstance(value, str):
14 # If start_index and end_index are provided, use the slice of the string
15 if start_index is not None and end_index is not None:
16 value_to_append = value[start_index:end_index]
17 else:
18 value_to_append = value
19 self.sink.write(value_to_append.replace("\n", "\r\n"))
20 return self
append(self, value, start_index=None, end_index=None)