Commit 262a47d2 authored by Ezio Melotti's avatar Ezio Melotti

Merged revisions 75407,75409-75413,75415,75419-75421 via svnmerge from

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

........
  r75407 | antoine.pitrou | 2009-10-14 20:30:52 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix py3k warnings in the aifc module
........
  r75409 | antoine.pitrou | 2009-10-14 21:01:33 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix py3k warnings in bsddb
........
  r75410 | antoine.pitrou | 2009-10-14 21:09:45 +0300 (Wed, 14 Oct 2009) | 3 lines

  Silence a py3k warning claiming to affect Lib/calendar.py
........
  r75411 | antoine.pitrou | 2009-10-14 21:12:54 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix a py3k warning in the StringIO module (exhibited in test_codecencodings_cn)
........
  r75412 | antoine.pitrou | 2009-10-14 21:27:32 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix py3k warnings in the socket module
........
  r75413 | antoine.pitrou | 2009-10-14 21:31:05 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix a py3k warning in the sndhdr module (found with test_email)
........
  r75415 | antoine.pitrou | 2009-10-14 21:39:46 +0300 (Wed, 14 Oct 2009) | 3 lines

  Silence some py3k warnings claiming to affect _pyio
........
  r75419 | antoine.pitrou | 2009-10-14 21:56:11 +0300 (Wed, 14 Oct 2009) | 3 lines

  Silence py3k warning claiming to affect the random module
........
  r75420 | antoine.pitrou | 2009-10-14 22:04:48 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix py3k warnings in httplib
........
  r75421 | antoine.pitrou | 2009-10-14 22:09:48 +0300 (Wed, 14 Oct 2009) | 3 lines

  Fix py3k warnings in the uuid module
........
parent efcdd849
...@@ -128,7 +128,7 @@ class StringIO: ...@@ -128,7 +128,7 @@ class StringIO:
if self.buflist: if self.buflist:
self.buf += ''.join(self.buflist) self.buf += ''.join(self.buflist)
self.buflist = [] self.buflist = []
if n < 0: if n is None or n < 0:
newpos = self.len newpos = self.len
else: else:
newpos = min(self.pos+n, self.len) newpos = min(self.pos+n, self.len)
......
...@@ -409,7 +409,7 @@ class Aifc_read: ...@@ -409,7 +409,7 @@ class Aifc_read:
data = self._ssnd_chunk.read(nframes * self._framesize) data = self._ssnd_chunk.read(nframes * self._framesize)
if self._convert and data: if self._convert and data:
data = self._convert(data) data = self._convert(data)
self._soundpos = self._soundpos + len(data) / (self._nchannels * self._sampwidth) self._soundpos = self._soundpos + len(data) // (self._nchannels * self._sampwidth)
return data return data
# #
...@@ -420,7 +420,7 @@ class Aifc_read: ...@@ -420,7 +420,7 @@ class Aifc_read:
import cl import cl
dummy = self._decomp.SetParam(cl.FRAME_BUFFER_SIZE, dummy = self._decomp.SetParam(cl.FRAME_BUFFER_SIZE,
len(data) * 2) len(data) * 2)
return self._decomp.Decompress(len(data) / self._nchannels, return self._decomp.Decompress(len(data) // self._nchannels,
data) data)
def _ulaw2lin(self, data): def _ulaw2lin(self, data):
...@@ -439,7 +439,7 @@ class Aifc_read: ...@@ -439,7 +439,7 @@ class Aifc_read:
def _read_comm_chunk(self, chunk): def _read_comm_chunk(self, chunk):
self._nchannels = _read_short(chunk) self._nchannels = _read_short(chunk)
self._nframes = _read_long(chunk) self._nframes = _read_long(chunk)
self._sampwidth = (_read_short(chunk) + 7) / 8 self._sampwidth = (_read_short(chunk) + 7) // 8
self._framerate = int(_read_float(chunk)) self._framerate = int(_read_float(chunk))
self._framesize = self._nchannels * self._sampwidth self._framesize = self._nchannels * self._sampwidth
if self._aifc: if self._aifc:
...@@ -468,7 +468,7 @@ class Aifc_read: ...@@ -468,7 +468,7 @@ class Aifc_read:
pass pass
else: else:
self._convert = self._adpcm2lin self._convert = self._adpcm2lin
self._framesize = self._framesize / 4 self._framesize = self._framesize // 4
return return
# for ULAW and ALAW try Compression Library # for ULAW and ALAW try Compression Library
try: try:
...@@ -478,17 +478,17 @@ class Aifc_read: ...@@ -478,17 +478,17 @@ class Aifc_read:
try: try:
import audioop import audioop
self._convert = self._ulaw2lin self._convert = self._ulaw2lin
self._framesize = self._framesize / 2 self._framesize = self._framesize // 2
return return
except ImportError: except ImportError:
pass pass
raise Error, 'cannot read compressed AIFF-C files' raise Error, 'cannot read compressed AIFF-C files'
if self._comptype == 'ULAW': if self._comptype == 'ULAW':
scheme = cl.G711_ULAW scheme = cl.G711_ULAW
self._framesize = self._framesize / 2 self._framesize = self._framesize // 2
elif self._comptype == 'ALAW': elif self._comptype == 'ALAW':
scheme = cl.G711_ALAW scheme = cl.G711_ALAW
self._framesize = self._framesize / 2 self._framesize = self._framesize // 2
else: else:
raise Error, 'unsupported compression type' raise Error, 'unsupported compression type'
self._decomp = cl.OpenDecompressor(scheme) self._decomp = cl.OpenDecompressor(scheme)
...@@ -706,7 +706,7 @@ class Aifc_write: ...@@ -706,7 +706,7 @@ class Aifc_write:
def writeframesraw(self, data): def writeframesraw(self, data):
self._ensure_header_written(len(data)) self._ensure_header_written(len(data))
nframes = len(data) / (self._sampwidth * self._nchannels) nframes = len(data) // (self._sampwidth * self._nchannels)
if self._convert: if self._convert:
data = self._convert(data) data = self._convert(data)
self._file.write(data) self._file.write(data)
...@@ -820,17 +820,17 @@ class Aifc_write: ...@@ -820,17 +820,17 @@ class Aifc_write:
self._init_compression() self._init_compression()
self._file.write('FORM') self._file.write('FORM')
if not self._nframes: if not self._nframes:
self._nframes = initlength / (self._nchannels * self._sampwidth) self._nframes = initlength // (self._nchannels * self._sampwidth)
self._datalength = self._nframes * self._nchannels * self._sampwidth self._datalength = self._nframes * self._nchannels * self._sampwidth
if self._datalength & 1: if self._datalength & 1:
self._datalength = self._datalength + 1 self._datalength = self._datalength + 1
if self._aifc: if self._aifc:
if self._comptype in ('ULAW', 'ALAW'): if self._comptype in ('ULAW', 'ALAW'):
self._datalength = self._datalength / 2 self._datalength = self._datalength // 2
if self._datalength & 1: if self._datalength & 1:
self._datalength = self._datalength + 1 self._datalength = self._datalength + 1
elif self._comptype == 'G722': elif self._comptype == 'G722':
self._datalength = (self._datalength + 3) / 4 self._datalength = (self._datalength + 3) // 4
if self._datalength & 1: if self._datalength & 1:
self._datalength = self._datalength + 1 self._datalength = self._datalength + 1
self._form_length_pos = self._file.tell() self._form_length_pos = self._file.tell()
......
This diff is collapsed.
...@@ -225,7 +225,7 @@ class DBShelf(DictMixin): ...@@ -225,7 +225,7 @@ class DBShelf(DictMixin):
# given nothing is passed to the extension module. That way # given nothing is passed to the extension module. That way
# an exception can be raised if set_get_returns_none is turned # an exception can be raised if set_get_returns_none is turned
# off. # off.
data = apply(self.db.get, args, kw) data = self.db.get(*args, **kw)
try: try:
return cPickle.loads(data) return cPickle.loads(data)
except (EOFError, TypeError, cPickle.UnpicklingError): except (EOFError, TypeError, cPickle.UnpicklingError):
...@@ -294,7 +294,7 @@ class DBShelfCursor: ...@@ -294,7 +294,7 @@ class DBShelfCursor:
def get(self, *args): def get(self, *args):
count = len(args) # a method overloading hack count = len(args) # a method overloading hack
method = getattr(self, 'get_%d' % count) method = getattr(self, 'get_%d' % count)
apply(method, args) method(*args)
def get_1(self, flags): def get_1(self, flags):
rec = self.dbc.get(flags) rec = self.dbc.get(flags)
......
...@@ -398,7 +398,7 @@ class bsdTableDB : ...@@ -398,7 +398,7 @@ class bsdTableDB :
# column names # column names
newcolumnlist = copy.copy(oldcolumnlist) newcolumnlist = copy.copy(oldcolumnlist)
for c in columns: for c in columns:
if not oldcolumnhash.has_key(c): if c not in oldcolumnhash:
newcolumnlist.append(c) newcolumnlist.append(c)
# store the table's new extended column list # store the table's new extended column list
...@@ -472,7 +472,7 @@ class bsdTableDB : ...@@ -472,7 +472,7 @@ class bsdTableDB :
raise TableDBError, "unknown table" raise TableDBError, "unknown table"
# check the validity of each column name # check the validity of each column name
if not self.__tablecolumns.has_key(table): if not table in self.__tablecolumns:
self.__load_column_info(table) self.__load_column_info(table)
for column in rowdict.keys() : for column in rowdict.keys() :
if not self.__tablecolumns[table].count(column): if not self.__tablecolumns[table].count(column):
...@@ -615,7 +615,7 @@ class bsdTableDB : ...@@ -615,7 +615,7 @@ class bsdTableDB :
argument and returning a boolean. argument and returning a boolean.
""" """
try: try:
if not self.__tablecolumns.has_key(table): if table not in self.__tablecolumns:
self.__load_column_info(table) self.__load_column_info(table)
if columns is None: if columns is None:
columns = self.__tablecolumns[table] columns = self.__tablecolumns[table]
...@@ -639,7 +639,7 @@ class bsdTableDB : ...@@ -639,7 +639,7 @@ class bsdTableDB :
argument and returning a boolean. argument and returning a boolean.
""" """
# check the validity of each column name # check the validity of each column name
if not self.__tablecolumns.has_key(table): if not table in self.__tablecolumns:
self.__load_column_info(table) self.__load_column_info(table)
if columns is None: if columns is None:
columns = self.tablecolumns[table] columns = self.tablecolumns[table]
...@@ -709,28 +709,24 @@ class bsdTableDB : ...@@ -709,28 +709,24 @@ class bsdTableDB :
# extract the rowid from the key # extract the rowid from the key
rowid = key[-_rowid_str_len:] rowid = key[-_rowid_str_len:]
if not rejected_rowids.has_key(rowid): if not rowid in rejected_rowids:
# if no condition was specified or the condition # if no condition was specified or the condition
# succeeds, add row to our match list. # succeeds, add row to our match list.
if not condition or condition(data): if not condition or condition(data):
if not matching_rowids.has_key(rowid): if not rowid in matching_rowids:
matching_rowids[rowid] = {} matching_rowids[rowid] = {}
if savethiscolumndata: if savethiscolumndata:
matching_rowids[rowid][column] = data matching_rowids[rowid][column] = data
else: else:
if matching_rowids.has_key(rowid): if rowid in matching_rowids:
del matching_rowids[rowid] del matching_rowids[rowid]
rejected_rowids[rowid] = rowid rejected_rowids[rowid] = rowid
key, data = cur.next() key, data = cur.next()
except db.DBError, dberror: except db.DBError, dberror:
if sys.version_info[0] < 3 : if dberror.args[0] != db.DB_NOTFOUND:
if dberror[0] != db.DB_NOTFOUND: raise
raise
else :
if dberror.args[0] != db.DB_NOTFOUND:
raise
continue continue
cur.close() cur.close()
...@@ -743,7 +739,7 @@ class bsdTableDB : ...@@ -743,7 +739,7 @@ class bsdTableDB :
if len(columns) > 0: if len(columns) > 0:
for rowid, rowdata in matching_rowids.items(): for rowid, rowdata in matching_rowids.items():
for column in columns: for column in columns:
if rowdata.has_key(column): if column in rowdata:
continue continue
try: try:
rowdata[column] = self.db.get( rowdata[column] = self.db.get(
...@@ -815,13 +811,10 @@ class bsdTableDB : ...@@ -815,13 +811,10 @@ class bsdTableDB :
txn.commit() txn.commit()
txn = None txn = None
if self.__tablecolumns.has_key(table): if table in self.__tablecolumns:
del self.__tablecolumns[table] del self.__tablecolumns[table]
except db.DBError, dberror: except db.DBError, dberror:
if txn: if txn:
txn.abort() txn.abort()
if sys.version_info[0] < 3 : raise TableDBError(dberror.args[1])
raise TableDBError, dberror[1]
else :
raise TableDBError, dberror.args[1]
...@@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kwargs): ...@@ -61,7 +61,7 @@ def DeadlockWrap(function, *_args, **_kwargs):
""" """
sleeptime = _deadlock_MinSleepTime sleeptime = _deadlock_MinSleepTime
max_retries = _kwargs.get('max_retries', -1) max_retries = _kwargs.get('max_retries', -1)
if _kwargs.has_key('max_retries'): if 'max_retries' in _kwargs:
del _kwargs['max_retries'] del _kwargs['max_retries']
while True: while True:
try: try:
......
...@@ -707,8 +707,8 @@ class HTTPConnection: ...@@ -707,8 +707,8 @@ class HTTPConnection:
if code != 200: if code != 200:
self.close() self.close()
raise socket.error, "Tunnel connection failed: %d %s" % (code, raise socket.error("Tunnel connection failed: %d %s" % (code,
message.strip()) message.strip()))
while True: while True:
line = response.fp.readline() line = response.fp.readline()
if line == '\r\n': break if line == '\r\n': break
...@@ -758,7 +758,7 @@ class HTTPConnection: ...@@ -758,7 +758,7 @@ class HTTPConnection:
else: else:
self.sock.sendall(str) self.sock.sendall(str)
except socket.error, v: except socket.error, v:
if v[0] == 32: # Broken pipe if v.args[0] == 32: # Broken pipe
self.close() self.close()
raise raise
...@@ -914,7 +914,7 @@ class HTTPConnection: ...@@ -914,7 +914,7 @@ class HTTPConnection:
self._send_request(method, url, body, headers) self._send_request(method, url, body, headers)
except socket.error, v: except socket.error, v:
# trap 'Broken pipe' if we're allowed to automatically reconnect # trap 'Broken pipe' if we're allowed to automatically reconnect
if v[0] != 32 or not self.auto_open: if v.args[0] != 32 or not self.auto_open:
raise raise
# try one more time # try one more time
self._send_request(method, url, body, headers) self._send_request(method, url, body, headers)
......
...@@ -100,7 +100,7 @@ def test_au(h, f): ...@@ -100,7 +100,7 @@ def test_au(h, f):
else: else:
sample_bits = '?' sample_bits = '?'
frame_size = sample_size * nchannels frame_size = sample_size * nchannels
return type, rate, nchannels, data_size/frame_size, sample_bits return type, rate, nchannels, data_size//frame_size, sample_bits
tests.append(test_au) tests.append(test_au)
...@@ -109,7 +109,7 @@ def test_hcom(h, f): ...@@ -109,7 +109,7 @@ def test_hcom(h, f):
if h[65:69] != 'FSSD' or h[128:132] != 'HCOM': if h[65:69] != 'FSSD' or h[128:132] != 'HCOM':
return None return None
divisor = get_long_be(h[128+16:128+20]) divisor = get_long_be(h[128+16:128+20])
return 'hcom', 22050/divisor, 1, -1, 8 return 'hcom', 22050//divisor, 1, -1, 8
tests.append(test_hcom) tests.append(test_hcom)
......
...@@ -290,12 +290,16 @@ class _fileobject(object): ...@@ -290,12 +290,16 @@ class _fileobject(object):
write_offset = 0 write_offset = 0
try: try:
while write_offset < data_size: while write_offset < data_size:
self._sock.sendall(buffer(data, write_offset, buffer_size)) with warnings.catch_warnings():
if sys.py3kwarning:
warnings.filterwarnings("ignore", ".*buffer",
DeprecationWarning)
self._sock.sendall(buffer(data, write_offset, buffer_size))
write_offset += buffer_size write_offset += buffer_size
finally: finally:
if write_offset < data_size: if write_offset < data_size:
remainder = data[write_offset:] remainder = data[write_offset:]
del data # explicit free del view, data # explicit free
self._wbuf.append(remainder) self._wbuf.append(remainder)
self._wbuf_len = len(remainder) self._wbuf_len = len(remainder)
...@@ -343,7 +347,7 @@ class _fileobject(object): ...@@ -343,7 +347,7 @@ class _fileobject(object):
try: try:
data = self._sock.recv(rbufsize) data = self._sock.recv(rbufsize)
except error, e: except error, e:
if e[0] == EINTR: if e.args[0] == EINTR:
continue continue
raise raise
if not data: if not data:
...@@ -372,7 +376,7 @@ class _fileobject(object): ...@@ -372,7 +376,7 @@ class _fileobject(object):
try: try:
data = self._sock.recv(left) data = self._sock.recv(left)
except error, e: except error, e:
if e[0] == EINTR: if e.args[0] == EINTR:
continue continue
raise raise
if not data: if not data:
...@@ -427,7 +431,7 @@ class _fileobject(object): ...@@ -427,7 +431,7 @@ class _fileobject(object):
except error, e: except error, e:
# The try..except to catch EINTR was moved outside the # The try..except to catch EINTR was moved outside the
# recv loop to avoid the per byte overhead. # recv loop to avoid the per byte overhead.
if e[0] == EINTR: if e.args[0] == EINTR:
continue continue
raise raise
break break
...@@ -439,7 +443,7 @@ class _fileobject(object): ...@@ -439,7 +443,7 @@ class _fileobject(object):
try: try:
data = self._sock.recv(self._rbufsize) data = self._sock.recv(self._rbufsize)
except error, e: except error, e:
if e[0] == EINTR: if e.args[0] == EINTR:
continue continue
raise raise
if not data: if not data:
...@@ -468,7 +472,7 @@ class _fileobject(object): ...@@ -468,7 +472,7 @@ class _fileobject(object):
try: try:
data = self._sock.recv(self._rbufsize) data = self._sock.recv(self._rbufsize)
except error, e: except error, e:
if e[0] == EINTR: if e.args[0] == EINTR:
continue continue
raise raise
if not data: if not data:
......
...@@ -502,8 +502,8 @@ def uuid1(node=None, clock_seq=None): ...@@ -502,8 +502,8 @@ def uuid1(node=None, clock_seq=None):
nanoseconds = int(time.time() * 1e9) nanoseconds = int(time.time() * 1e9)
# 0x01b21dd213814000 is the number of 100-ns intervals between the # 0x01b21dd213814000 is the number of 100-ns intervals between the
# UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00. # UUID epoch 1582-10-15 00:00:00 and the Unix epoch 1970-01-01 00:00:00.
timestamp = int(nanoseconds/100) + 0x01b21dd213814000L timestamp = int(nanoseconds//100) + 0x01b21dd213814000L
if timestamp <= _last_timestamp: if _last_timestamp is not None and timestamp <= _last_timestamp:
timestamp = _last_timestamp + 1 timestamp = _last_timestamp + 1
_last_timestamp = timestamp _last_timestamp = timestamp
if clock_seq is None: if clock_seq is None:
......
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