You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

169 lines
4.9 KiB

Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62194 | jeffrey.yasskin | 2008-04-07 01:04:28 +0200 (Mon, 07 Apr 2008) | 7 lines Add enough debugging information to diagnose failures where the HandlerBException is ignored, and fix one such problem, where it was thrown during the __del__ method of the previous Popen object. We may want to find a better way of printing verbose information so it's not spammy when the test passes. ........ r62197 | mark.hammond | 2008-04-07 03:53:39 +0200 (Mon, 07 Apr 2008) | 2 lines Issue #2513: enable 64bit cross compilation on windows. ........ r62198 | mark.hammond | 2008-04-07 03:59:40 +0200 (Mon, 07 Apr 2008) | 2 lines correct heading underline for new "Cross-compiling on Windows" section ........ r62204 | gregory.p.smith | 2008-04-07 08:33:21 +0200 (Mon, 07 Apr 2008) | 4 lines Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly within the standard library. These modules use PyFile_AsFile and later release the GIL while operating on the previously returned FILE*. ........ r62205 | mark.summerfield | 2008-04-07 09:39:23 +0200 (Mon, 07 Apr 2008) | 4 lines changed "2500 components" to "several thousand" since the number keeps growning:-) ........ r62214 | georg.brandl | 2008-04-07 20:51:59 +0200 (Mon, 07 Apr 2008) | 2 lines #2525: update timezone info examples in the docs. ........ r62219 | andrew.kuchling | 2008-04-08 01:57:07 +0200 (Tue, 08 Apr 2008) | 1 line Write PEP 3127 section; add items ........ r62220 | andrew.kuchling | 2008-04-08 01:57:21 +0200 (Tue, 08 Apr 2008) | 1 line Typo fix ........ r62221 | andrew.kuchling | 2008-04-08 03:33:10 +0200 (Tue, 08 Apr 2008) | 1 line Typographical fix: 32bit -> 32-bit, 64bit -> 64-bit ........ r62227 | andrew.kuchling | 2008-04-08 23:22:53 +0200 (Tue, 08 Apr 2008) | 1 line Add items ........ r62229 | amaury.forgeotdarc | 2008-04-08 23:27:42 +0200 (Tue, 08 Apr 2008) | 7 lines Issue2564: Prevent a hang in "import test.autotest", which runs the entire test suite as a side-effect of importing the module. - in test_capi, a thread tried to import other modules - re.compile() imported sre_parse again on every call. ........ r62230 | amaury.forgeotdarc | 2008-04-08 23:51:57 +0200 (Tue, 08 Apr 2008) | 2 lines Prevent an error when inspect.isabstract() is called with something else than a new-style class. ........ r62231 | amaury.forgeotdarc | 2008-04-09 00:07:05 +0200 (Wed, 09 Apr 2008) | 8 lines Issue 2408: remove the _types module It was only used as a helper in types.py to access types (GetSetDescriptorType and MemberDescriptorType), when they can easily be obtained with python code. These expressions even work with Jython. I don't know what the future of the types module is; (cf. discussion in http://bugs.python.org/issue1605 ) at least this change makes it simpler. ........ r62233 | amaury.forgeotdarc | 2008-04-09 01:10:07 +0200 (Wed, 09 Apr 2008) | 2 lines Add a NEWS entry for previous checkin ........ r62234 | trent.nelson | 2008-04-09 01:47:30 +0200 (Wed, 09 Apr 2008) | 37 lines - Issue #2550: The approach used by client/server code for obtaining ports to listen on in network-oriented tests has been refined in an effort to facilitate running multiple instances of the entire regression test suite in parallel without issue. test_support.bind_port() has been fixed such that it will always return a unique port -- which wasn't always the case with the previous implementation, especially if socket options had been set that affected address reuse (i.e. SO_REUSEADDR, SO_REUSEPORT). The new implementation of bind_port() will actually raise an exception if it is passed an AF_INET/SOCK_STREAM socket with either the SO_REUSEADDR or SO_REUSEPORT socket option set. Furthermore, if available, bind_port() will set the SO_EXCLUSIVEADDRUSE option on the socket it's been passed. This currently only applies to Windows. This option prevents any other sockets from binding to the host/port we've bound to, thus removing the possibility of the 'non-deterministic' behaviour, as Microsoft puts it, that occurs when a second SOCK_STREAM socket binds and accepts to a host/port that's already been bound by another socket. The optional preferred port parameter to bind_port() has been removed. Under no circumstances should tests be hard coding ports! test_support.find_unused_port() has also been introduced, which will pass a temporary socket object to bind_port() in order to obtain an unused port. The temporary socket object is then closed and deleted, and the port is returned. This method should only be used for obtaining an unused port in order to pass to an external program (i.e. the -accept [port] argument to openssl's s_server mode) or as a parameter to a server-oriented class that doesn't give you direct access to the underlying socket used. Finally, test_support.HOST has been introduced, which should be used for the host argument of any relevant socket calls (i.e. bind and connect). The following tests were updated to following the new conventions: test_socket, test_smtplib, test_asyncore, test_ssl, test_httplib, test_poplib, test_ftplib, test_telnetlib, test_socketserver, test_asynchat and test_socket_ssl. It is now possible for multiple instances of the regression test suite to run in parallel without issue. ........ r62235 | gregory.p.smith | 2008-04-09 02:25:17 +0200 (Wed, 09 Apr 2008) | 3 lines Fix zlib crash from zlib.decompressobj().flush(val) when val was not positive. It tried to allocate negative or zero memory. That fails. ........ r62237 | trent.nelson | 2008-04-09 02:34:53 +0200 (Wed, 09 Apr 2008) | 1 line Fix typo with regards to self.PORT shadowing class variables with the same name. ........ r62238 | andrew.kuchling | 2008-04-09 03:08:32 +0200 (Wed, 09 Apr 2008) | 1 line Add items ........ r62239 | jerry.seutter | 2008-04-09 07:07:58 +0200 (Wed, 09 Apr 2008) | 1 line Changed test so it no longer runs as a side effect of importing. ........
19 years ago
Merged revisions 62194,62197-62198,62204-62205,62214,62219-62221,62227,62229-62231,62233-62235,62237-62239 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r62194 | jeffrey.yasskin | 2008-04-07 01:04:28 +0200 (Mon, 07 Apr 2008) | 7 lines Add enough debugging information to diagnose failures where the HandlerBException is ignored, and fix one such problem, where it was thrown during the __del__ method of the previous Popen object. We may want to find a better way of printing verbose information so it's not spammy when the test passes. ........ r62197 | mark.hammond | 2008-04-07 03:53:39 +0200 (Mon, 07 Apr 2008) | 2 lines Issue #2513: enable 64bit cross compilation on windows. ........ r62198 | mark.hammond | 2008-04-07 03:59:40 +0200 (Mon, 07 Apr 2008) | 2 lines correct heading underline for new "Cross-compiling on Windows" section ........ r62204 | gregory.p.smith | 2008-04-07 08:33:21 +0200 (Mon, 07 Apr 2008) | 4 lines Use the new PyFile_IncUseCount & PyFile_DecUseCount calls appropriatly within the standard library. These modules use PyFile_AsFile and later release the GIL while operating on the previously returned FILE*. ........ r62205 | mark.summerfield | 2008-04-07 09:39:23 +0200 (Mon, 07 Apr 2008) | 4 lines changed "2500 components" to "several thousand" since the number keeps growning:-) ........ r62214 | georg.brandl | 2008-04-07 20:51:59 +0200 (Mon, 07 Apr 2008) | 2 lines #2525: update timezone info examples in the docs. ........ r62219 | andrew.kuchling | 2008-04-08 01:57:07 +0200 (Tue, 08 Apr 2008) | 1 line Write PEP 3127 section; add items ........ r62220 | andrew.kuchling | 2008-04-08 01:57:21 +0200 (Tue, 08 Apr 2008) | 1 line Typo fix ........ r62221 | andrew.kuchling | 2008-04-08 03:33:10 +0200 (Tue, 08 Apr 2008) | 1 line Typographical fix: 32bit -> 32-bit, 64bit -> 64-bit ........ r62227 | andrew.kuchling | 2008-04-08 23:22:53 +0200 (Tue, 08 Apr 2008) | 1 line Add items ........ r62229 | amaury.forgeotdarc | 2008-04-08 23:27:42 +0200 (Tue, 08 Apr 2008) | 7 lines Issue2564: Prevent a hang in "import test.autotest", which runs the entire test suite as a side-effect of importing the module. - in test_capi, a thread tried to import other modules - re.compile() imported sre_parse again on every call. ........ r62230 | amaury.forgeotdarc | 2008-04-08 23:51:57 +0200 (Tue, 08 Apr 2008) | 2 lines Prevent an error when inspect.isabstract() is called with something else than a new-style class. ........ r62231 | amaury.forgeotdarc | 2008-04-09 00:07:05 +0200 (Wed, 09 Apr 2008) | 8 lines Issue 2408: remove the _types module It was only used as a helper in types.py to access types (GetSetDescriptorType and MemberDescriptorType), when they can easily be obtained with python code. These expressions even work with Jython. I don't know what the future of the types module is; (cf. discussion in http://bugs.python.org/issue1605 ) at least this change makes it simpler. ........ r62233 | amaury.forgeotdarc | 2008-04-09 01:10:07 +0200 (Wed, 09 Apr 2008) | 2 lines Add a NEWS entry for previous checkin ........ r62234 | trent.nelson | 2008-04-09 01:47:30 +0200 (Wed, 09 Apr 2008) | 37 lines - Issue #2550: The approach used by client/server code for obtaining ports to listen on in network-oriented tests has been refined in an effort to facilitate running multiple instances of the entire regression test suite in parallel without issue. test_support.bind_port() has been fixed such that it will always return a unique port -- which wasn't always the case with the previous implementation, especially if socket options had been set that affected address reuse (i.e. SO_REUSEADDR, SO_REUSEPORT). The new implementation of bind_port() will actually raise an exception if it is passed an AF_INET/SOCK_STREAM socket with either the SO_REUSEADDR or SO_REUSEPORT socket option set. Furthermore, if available, bind_port() will set the SO_EXCLUSIVEADDRUSE option on the socket it's been passed. This currently only applies to Windows. This option prevents any other sockets from binding to the host/port we've bound to, thus removing the possibility of the 'non-deterministic' behaviour, as Microsoft puts it, that occurs when a second SOCK_STREAM socket binds and accepts to a host/port that's already been bound by another socket. The optional preferred port parameter to bind_port() has been removed. Under no circumstances should tests be hard coding ports! test_support.find_unused_port() has also been introduced, which will pass a temporary socket object to bind_port() in order to obtain an unused port. The temporary socket object is then closed and deleted, and the port is returned. This method should only be used for obtaining an unused port in order to pass to an external program (i.e. the -accept [port] argument to openssl's s_server mode) or as a parameter to a server-oriented class that doesn't give you direct access to the underlying socket used. Finally, test_support.HOST has been introduced, which should be used for the host argument of any relevant socket calls (i.e. bind and connect). The following tests were updated to following the new conventions: test_socket, test_smtplib, test_asyncore, test_ssl, test_httplib, test_poplib, test_ftplib, test_telnetlib, test_socketserver, test_asynchat and test_socket_ssl. It is now possible for multiple instances of the regression test suite to run in parallel without issue. ........ r62235 | gregory.p.smith | 2008-04-09 02:25:17 +0200 (Wed, 09 Apr 2008) | 3 lines Fix zlib crash from zlib.decompressobj().flush(val) when val was not positive. It tried to allocate negative or zero memory. That fails. ........ r62237 | trent.nelson | 2008-04-09 02:34:53 +0200 (Wed, 09 Apr 2008) | 1 line Fix typo with regards to self.PORT shadowing class variables with the same name. ........ r62238 | andrew.kuchling | 2008-04-09 03:08:32 +0200 (Wed, 09 Apr 2008) | 1 line Add items ........ r62239 | jerry.seutter | 2008-04-09 07:07:58 +0200 (Wed, 09 Apr 2008) | 1 line Changed test so it no longer runs as a side effect of importing. ........
19 years ago
  1. from datetime import tzinfo, timedelta, datetime
  2. ZERO = timedelta(0)
  3. HOUR = timedelta(hours=1)
  4. # A UTC class.
  5. class UTC(tzinfo):
  6. """UTC"""
  7. def utcoffset(self, dt):
  8. return ZERO
  9. def tzname(self, dt):
  10. return "UTC"
  11. def dst(self, dt):
  12. return ZERO
  13. utc = UTC()
  14. # A class building tzinfo objects for fixed-offset time zones.
  15. # Note that FixedOffset(0, "UTC") is a different way to build a
  16. # UTC tzinfo object.
  17. class FixedOffset(tzinfo):
  18. """Fixed offset in minutes east from UTC."""
  19. def __init__(self, offset, name):
  20. self.__offset = timedelta(minutes=offset)
  21. self.__name = name
  22. def utcoffset(self, dt):
  23. return self.__offset
  24. def tzname(self, dt):
  25. return self.__name
  26. def dst(self, dt):
  27. return ZERO
  28. # A class capturing the platform's idea of local time.
  29. import time as _time
  30. STDOFFSET = timedelta(seconds = -_time.timezone)
  31. if _time.daylight:
  32. DSTOFFSET = timedelta(seconds = -_time.altzone)
  33. else:
  34. DSTOFFSET = STDOFFSET
  35. DSTDIFF = DSTOFFSET - STDOFFSET
  36. class LocalTimezone(tzinfo):
  37. def utcoffset(self, dt):
  38. if self._isdst(dt):
  39. return DSTOFFSET
  40. else:
  41. return STDOFFSET
  42. def dst(self, dt):
  43. if self._isdst(dt):
  44. return DSTDIFF
  45. else:
  46. return ZERO
  47. def tzname(self, dt):
  48. return _time.tzname[self._isdst(dt)]
  49. def _isdst(self, dt):
  50. tt = (dt.year, dt.month, dt.day,
  51. dt.hour, dt.minute, dt.second,
  52. dt.weekday(), 0, 0)
  53. stamp = _time.mktime(tt)
  54. tt = _time.localtime(stamp)
  55. return tt.tm_isdst > 0
  56. Local = LocalTimezone()
  57. # A complete implementation of current DST rules for major US time zones.
  58. def first_sunday_on_or_after(dt):
  59. days_to_go = 6 - dt.weekday()
  60. if days_to_go:
  61. dt += timedelta(days_to_go)
  62. return dt
  63. # US DST Rules
  64. #
  65. # This is a simplified (i.e., wrong for a few cases) set of rules for US
  66. # DST start and end times. For a complete and up-to-date set of DST rules
  67. # and timezone definitions, visit the Olson Database (or try pytz):
  68. # http://www.twinsun.com/tz/tz-link.htm
  69. # http://sourceforge.net/projects/pytz/ (might not be up-to-date)
  70. #
  71. # In the US, since 2007, DST starts at 2am (standard time) on the second
  72. # Sunday in March, which is the first Sunday on or after Mar 8.
  73. DSTSTART_2007 = datetime(1, 3, 8, 2)
  74. # and ends at 2am (DST time; 1am standard time) on the first Sunday of Nov.
  75. DSTEND_2007 = datetime(1, 11, 1, 1)
  76. # From 1987 to 2006, DST used to start at 2am (standard time) on the first
  77. # Sunday in April and to end at 2am (DST time; 1am standard time) on the last
  78. # Sunday of October, which is the first Sunday on or after Oct 25.
  79. DSTSTART_1987_2006 = datetime(1, 4, 1, 2)
  80. DSTEND_1987_2006 = datetime(1, 10, 25, 1)
  81. # From 1967 to 1986, DST used to start at 2am (standard time) on the last
  82. # Sunday in April (the one on or after April 24) and to end at 2am (DST time;
  83. # 1am standard time) on the last Sunday of October, which is the first Sunday
  84. # on or after Oct 25.
  85. DSTSTART_1967_1986 = datetime(1, 4, 24, 2)
  86. DSTEND_1967_1986 = DSTEND_1987_2006
  87. class USTimeZone(tzinfo):
  88. def __init__(self, hours, reprname, stdname, dstname):
  89. self.stdoffset = timedelta(hours=hours)
  90. self.reprname = reprname
  91. self.stdname = stdname
  92. self.dstname = dstname
  93. def __repr__(self):
  94. return self.reprname
  95. def tzname(self, dt):
  96. if self.dst(dt):
  97. return self.dstname
  98. else:
  99. return self.stdname
  100. def utcoffset(self, dt):
  101. return self.stdoffset + self.dst(dt)
  102. def dst(self, dt):
  103. if dt is None or dt.tzinfo is None:
  104. # An exception may be sensible here, in one or both cases.
  105. # It depends on how you want to treat them. The default
  106. # fromutc() implementation (called by the default astimezone()
  107. # implementation) passes a datetime with dt.tzinfo is self.
  108. return ZERO
  109. assert dt.tzinfo is self
  110. # Find start and end times for US DST. For years before 1967, return
  111. # ZERO for no DST.
  112. if 2006 < dt.year:
  113. dststart, dstend = DSTSTART_2007, DSTEND_2007
  114. elif 1986 < dt.year < 2007:
  115. dststart, dstend = DSTSTART_1987_2006, DSTEND_1987_2006
  116. elif 1966 < dt.year < 1987:
  117. dststart, dstend = DSTSTART_1967_1986, DSTEND_1967_1986
  118. else:
  119. return ZERO
  120. start = first_sunday_on_or_after(dststart.replace(year=dt.year))
  121. end = first_sunday_on_or_after(dstend.replace(year=dt.year))
  122. # Can't compare naive to aware objects, so strip the timezone from
  123. # dt first.
  124. if start <= dt.replace(tzinfo=None) < end:
  125. return HOUR
  126. else:
  127. return ZERO
  128. Eastern = USTimeZone(-5, "Eastern", "EST", "EDT")
  129. Central = USTimeZone(-6, "Central", "CST", "CDT")
  130. Mountain = USTimeZone(-7, "Mountain", "MST", "MDT")
  131. Pacific = USTimeZone(-8, "Pacific", "PST", "PDT")