Author: Armin Rigo <ar...@tunes.org> Branch: Changeset: r69778:ac3ce8b66c72 Date: 2014-03-07 10:19 +0100 http://bitbucket.org/pypy/pypy/changeset/ac3ce8b66c72/
Log: merge heads diff --git a/lib_pypy/datetime.py b/lib_pypy/datetime.py --- a/lib_pypy/datetime.py +++ b/lib_pypy/datetime.py @@ -66,7 +66,7 @@ return _DAYS_IN_MONTH[month] def _days_before_month(year, month): - "year, month -> number of days in year preceeding first day of month." + "year, month -> number of days in year preceding first day of month." assert 1 <= month <= 12, 'month must be in 1..12' return _DAYS_BEFORE_MONTH[month] + (month > 2 and _is_leap(year)) @@ -251,7 +251,7 @@ def _check_utc_offset(name, offset): assert name in ("utcoffset", "dst") if offset is None: - return None + return if not isinstance(offset, timedelta): raise TypeError("tzinfo.%s() must return None " "or timedelta, not '%s'" % (name, type(offset))) @@ -497,8 +497,7 @@ # secondsfrac isn't referenced again if isinstance(microseconds, float): - microseconds += usdouble - microseconds = _round(microseconds) + microseconds = _round(microseconds + usdouble) seconds, microseconds = divmod(microseconds, 1000000) days, seconds = divmod(seconds, 24*3600) d += days @@ -510,8 +509,7 @@ days, seconds = divmod(seconds, 24*3600) d += days s += int(seconds) - microseconds += usdouble - microseconds = _round(microseconds) + microseconds = _round(microseconds + usdouble) assert isinstance(s, int) assert isinstance(microseconds, int) assert abs(s) <= 3 * 24 * 3600 @@ -1140,7 +1138,8 @@ self = object.__new__(cls) self.__setstate(hour, minute or None) return self - hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond) + hour, minute, second, microsecond = _check_time_fields( + hour, minute, second, microsecond) _check_tzinfo_arg(tzinfo) self = object.__new__(cls) self._hour = hour @@ -1444,7 +1443,8 @@ self.__setstate(year, month) return self year, month, day = _check_date_fields(year, month, day) - hour, minute, second, microsecond = _check_time_fields(hour, minute, second, microsecond) + hour, minute, second, microsecond = _check_time_fields( + hour, minute, second, microsecond) _check_tzinfo_arg(tzinfo) self = object.__new__(cls) self._year = year diff --git a/pypy/module/select/test/test_select.py b/pypy/module/select/test/test_select.py --- a/pypy/module/select/test/test_select.py +++ b/pypy/module/select/test/test_select.py @@ -43,7 +43,7 @@ try: iwtd, owtd, ewtd = select.select([readend], [], [], 0) assert iwtd == owtd == ewtd == [] - writeend.send('X') + writeend.send(b'X') iwtd, owtd, ewtd = select.select([readend], [], []) assert iwtd == [readend] assert owtd == ewtd == [] @@ -84,7 +84,7 @@ if owtd == []: break assert owtd == [writeend] - total_out += writeend.send('x' * 512) + total_out += writeend.send(b'x' * 512) total_in = 0 while True: iwtd, owtd, ewtd = select.select([readend], [], [], 0) @@ -94,7 +94,7 @@ assert iwtd == [readend] data = readend.recv(4096) assert len(data) > 0 - assert data == 'x' * len(data) + assert data == b'x' * len(data) total_in += len(data) assert total_in == total_out finally: @@ -110,7 +110,7 @@ readend, writeend = self.getpair() try: try: - total_out = writeend.send('x' * 512) + total_out = writeend.send(b'x' * 512) finally: # win32 sends the 'closed' event immediately, even when # more data is available @@ -126,7 +126,7 @@ data = readend.recv(4096) if len(data) == 0: break - assert data == 'x' * len(data) + assert data == b'x' * len(data) total_in += len(data) # win32: check that closing the socket exits the loop if sys.platform == 'win32' and total_in == total_out: @@ -171,12 +171,12 @@ for i in range(50): n = (i*3) % 10 - writeends[n].send('X') + writeends[n].send(b'X') iwtd, owtd, ewtd = select.select(readends, [], []) assert iwtd == [readends[n]] assert owtd == ewtd == [] data = readends[n].recv(1) - assert data == 'X' + assert data == b'X' finally: for fd in readends + writeends: @@ -251,34 +251,30 @@ "usemodules": ["select", "_socket", "rctime", "thread"], } - def setup_class(cls): - space = cls.space - w_import = space.getattr(space.builtin, space.wrap("__import__")) - w_socketmod = space.call_function(w_import, space.wrap("socket")) - cls.w_sock = cls.space.call_method(w_socketmod, "socket") - cls.w_sock_err = space.getattr(w_socketmod, space.wrap("error")) - - try_ports = [1023] + range(20000, 30000, 437) + def w_make_server(self): + import socket + if hasattr(self, 'sock'): + return self.sock + self.sock = socket.socket() + try_ports = [1023] + list(range(20000, 30000, 437)) for port in try_ports: - print 'binding to port %d:' % (port,), - cls.w_sockaddress = space.wrap(('127.0.0.1', port)) + print('binding to port %d:' % (port,)) + self.sockaddress = ('127.0.0.1', port) try: - space.call_method(cls.w_sock, "bind", cls.w_sockaddress) + self.sock.bind(self.sockaddress) break - except OperationError, e: # should get a "Permission denied" - if not e.match(space, space.getattr(w_socketmod, space.wrap("error"))): - raise - print e.errorstr(space) - except cls.w_sock_err, e: # should get a "Permission denied" - print e + except socket.error as e: # should get a "Permission denied" + print(e) else: - raise e + raise(e) def w_getpair(self): """Helper method which returns a pair of connected sockets.""" import socket import thread + self.make_server() + self.sock.listen(1) s2 = socket.socket() thread.start_new_thread(s2.connect, (self.sockaddress,)) diff --git a/pypy/module/test_lib_pypy/test_datetime.py b/pypy/module/test_lib_pypy/test_datetime.py --- a/pypy/module/test_lib_pypy/test_datetime.py +++ b/pypy/module/test_lib_pypy/test_datetime.py @@ -17,6 +17,14 @@ datetime.tzinfo()]: raises(AttributeError, 'x.abc = 1') +def test_timedelta_init_long(): + td = datetime.timedelta(microseconds=20000000000000000000) + assert td.days == 231481481 + assert td.seconds == 41600 + td = datetime.timedelta(microseconds=20000000000000000000.) + assert td.days == 231481481 + assert td.seconds == 41600 + def test_unpickle(): e = raises(TypeError, datetime.date, '123') assert e.value.args[0] == 'an integer is required' _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit