Commit c65bc875 authored by Stefan Behnel's avatar Stefan Behnel

reformat code

parent a7c82988
...@@ -217,42 +217,45 @@ def detect_opened_file_encoding(f): ...@@ -217,42 +217,45 @@ def detect_opened_file_encoding(f):
normalise_newlines = re.compile(u'\r\n?|\n').sub normalise_newlines = re.compile(u'\r\n?|\n').sub
class NormalisedNewlineStream(object): class NormalisedNewlineStream(object):
"""The codecs module doesn't provide universal newline support. """The codecs module doesn't provide universal newline support.
This class is used as a stream wrapper that provides this This class is used as a stream wrapper that provides this
functionality. The new 'io' in Py2.6+/3.x supports this out of the functionality. The new 'io' in Py2.6+/3.x supports this out of the
box. box.
""" """
def __init__(self, stream):
# let's assume .read() doesn't change def __init__(self, stream):
self.stream = stream # let's assume .read() doesn't change
self._read = stream.read self.stream = stream
self.close = stream.close self._read = stream.read
self.encoding = getattr(stream, 'encoding', 'UTF-8') self.close = stream.close
self.encoding = getattr(stream, 'encoding', 'UTF-8')
def read(self, count=-1):
data = self._read(count) def read(self, count=-1):
if u'\r' not in data: data = self._read(count)
return data if u'\r' not in data:
if data.endswith(u'\r'): return data
# may be missing a '\n' if data.endswith(u'\r'):
data += self._read(1) # may be missing a '\n'
return normalise_newlines(u'\n', data) data += self._read(1)
return normalise_newlines(u'\n', data)
def readlines(self):
content = [] def readlines(self):
data = self.read(0x1000) content = []
while data:
content.append(data)
data = self.read(0x1000) data = self.read(0x1000)
while data:
content.append(data)
data = self.read(0x1000)
return u''.join(content).splitlines(True) return u''.join(content).splitlines(True)
def seek(self, pos):
if pos == 0:
self.stream.seek(0)
else:
raise NotImplementedError
def seek(self, pos):
if pos == 0:
self.stream.seek(0)
else:
raise NotImplementedError
io = None io = None
if sys.version_info >= (2,6): if sys.version_info >= (2,6):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment