| 2711 | """ |
| 2712 | |
| 2713 | def __init__(self, initial_value="", newline="\n"): |
| 2714 | super(StringIO, self).__init__(BytesIO(), |
| 2715 | encoding="utf-8", |
| 2716 | errors="surrogatepass", |
| 2717 | newline=newline) |
| 2718 | # Issue #5645: make universal newlines semantics the same as in the |
| 2719 | # C version, even under Windows. |
| 2720 | if newline is None: |
| 2721 | self._writetranslate = False |
| 2722 | if initial_value is not None: |
| 2723 | if not isinstance(initial_value, str): |
| 2724 | raise TypeError("initial_value must be str or None, not {0}" |
| 2725 | .format(type(initial_value).__name__)) |
| 2726 | self.write(initial_value) |
| 2727 | self.seek(0) |
| 2728 | |
| 2729 | def getvalue(self): |
| 2730 | self.flush() |