[pypy-svn] r53761 - in pypy/dist/pypy: module/cStringIO rlib
arigo at codespeak.net
arigo at codespeak.net
Mon Apr 14 17:58:33 CEST 2008
Author: arigo
Date: Mon Apr 14 17:58:31 2008
New Revision: 53761
Modified:
pypy/dist/pypy/module/cStringIO/interp_stringio.py
pypy/dist/pypy/rlib/rStringIO.py
Log:
Translation fixes.
Modified: pypy/dist/pypy/module/cStringIO/interp_stringio.py
==============================================================================
--- pypy/dist/pypy/module/cStringIO/interp_stringio.py (original)
+++ pypy/dist/pypy/module/cStringIO/interp_stringio.py Mon Apr 14 17:58:31 2008
@@ -108,6 +108,8 @@
count = len(self.string) - p
if n >= 0:
count = min(n, count)
+ if count <= 0:
+ return ''
self.pos = p + count
if count == len(self.string):
return self.string
@@ -207,7 +209,6 @@
common_descrs = {
'__iter__': interp2app(W_InputOutputType.descr___iter__),
'close': interp2app(W_InputOutputType.descr_close),
- 'closed': GetSetProperty(descr_closed, cls=W_InputOutputType),
'flush': interp2app(W_InputOutputType.descr_flush),
'getvalue': interp2app(W_InputOutputType.descr_getvalue),
'isatty': interp2app(W_InputOutputType.descr_isatty),
@@ -217,15 +218,16 @@
'readlines': interp2app(W_InputOutputType.descr_readlines),
'reset': interp2app(W_InputOutputType.descr_reset),
'seek': interp2app(W_InputOutputType.descr_seek),
- 'softspace': GetSetProperty(descr_softspace,
- descr_setsoftspace,
- cls=W_InputOutputType),
'tell': interp2app(W_InputOutputType.descr_tell),
}
W_InputType.typedef = TypeDef(
"cStringIO.StringI",
__doc__ = "Simple type for treating strings as input file streams",
+ closed = GetSetProperty(descr_closed, cls=W_InputType),
+ softspace = GetSetProperty(descr_softspace,
+ descr_setsoftspace,
+ cls=W_InputType),
**common_descrs
# XXX CPython has the truncate() method here too, which is a bit strange
)
@@ -236,6 +238,10 @@
truncate = interp2app(W_OutputType.descr_truncate),
write = interp2app(W_OutputType.descr_write),
writelines = interp2app(W_OutputType.descr_writelines),
+ closed = GetSetProperty(descr_closed, cls=W_OutputType),
+ softspace = GetSetProperty(descr_softspace,
+ descr_setsoftspace,
+ cls=W_OutputType),
**common_descrs
)
Modified: pypy/dist/pypy/rlib/rStringIO.py
==============================================================================
--- pypy/dist/pypy/rlib/rStringIO.py (original)
+++ pypy/dist/pypy/rlib/rStringIO.py Mon Apr 14 17:58:31 2008
@@ -97,6 +97,7 @@
# used to handle the more complicated cases.
p = self.pos
if p != AT_END: # slow or semi-fast paths
+ assert p >= 0
endp = p + len(buffer)
if len(self.bigbuffer) >= endp:
# semi-fast path: the write is entirely inside self.bigbuffer
@@ -148,9 +149,11 @@
def tell(self):
if self.pos == AT_END:
- return self.getsize()
+ result = self.getsize()
else:
- return self.pos
+ result = self.pos
+ assert result >= 0
+ return result
def read(self, n=-1):
p = self.pos
@@ -159,6 +162,7 @@
return self.getvalue() # reading everything
if p == AT_END:
return ''
+ assert p >= 0
bigbuffer = self.copy_into_bigbuffer()
mysize = len(bigbuffer)
count = mysize - p
More information about the Pypy-commit
mailing list