[issue1602] windows console doesn't print or input Unicode

2012-09-21 Thread Drekin

Drekin added the comment:

Hello, I'm trying to handle Unicode input and output in Windows console and 
found this issue. Will this be solved in 3.3 final? I tried to write a solution 
(file attached) based on solution here – rewriting sys.stdin and sys.stdout so 
it uses ReadConsoleW and WriteConsoleW.

Output works well, but there are few problems with input. First, the Python 
interactive interpreter actually doesn't use sys.stdin but standard C stdin. 
It's implemented over file pointer (PyRun_InteractiveLoopFlags, 
PyRun_InteractiveOneFlags in pythonrun). But still the interpreter uses 
sys.stdin.encoding (assigning sys.stdin something, that doesn't have 
encoding==None freezes the interpreter). Wouldn't it make more sense if it used 
sys.__stdin__.encoding?

However, input() (which uses stdin.readline) works as expected. There's a small 
problem with KeyboardInterrupt. Since signals are processed asynchronously, 
it's raised at random place and it behaves wierdly. time.sleep(0.01) after the 
C call works well, but it's an ugly solution.

When code.interact() is used instead of standard interpreter, it works as 
expected. Is there a way of changing the intepreter loop? Some hook which calls 
code.interact() at the right place? The patch can be applied in site or 
sitecustomized, but calling code.iteract() there obviously doesn't work.

Some other remarks:
- When sys.stdin or sys.stdout doesn't define encoding and errors, input() 
raises TypeError: bad argument type for built-in operation.
- input() raises KeyboardInterrupt on Ctrl-C in Python 3.2 but not in Python 
3.3rc2.

--
nosy: +Drekin
Added file: http://bugs.python.org/file27245/win_unicode_console.py

___
Python tracker 
<http://bugs.python.org/issue1602>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1602] windows console doesn't print or input Unicode

2012-09-22 Thread Drekin

Drekin added the comment:

I have finished a solution working for me. It bypasses standard Python 
interactive interpreter and uses its own repl based on code.interact(). This 
repl is activated by an ugly hack since PYTHONSTARTUP doesn't apply when some 
file is run (python -i somefile.py). Why it works like that? Startup script 
could find out if a file is run or not. If anybody knows how to get rid of 
time.sleep() used for wait for KeyboardInterrupt or how to get rid of 
PromptHack, please let me know. The "patch" can be activated by 
win_unicode_console_2.enable(change_console=True, use_hack=True) in site or 
sitecustomize or usercustomize.

--
Added file: http://bugs.python.org/file27261/win_unicode_console_2.py

___
Python tracker 
<http://bugs.python.org/issue1602>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1602] windows console doesn't print or input Unicode

2013-03-24 Thread Drekin

Drekin added the comment:

Hello. I have made a small upgrade of the workaround.
• win_unicode_console.enable_streams() sets sys.stdin, stdout and stderr to 
custom filelike objects which use Windows functions ReadConcoleW and 
WriteConsoleW to handle unicode data properly. This can be done in 
sitecustomize.py to take effect automatically.

• Since Python interactive console doesn't use sys.stdin for getting input 
(still don't know reason for this), there is an alternative repl based on 
code.interact(). win_unicode_console.IntertactiveConsole.enable() sets it up. 
To set it up automatically, put the enabling code into a startup file and set 
PYTHONSTARTUP environment variable. This works for interactive session (just 
running python with no script).

• Since there is no hook to run InteractiveConsole.enable() when a script is 
run interactively (-i flag), that is after the script and before the 
interactive session, I have written a helper script i.py. It just runs given 
script and then enters an interactive mode using InteractiveConsole. Just put 
i.py into site-packages and run "py -m i script.py arguments" instead of "py -i 
script.py arguments".

It's a shame that in the year 2013 one cannot simply run Python console on 
Windows and enter Unicode characters. I'm not saying it's just Python fault, 
but there is a workaround on Python side.

--
versions: +Python 3.4
Added file: http://bugs.python.org/file29563/i.py

___
Python tracker 
<http://bugs.python.org/issue1602>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue1602] windows console doesn't print or input Unicode

2013-03-24 Thread Drekin

Changes by Drekin :


Added file: http://bugs.python.org/file29564/win_unicode_console_3.py

___
Python tracker 
<http://bugs.python.org/issue1602>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17588] runpy cannot run Unicode path on Windows

2013-03-31 Thread Drekin

New submission from Drekin:

runpy.run_path("\u222b.py") raises UnicodeEncodeError when trying to use mbcs 
codec on Windows. However opening the file using open() is ok. So why is runpy 
trying to encode the name using mbcs encoding when it's not necessary or even 
correct? See http://bpaste.net/show/aOqQLMyYAAFTJ8pQnkli/ .

--
components: Library (Lib), Unicode, Windows
messages: 185634
nosy: Drekin, ezio.melotti
priority: normal
severity: normal
status: open
title: runpy cannot run Unicode path on Windows
type: behavior
versions: Python 3.3

___
Python tracker 
<http://bugs.python.org/issue17588>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17619] input() swallows KeyboardInterrupt in Python 3.3

2013-04-02 Thread Drekin

New submission from Drekin:

At least on Windows, input() doesn't raise KeyboardInterrupt when Ctrl-C is hit 
in Python 3.3 (it does in Python 3.2).

3.3:
>>> x = input() # Ctrl-C hit - no exception raised
>>> x
NameError

3.2:
>>> x = input() # Ctrl-C hit
KeyboardInterrupt

------
messages: 185845
nosy: Drekin
priority: normal
severity: normal
status: open
title: input() swallows KeyboardInterrupt in Python 3.3
type: behavior
versions: Python 3.3

___
Python tracker 
<http://bugs.python.org/issue17619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17620] Python interactive console doesn't use sys.stdin for input

2013-04-02 Thread Drekin

New submission from Drekin:

The Python interactive console actually doesn't use sys.stdin but standard C 
stdin for input. Is there any reason for this? Why it then uses its encoding 
attribute? (Assigning sys.stdin something, that doesn't have encoding attribute 
freezes the interpreter.) If anything, wouldn't it make more sense if it used 
sys.__stdin__.encoding instead of sys.stdin? sys.stdin is intended to be set by 
user (it affects input() and code.inpterrupt() which tries to minic standard 
interactive console).

--
messages: 185848
nosy: Drekin
priority: normal
severity: normal
status: open
title: Python interactive console doesn't use sys.stdin for input
type: behavior
versions: Python 3.3, Python 3.4

___
Python tracker 
<http://bugs.python.org/issue17620>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17619] MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3

2013-04-03 Thread Drekin

Drekin added the comment:

I have Windows Vista Business SP2, 64-bit, (6.0.6002). If I start Python any 
way (from console, from shortcut, via py.exe or not) the same behavior occurs.

--

___
Python tracker 
<http://bugs.python.org/issue17619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17619] MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3

2013-04-03 Thread Drekin

Drekin added the comment:

However it raises the exception correctly in IDLE.

The same behavior occured on Windows 7 Home Premium SP1, 64-bit, (6.1.7601).

--

___
Python tracker 
<http://bugs.python.org/issue17619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17588] runpy cannot run Unicode path on Windows

2013-04-03 Thread Drekin

Drekin added the comment:

I have no specific use case. I just thought that runpy.run_path should work 
similarily as if the file was run directly (which works).

File ∫.py can be created, displayed and run by Python with no problem in 
Windows.

--

___
Python tracker 
<http://bugs.python.org/issue17588>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17619] MS WINDOWS: input() swallows KeyboardInterrupt in Python 3.3

2013-04-03 Thread Drekin

Drekin added the comment:

There is related weird behavior:

>>> try:
... input()
... except KeyboardInterrupt:
... print("exception occured")
...
# Ctrl-C hit
Traceback (most recent call last):
  File "", line 2, in 
KeyboardInterrupt

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "", line 2, in 
KeyboardInterrupt
>>>

Seems like handling of Ctrl-C is kind of “out of sync”.

--

___
Python tracker 
<http://bugs.python.org/issue17619>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17620] Python interactive console doesn't use sys.stdin for input

2013-04-06 Thread Drekin

Drekin added the comment:

Sorry for typos.
• interactive console doesn't use sys.stdin for input, why?
• it uses sys.stdin.encoding, shouldn't it rather use sys.__stdin__.encoding if 
anything?
• input() and hence code.interact() uses sys.stdin

--

___
Python tracker 
<http://bugs.python.org/issue17620>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17620] Python interactive console doesn't use sys.stdin for input

2013-04-11 Thread Drekin

Drekin added the comment:

I encountered it when I changed sys.stdin at runtime (I thought it was a 
supported feature) to affect the interactive console, see 
http://bugs.python.org/issue1602 .

--
versions:  -Python 2.7

___
Python tracker 
<http://bugs.python.org/issue17620>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue17730] code.interact() doesn't support no banner

2013-04-14 Thread Drekin

New submission from Drekin:

Currently, there is no way to run code.interact without a banner – empty string 
still means to print an empty line. If I want that behaviour, I must subclass 
code.InteractiveConsole and reimplement whole .interact method including the 
repl logic just not to print a banner. Maybe there should be .print_banner 
method for this.

--
components: Library (Lib)
messages: 186914
nosy: Drekin
priority: normal
severity: normal
status: open
title: code.interact() doesn't support no banner
type: enhancement
versions: Python 3.3, Python 3.4

___
Python tracker 
<http://bugs.python.org/issue17730>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18331] runpy.run_path gives functions with corrupted .__globals__

2013-06-30 Thread Drekin

New submission from Drekin:

Let's have a simple script test.py:
def f():
return x
x = 2
print(f())

Now if we try to run it via runpy.run_path, we get the following:
>>> import runpy
>>> g = runpy.run_path("test.py")
2
>>> g["f"]() is None
True
>>> g["x"] is 2
True
>>> g["f"].__globals__["x"] is None
True

Is the behaviour of f.__globals__ after return from run_path intended and why?

--
components: Library (Lib)
messages: 192072
nosy: Drekin
priority: normal
severity: normal
status: open
title: runpy.run_path gives functions with corrupted .__globals__
type: behavior
versions: Python 3.3

___
Python tracker 
<http://bugs.python.org/issue18331>
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com