Message5864
Yes, Philip, you're right: we could steal that information via reflection. Here using Jython:
---
from java.lang import System
def get_encoding(console):
"""returns encoding of this console
<!> untested if console is null (i.e. when not attached to a tty)
<!> might fail if a security manager is set without "suppressAccessChecks"
"""
encoding_method = console.getClass().getDeclaredMethod("encoding", None)
encoding_method.setAccessible(True)
return encoding_method.invoke(console, None)
def get_charset(console):
"""returns charset of this console
<!> untested if console is null (i.e. when not attached to a tty)
<!> might fail if a security manager is set without "suppressAccessChecks"
"""
charset_field = console.getClass().getDeclaredField("cs")
charset_field.setAccessible(True)
return charset_field.get(console)
if __name__ == "__main__":
print "java.io.Console's encoding:", get_encoding(System.console())
# cp437 (string)
print "java.io.Console's charset:", get_charset(System.console())
# IBM437 (java.nio.charset.Charset object)
---
Regards,
Regis |
|
Date |
User |
Action |
Args |
2010-06-30 16:00:16 | rdesgroppes | set | messageid: <1277913616.19.0.606439342823.issue1568@psf.upfronthosting.co.za> |
2010-06-30 16:00:16 | rdesgroppes | set | recipients:
+ rdesgroppes, fwierzbicki, pekka.klarck, pjenvey, yanne |
2010-06-30 16:00:16 | rdesgroppes | link | issue1568 messages |
2010-06-30 16:00:14 | rdesgroppes | create | |
|