Commits

Armin Rigo  committed ac3ce8b Merge

merge heads

  • Participants
  • Parent commits 483c826, 0b343f4

Comments (0)

Files changed (3)

File lib_pypy/datetime.py

     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))
 
 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)))
         # 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
             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
             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
             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

File pypy/module/select/test/test_select.py

         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 == []
                 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)
                 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:
         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
                 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:
 
             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:
         "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,))

File pypy/module/test_lib_pypy/test_datetime.py

               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'