Opened 12 months ago

Last modified 5 weeks ago

#6746 enhancement new

Improve Jython platform detection in t.python.runtime

Reported by: thijs Owned by: oberstet
Priority: low Milestone:
Component: core Keywords:
Cc: thijs Branch:
Author: Launchpad Bug:

Description

Jython identifies itself as "java" on any platform, eg.

Jython 2.7b1 (default:ac42d59644e9, Feb 9 2013, 15:24:52) 
[OpenJDK 64-Bit Server VM (Sun Microsystems Inc.)] on java1.6.0_27
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.name == 'java' and hasattr(os, '_name')
True
>>> os._name
'posix'
>>> from twisted.python.runtime import platform, platformType
>>> platform.isWindows()
False
>>> platform.isLinux()
False
>>> platform.isKnown()
True
>>> platform.getType()
'java'

The session above comes from an Ubuntu 12.10 system with the latest Jython 2.7b1 release. platform.isLinux() should return True but that function incorrectly check if it's Jython *running on Linux*. It only checks if the platform name starts with 'linux' which is False on Jython (it's always 'java' no matter the platform). Same issue is present in isMacOSX, isWindows etc.

Originally reported in #3413 by oberstet that also includes a possible fix.

Change History (2)

comment:1 Changed 5 weeks ago by hongleij

Win8.1 64bit

F:\PythonDev>jython
Jython 2.7b3 (default:5efdcedc9817, Jun 28 2014, 19:17:21)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.8.0_05
Type "help", "copyright", "credits" or "license" for more information.
>>> import os
>>> os.name == 'java' and hasattr(os, '_name')
True
>>> os._name
'nt'
>>> from twisted.python.runtime import platform, platformType
>>> platform.isWindows()
False
>>> platform.isKnown()
True
>>> platform.getType()
'java'
>>>

comment:2 Changed 5 weeks ago by hongleij

I think change the behavior of platform will cause many other changes. like the file twisted/internet/stdio.py:

from twisted.python.runtime import platform

if platform.isWindows():
    from twisted.internet import _win32stdio
    StandardIO = _win32stdio.StandardIO
    PipeAddress = _win32stdio.Win32PipeAddress

else:
    from twisted.internet._posixstdio import StandardIO, PipeAddress 

__all__ = ['StandardIO', 'PipeAddress']

We need implement these files to make it work under Jython

Note: See TracTickets for help on using tickets.