[Python-Dev] Re: [Patches] PC\config.[hc] changes for Win64

Trent Mick trentm@activestate.com
Mon, 8 May 2000 15:49:58 -0700


On Tue, May 09, 2000 at 08:15:17AM +1000, Mark Hammond wrote:
> [Trent]
> > What if someone needs to do something in Python code for either Win32 or
> > Win64 but not both? Or should this never be necessary (not
> > likely). I would
> > like Mark H's opinion on this stuff.
> 
> OK :-)
> 
> I have always thought that it _would_ move to "win64", and the official way
> of checking for "Windows" will be sys.platform[:3]=="win".
> 
> In fact, Ive noticed Guido use this idiom (both stand-alone, and as :if
> sys.platform[:3] in ["win", "mac"])
> 
> It will no doubt cause a bit of pain, but IMO it is cleaner...
> 
Mark's a smart guy. I think using "win64" should be okay. When the "pain"
comes, the user should not be totally blind to it. She should be inclined to
blame failures on her new Windows64 OS anyway. :) I have included a patch to
correct those occurences in the core python code. There weren't that many.

Is there some bullet list somewhere that the following comment could get
appended to: """The prefered method of checking for a windows platform in
python code is:
  if sys.platform[:3] == "win"
This includes the "win32" and "win64"
"""
Acutally it also includes "win16". Is that a problem?


Discussion:

Correct checks in python code for the windows platform to include "win64" as
well. Thus the common idiom:
  if sys.platform == "win32":
becomes:
  if sys.platform[:3] == "win"


Legal:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under
copyright, patent or other rights or interests ("claims").  To
the extent that I have any such claims, I hereby grant to CNRI a
nonexclusive, irrevocable, royalty-free, worldwide license to
reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part
of the Python software and its related documentation, or any
derivative versions thereof, at no cost to CNRI or its licensed
users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide
whether or not to incorporate this contribution in the Python
software and its related documentation.  I further grant CNRI
permission to use my name and other identifying information
provided to CNRI by me for use in connection with the Python
software and its related documentation.


Patch:


diff -c3  /home/trentm/main/contrib/python/dist/src/Lib/dos-8x3/telnetli.py ./Lib/dos-8x3/telnetli.py
*** /home/trentm/main/contrib/python/dist/src/Lib/dos-8x3/telnetli.py	Mon May  8 11:49:03 2000
--- ./Lib/dos-8x3/telnetli.py	Mon May  8 15:30:29 2000
***************
*** 377,383 ****
  
      def interact(self):
          """Interaction function, emulates a very dumb telnet client."""
!         if sys.platform == "win32":
              self.mt_interact()
              return
          while 1:
--- 377,383 ----
  
      def interact(self):
          """Interaction function, emulates a very dumb telnet client."""
!         if sys.platform[:3] == "win":
              self.mt_interact()
              return
          while 1:
diff -c3  /home/trentm/main/contrib/python/dist/src/Lib/lib-tk/Tkinter.py ./Lib/lib-tk/Tkinter.py
*** /home/trentm/main/contrib/python/dist/src/Lib/lib-tk/Tkinter.py	Fri May  5 10:53:25 2000
--- ./Lib/lib-tk/Tkinter.py	Mon May  8 15:31:31 2000
***************
*** 3,9 ****
  __version__ = "$Revision: 1.137 $"
  
  import sys
! if sys.platform == "win32":
  	import FixTk # Attempt to configure Tcl/Tk without requiring PATH
  import _tkinter # If this fails your Python may not be configured for Tk
  tkinter = _tkinter # b/w compat for export
--- 3,9 ----
  __version__ = "$Revision: 1.137 $"
  
  import sys
! if sys.platform[:3] == "win":
  	import FixTk # Attempt to configure Tcl/Tk without requiring PATH
  import _tkinter # If this fails your Python may not be configured for Tk
  tkinter = _tkinter # b/w compat for export
diff -c3  /home/trentm/main/contrib/python/dist/src/Lib/telnetlib.py ./Lib/telnetlib.py
*** /home/trentm/main/contrib/python/dist/src/Lib/telnetlib.py	Fri May  5 10:53:28 2000
--- ./Lib/telnetlib.py	Mon May  8 15:31:58 2000
***************
*** 377,383 ****
  
      def interact(self):
          """Interaction function, emulates a very dumb telnet client."""
!         if sys.platform == "win32":
              self.mt_interact()
              return
          while 1:
--- 377,383 ----
  
      def interact(self):
          """Interaction function, emulates a very dumb telnet client."""
!         if sys.platform[:3] == "win":
              self.mt_interact()
              return
          while 1:
diff -c3  /home/trentm/main/contrib/python/dist/src/Tools/freeze/freeze.py ./Tools/freeze/freeze.py
*** /home/trentm/main/contrib/python/dist/src/Tools/freeze/freeze.py	Mon May  8 11:49:05 2000
--- ./Tools/freeze/freeze.py	Mon May  8 15:33:03 2000
***************
*** 54,60 ****
                'console' (default), 'windows', 'service' or 'com_dll'
                
  -w:           Toggle Windows (NT or 95) behavior.
!               (For debugging only -- on a win32 platform, win32 behaviour
                is automatic.)
  
  Arguments:
--- 54,60 ----
                'console' (default), 'windows', 'service' or 'com_dll'
                
  -w:           Toggle Windows (NT or 95) behavior.
!               (For debugging only -- on a win32/64 platform, win32/64 behaviour
                is automatic.)
  
  Arguments:
diff -c3  /home/trentm/main/contrib/python/dist/src/Tools/freeze/modulefinder.py ./Tools/freeze/modulefinder.py
*** /home/trentm/main/contrib/python/dist/src/Tools/freeze/modulefinder.py	Fri May  5 10:53:39 2000
--- ./Tools/freeze/modulefinder.py	Mon May  8 15:34:29 2000
***************
*** 8,14 ****
  import string
  import sys
  
! if sys.platform=="win32":
      # On Windows, we can locate modules in the registry with
      # the help of the win32api package.
      try:
--- 8,14 ----
  import string
  import sys
  
! if sys.platform[:3] == "win":
      # On Windows, we can locate modules in the registry with
      # the help of the win32api package.
      try:
***************
*** 332,338 ****
                  return (None, None, ("", "", imp.C_BUILTIN))
  
              # Emulate the Registered Module support on Windows.
!             if sys.platform=="win32" and win32api is not None:
                  HKEY_LOCAL_MACHINE = 0x80000002
                  try:
                      pathname = win32api.RegQueryValue(HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, name))
--- 332,338 ----
                  return (None, None, ("", "", imp.C_BUILTIN))
  
              # Emulate the Registered Module support on Windows.
!             if sys.platform[:3] == "win" and win32api is not None:
                  HKEY_LOCAL_MACHINE = 0x80000002
                  try:
                      pathname = win32api.RegQueryValue(HKEY_LOCAL_MACHINE, "Software\\Python\\PythonCore\\%s\\Modules\\%s" % (sys.winver, name))
diff -c3  /home/trentm/main/contrib/python/dist/src/Tools/idle/Bindings.py ./Tools/idle/Bindings.py
*** /home/trentm/main/contrib/python/dist/src/Tools/idle/Bindings.py	Fri May  5 10:53:39 2000
--- ./Tools/idle/Bindings.py	Mon May  8 15:34:51 2000
***************
*** 49,55 ****
    ]),
  ]
  
! if sys.platform == 'win32':
      default_keydefs = windows_keydefs
  else:
      default_keydefs = unix_keydefs
--- 49,55 ----
    ]),
  ]
  
! if sys.platform[:3] == 'win':
      default_keydefs = windows_keydefs
  else:
      default_keydefs = unix_keydefs
diff -c3  /home/trentm/main/contrib/python/dist/src/Tools/idle/EditorWindow.py ./Tools/idle/EditorWindow.py
*** /home/trentm/main/contrib/python/dist/src/Tools/idle/EditorWindow.py	Fri May  5 10:53:39 2000
--- ./Tools/idle/EditorWindow.py	Mon May  8 15:35:30 2000
***************
*** 538,544 ****
          ins = cls(self)
          self.extensions[name] = ins
          kdnames = ["keydefs"]
!         if sys.platform == 'win32':
              kdnames.append("windows_keydefs")
          elif sys.platform == 'mac':
              kdnames.append("mac_keydefs")
--- 538,544 ----
          ins = cls(self)
          self.extensions[name] = ins
          kdnames = ["keydefs"]
!         if sys.platform[:3] == 'win':
              kdnames.append("windows_keydefs")
          elif sys.platform == 'mac':
              kdnames.append("mac_keydefs")
diff -c3  /home/trentm/main/contrib/python/dist/src/Tools/idle/ZoomHeight.py ./Tools/idle/ZoomHeight.py
*** /home/trentm/main/contrib/python/dist/src/Tools/idle/ZoomHeight.py	Fri May  5 10:53:40 2000
--- ./Tools/idle/ZoomHeight.py	Mon May  8 15:35:58 2000
***************
*** 33,39 ****
          return
      width, height, x, y = map(int, m.groups())
      newheight = top.winfo_screenheight()
!     if sys.platform == 'win32':
          newy = 0
          newheight = newheight - 72
      else:
--- 33,39 ----
          return
      width, height, x, y = map(int, m.groups())
      newheight = top.winfo_screenheight()
!     if sys.platform[:3] == 'win':
          newy = 0
          newheight = newheight - 72
      else:


-- 
Trent Mick
trentm@activestate.com