[pypy-commit] pypy default: mangle RStringIO attr names so they don't clash with implementations
bdkearns
noreply at buildbot.pypy.org
Fri Apr 12 07:22:37 CEST 2013
Author: Brian Kearns <bdkearns at gmail.com>
Branch:
Changeset: r63262:1a0242a40bd1
Date: 2013-04-11 21:52 -0400
http://bitbucket.org/pypy/pypy/changeset/1a0242a40bd1/
Log: mangle RStringIO attr names so they don't clash with implementations
diff --git a/rpython/rlib/rStringIO.py b/rpython/rlib/rStringIO.py
--- a/rpython/rlib/rStringIO.py
+++ b/rpython/rlib/rStringIO.py
@@ -12,166 +12,166 @@
def __init__(self):
# The real content is the join of the following data:
- # * the list of characters self.bigbuffer;
- # * each of the strings in self.strings.
+ # * the list of characters self.__bigbuffer;
+ # * each of the strings in self.__strings.
#
- self.closed = False
- self.strings = None
- self.bigbuffer = None
- self.pos = AT_END
+ self.__closed = False
+ self.__strings = None
+ self.__bigbuffer = None
+ self.__pos = AT_END
def close(self):
- self.closed = True
- self.strings = None
- self.bigbuffer = None
- self.pos = AT_END
+ self.__closed = True
+ self.__strings = None
+ self.__bigbuffer = None
+ self.__pos = AT_END
def is_closed(self):
- return self.closed
+ return self.__closed
- def _copy_into_bigbuffer(self):
- """Copy all the data into the list of characters self.bigbuffer."""
- if self.bigbuffer is None:
- self.bigbuffer = []
- if self.strings is not None:
- self.bigbuffer += self.strings.build()
- self.strings = None
+ def __copy_into_bigbuffer(self):
+ """Copy all the data into the list of characters self.__bigbuffer."""
+ if self.__bigbuffer is None:
+ self.__bigbuffer = []
+ if self.__strings is not None:
+ self.__bigbuffer += self.__strings.build()
+ self.__strings = None
def getvalue(self):
- """If self.strings contains more than 1 string, join all the
+ """If self.__strings contains more than 1 string, join all the
strings together. Return the final single string."""
- if self.bigbuffer is not None:
- self._copy_into_bigbuffer()
- return ''.join(self.bigbuffer)
- if self.strings is not None:
- return self.strings.build()
+ if self.__bigbuffer is not None:
+ self.__copy_into_bigbuffer()
+ return ''.join(self.__bigbuffer)
+ if self.__strings is not None:
+ return self.__strings.build()
return ''
def getsize(self):
result = 0
- if self.bigbuffer is not None:
- result += len(self.bigbuffer)
- if self.strings is not None:
- result += self.strings.getlength()
+ if self.__bigbuffer is not None:
+ result += len(self.__bigbuffer)
+ if self.__strings is not None:
+ result += self.__strings.getlength()
return result
def write(self, buffer):
# Idea: for the common case of a sequence of write() followed
- # by only getvalue(), self.bigbuffer remains empty. It is only
+ # by only getvalue(), self.__bigbuffer remains empty. It is only
# used to handle the more complicated cases.
- if self.pos == AT_END:
- self._fast_write(buffer)
+ if self.__pos == AT_END:
+ self.__fast_write(buffer)
else:
- self._slow_write(buffer)
+ self.__slow_write(buffer)
- def _fast_write(self, buffer):
- if self.strings is None:
- self.strings = StringBuilder()
- self.strings.append(buffer)
+ def __fast_write(self, buffer):
+ if self.__strings is None:
+ self.__strings = StringBuilder()
+ self.__strings.append(buffer)
- def _slow_write(self, buffer):
- p = self.pos
+ def __slow_write(self, buffer):
+ p = self.__pos
assert p >= 0
endp = p + len(buffer)
- if self.bigbuffer is not None and len(self.bigbuffer) >= endp:
- # semi-fast path: the write is entirely inside self.bigbuffer
+ if self.__bigbuffer is not None and len(self.__bigbuffer) >= endp:
+ # semi-fast path: the write is entirely inside self.__bigbuffer
for i in range(len(buffer)):
- self.bigbuffer[p + i] = buffer[i]
+ self.__bigbuffer[p + i] = buffer[i]
else:
- # slow path: collect all data into self.bigbuffer and
+ # slow path: collect all data into self.__bigbuffer and
# handle the various cases
- self._copy_into_bigbuffer()
- fitting = len(self.bigbuffer) - p
+ self.__copy_into_bigbuffer()
+ fitting = len(self.__bigbuffer) - p
if fitting > 0:
# the write starts before the end of the data
fitting = min(len(buffer), fitting)
for i in range(fitting):
- self.bigbuffer[p + i] = buffer[i]
+ self.__bigbuffer[p + i] = buffer[i]
if len(buffer) > fitting:
# the write extends beyond the end of the data
- self.bigbuffer += buffer[fitting:]
+ self.__bigbuffer += buffer[fitting:]
endp = AT_END
else:
# the write starts at or beyond the end of the data
- self.bigbuffer += '\x00' * (-fitting) + buffer
+ self.__bigbuffer += '\x00' * (-fitting) + buffer
endp = AT_END
- self.pos = endp
+ self.__pos = endp
def seek(self, position, mode=0):
if mode == 1:
- if self.pos == AT_END:
- self.pos = self.getsize()
- position += self.pos
+ if self.__pos == AT_END:
+ self.__pos = self.getsize()
+ position += self.__pos
elif mode == 2:
if position == 0:
- self.pos = AT_END
+ self.__pos = AT_END
return
position += self.getsize()
if position < 0:
position = 0
- self.pos = position
+ self.__pos = position
def tell(self):
- if self.pos == AT_END:
+ if self.__pos == AT_END:
result = self.getsize()
else:
- result = self.pos
+ result = self.__pos
assert result >= 0
return result
def read(self, n=-1):
- p = self.pos
+ p = self.__pos
if p == 0 and n < 0:
- self.pos = AT_END
+ self.__pos = AT_END
return self.getvalue() # reading everything
if p == AT_END or n == 0:
return ''
assert p >= 0
- self._copy_into_bigbuffer()
- mysize = len(self.bigbuffer)
+ self.__copy_into_bigbuffer()
+ mysize = len(self.__bigbuffer)
count = mysize - p
if n >= 0:
count = min(n, count)
if count <= 0:
return ''
if p == 0 and count == mysize:
- self.pos = AT_END
- return ''.join(self.bigbuffer)
+ self.__pos = AT_END
+ return ''.join(self.__bigbuffer)
else:
- self.pos = p + count
- return ''.join(self.bigbuffer[p:p+count])
+ self.__pos = p + count
+ return ''.join(self.__bigbuffer[p:p+count])
def readline(self, size=-1):
- p = self.pos
+ p = self.__pos
if p == AT_END or size == 0:
return ''
assert p >= 0
- self._copy_into_bigbuffer()
- end = len(self.bigbuffer)
+ self.__copy_into_bigbuffer()
+ end = len(self.__bigbuffer)
if size >= 0 and size < end - p:
end = p + size
i = p
while i < end:
- finished = self.bigbuffer[i] == '\n'
+ finished = self.__bigbuffer[i] == '\n'
i += 1
if finished:
break
- self.pos = i
- return ''.join(self.bigbuffer[p:i])
+ self.__pos = i
+ return ''.join(self.__bigbuffer[p:i])
def truncate(self, size):
# NB. 'size' is mandatory. This has the same un-Posix-y semantics
# than CPython: it never grows the buffer, and it sets the current
# position to the end.
assert size >= 0
- if self.bigbuffer is None or size > len(self.bigbuffer):
- self._copy_into_bigbuffer()
+ if self.__bigbuffer is None or size > len(self.__bigbuffer):
+ self.__copy_into_bigbuffer()
else:
# we can drop all extra strings
- if self.strings is not None:
- self.strings = None
- if size < len(self.bigbuffer):
- del self.bigbuffer[size:]
- if len(self.bigbuffer) == 0:
- self.bigbuffer = None
- self.pos = AT_END
+ if self.__strings is not None:
+ self.__strings = None
+ if size < len(self.__bigbuffer):
+ del self.__bigbuffer[size:]
+ if len(self.__bigbuffer) == 0:
+ self.__bigbuffer = None
+ self.__pos = AT_END
More information about the pypy-commit
mailing list