Commit 26dfaacd authored by Ezio Melotti's avatar Ezio Melotti

Merged revisions 78757 via svnmerge from

svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78757 | florent.xicluna | 2010-03-07 14:14:25 +0200 (Sun, 07 Mar 2010) | 2 lines

  Fix some py3k warnings in the standard library.
........
parent 1c9972e6
...@@ -564,6 +564,10 @@ c = TextCalendar() ...@@ -564,6 +564,10 @@ c = TextCalendar()
firstweekday = c.getfirstweekday firstweekday = c.getfirstweekday
def setfirstweekday(firstweekday): def setfirstweekday(firstweekday):
try:
firstweekday.__index__
except AttributeError:
raise IllegalWeekdayError(firstweekday)
if not MONDAY <= firstweekday <= SUNDAY: if not MONDAY <= firstweekday <= SUNDAY:
raise IllegalWeekdayError(firstweekday) raise IllegalWeekdayError(firstweekday)
c.firstweekday = firstweekday c.firstweekday = firstweekday
......
...@@ -132,7 +132,7 @@ class Callbacks(unittest.TestCase): ...@@ -132,7 +132,7 @@ class Callbacks(unittest.TestCase):
gc.collect() gc.collect()
live = [x for x in gc.get_objects() live = [x for x in gc.get_objects()
if isinstance(x, X)] if isinstance(x, X)]
self.failUnlessEqual(len(live), 0) self.assertEqual(len(live), 0)
try: try:
WINFUNCTYPE WINFUNCTYPE
...@@ -164,7 +164,7 @@ class SampleCallbacksTestCase(unittest.TestCase): ...@@ -164,7 +164,7 @@ class SampleCallbacksTestCase(unittest.TestCase):
result = integrate(0.0, 1.0, CALLBACK(func), 10) result = integrate(0.0, 1.0, CALLBACK(func), 10)
diff = abs(result - 1./3.) diff = abs(result - 1./3.)
self.failUnless(diff < 0.01, "%s not less than 0.01" % diff) self.assertTrue(diff < 0.01, "%s not less than 0.01" % diff)
################################################################ ################################################################
......
...@@ -405,7 +405,7 @@ def execute (func, args, msg=None, verbose=0, dry_run=0): ...@@ -405,7 +405,7 @@ def execute (func, args, msg=None, verbose=0, dry_run=0):
log.info(msg) log.info(msg)
if not dry_run: if not dry_run:
apply(func, args) func(*args)
def strtobool (val): def strtobool (val):
......
...@@ -849,8 +849,8 @@ class _BytesIO(BufferedIOBase): ...@@ -849,8 +849,8 @@ class _BytesIO(BufferedIOBase):
if self.closed: if self.closed:
raise ValueError("seek on closed file") raise ValueError("seek on closed file")
try: try:
pos = pos.__index__() pos.__index__
except AttributeError as err: except AttributeError:
raise TypeError("an integer is required") # from err raise TypeError("an integer is required") # from err
if whence == 0: if whence == 0:
if pos < 0: if pos < 0:
...@@ -874,8 +874,13 @@ class _BytesIO(BufferedIOBase): ...@@ -874,8 +874,13 @@ class _BytesIO(BufferedIOBase):
raise ValueError("truncate on closed file") raise ValueError("truncate on closed file")
if pos is None: if pos is None:
pos = self._pos pos = self._pos
elif pos < 0: else:
raise ValueError("negative truncate position %r" % (pos,)) try:
pos.__index__
except AttributeError:
raise TypeError("an integer is required")
if pos < 0:
raise ValueError("negative truncate position %r" % (pos,))
del self._buffer[pos:] del self._buffer[pos:]
return pos return pos
...@@ -1752,6 +1757,10 @@ class TextIOWrapper(TextIOBase): ...@@ -1752,6 +1757,10 @@ class TextIOWrapper(TextIOBase):
if n is None: if n is None:
n = -1 n = -1
decoder = self._decoder or self._get_decoder() decoder = self._decoder or self._get_decoder()
try:
n.__index__
except AttributeError:
raise TypeError("an integer is required")
if n < 0: if n < 0:
# Read everything. # Read everything.
result = (self._get_decoded_chars() + result = (self._get_decoded_chars() +
......
...@@ -29,7 +29,7 @@ def _show_warning(message, category, filename, lineno, file=None, line=None): ...@@ -29,7 +29,7 @@ def _show_warning(message, category, filename, lineno, file=None, line=None):
file.write(formatwarning(message, category, filename, lineno, line)) file.write(formatwarning(message, category, filename, lineno, line))
except IOError: except IOError:
pass # the file (probably stderr) is invalid - this warning gets lost. pass # the file (probably stderr) is invalid - this warning gets lost.
# Keep a worrking version around in case the deprecation of the old API is # Keep a working version around in case the deprecation of the old API is
# triggered. # triggered.
showwarning = _show_warning showwarning = _show_warning
......
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