[issue35870] readline() specification is unclear

2019-01-31 Thread Victor Porton


New submission from Victor Porton :

In https://docs.python.org/3/library/io.html it is forgotten to say whether 
'\n' is appened to the return value of readline().

It is also unclear what happens if the last line not terminated by '\n' is read.

It is also unclear what is returned if a text file (say with '\r\n' 
terminators) is read. Is it appended to the return value '\n', '\r\n' or 
nothing?

--
assignee: docs@python
components: Documentation
messages: 334634
nosy: docs@python, porton
priority: normal
severity: normal
status: open
title: readline() specification is unclear
versions: Python 3.8

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



[issue35530] Counter-intuitive logging API

2018-12-18 Thread Victor Porton


New submission from Victor Porton :

The following script:

#/usr/bin/env python3
import logging
logger = logging.getLogger(name='main')
logger.setLevel(logging.INFO)
logger.error('XXX')
logging.error('ZZZ')
logger.error('XXX')

outputs

XXX
ERROR:root:ZZZ
ERROR:main:XXX

That is counter-intuitive: two logger.error('XXX') operators should output the 
same string, not two different strings "XXX" and "ERROR:main:XXX".

Please discuss how to make Python behave as a user could expect.

--
components: Library (Lib)
messages: 332103
nosy: porton
priority: normal
severity: normal
status: open
title: Counter-intuitive logging API
type: behavior
versions: Python 3.7

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



[issue35480] argparse: add a full fledged parser as a subparser

2018-12-12 Thread Victor Porton


Victor Porton  added the comment:

Oh, I noticed I can do

my_subparser = subparsers.add_parser('checkout', aliases=['co'])

So resolution invalid.

--
resolution:  -> not a bug

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



[issue35442] Chain of several subcommands in argparse

2018-12-12 Thread Victor Porton


Victor Porton  added the comment:

One of possible solutions:
https://bugs.python.org/issue35480

--

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



[issue35480] argparse: add a full fledged parser as a subparser

2018-12-12 Thread Victor Porton


New submission from Victor Porton :

Subparsers are added like:

subparsers.add_parser('checkout', aliases=['co'])

But I want to use a parser BOTH as a subparser and as a full-fledged parser.

It is because my program should understand both of the following command line 
options:

boiler chain -t http://www.w3.org/1999/xhtml -W inverseofsum

and

boiler pipe 'chain -t http://www.w3.org/1999/xhtml -W inverseofsum + 
transformation http://example.com/ns1'.

I split it (at +) into several lists of arguments as explained in 
https://stackoverflow.com/a/53750697/856090

So I need `chain` both as a subparser and as a standalone parser of `-t 
http://www.w3.org/1999/xhtml -W inverseofsum`.

So, feature which I want:

subparsers.add_parser('checkout', aliases=['co'], parser=...)

where ... is a reference to a parser object.

--
components: Library (Lib)
messages: 331730
nosy: porton
priority: normal
severity: normal
status: open
title: argparse: add a full fledged parser as a subparser
type: enhancement
versions: Python 3.7

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



[issue9334] argparse: add a full fledged parser as a subparser

2018-12-12 Thread Victor Porton


Victor Porton  added the comment:

Subparsers are added like:

subparsers.add_parser('checkout', aliases=['co'])

But I want to use a parser BOTH as a subparser and as a full-fledged parser.

It is because my program should understand both of the following command line 
options:

boiler chain -t http://www.w3.org/1999/xhtml -W inverseofsum

and

boiler pipe 'chain -t http://www.w3.org/1999/xhtml -W inverseofsum + 
transformation http://example.com/ns1'.

I split it (at +) into several lists of arguments as explained in 
https://stackoverflow.com/a/53750697/856090

So I need `chain` both as a subparser and as a standalone parser of `-t 
http://www.w3.org/1999/xhtml -W inverseofsum`.

So, feature which I want:

subparsers.add_parser('checkout', aliases=['co'], parser=...)

where ... is a reference to a parser object.

--
nosy: +porton
title: argparse does not accept options taking arguments beginning with dash 
(regression from optparse) -> argparse: add a full fledged parser as a subparser
versions: +Python 3.7 -Python 3.5

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



[issue35442] Chain of several subcommands in argparse

2018-12-08 Thread Victor Porton


New submission from Victor Porton :

We should consider some way to implement argparse functionality asked here:

https://stackoverflow.com/q/53686523/856090

It is unclear how exactly to do this. This message is a call to discuss what 
should be the information format and API.

The awful thing is that I may need to write my own command line parser, as 
current argparse seems to be unable to provide this functionality.

I think, I will implement this for my program sooner or later but the idea to 
write my own analogue of argparse somehow terrifies me.

--
components: Library (Lib)
messages: 331393
nosy: porton
priority: normal
severity: normal
status: open
title: Chain of several subcommands in argparse
type: enhancement

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



[issue34306] minidom: wrong processing of xmlns attributes

2018-08-25 Thread Victor Porton


Victor Porton  added the comment:

My bug report was wrong:

https://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/core.html
In the DOM, all namespace declaration attributes are by definition bound to the 
namespace URI: "http://www.w3.org/2000/xmlns/;. These are the attributes whose 
namespace prefix or qualified name is "xmlns" as introduced in [XML Namespaces 
1.1].

--
resolution:  -> not a bug
stage:  -> resolved
status: open -> closed
type:  -> behavior

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



[issue34458] No way to alternate options

2018-08-21 Thread Victor Porton


New submission from Victor Porton :

I have:

parser.add_argument('-p', '--preload', help='preload asset', action='append', 
metavar='NAMESPACE')

I want also add:

parser.add_argument('-f', '--file', help='preload file', action='append', 
metavar='FILE', dest='preload')

This way I could specify -p and/or -f options in any order (like: first -p then 
-f then -p again) and store then in 'preload' field in the order which the user 
specified the options.

But I have no way to know if an option is -p or -f :-(

Please add something to argparse to solve this problem.

--
components: Library (Lib)
messages: 323857
nosy: porton
priority: normal
severity: normal
status: open
title: No way to alternate options
versions: Python 3.7

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



[issue34375] Subtests (unittest)

2018-08-10 Thread Victor Porton


New submission from Victor Porton :

The following is a fragment of a real code:

~~~
def test_run_xinlude(self):
# stub_stdin(self, 
Global.get_resource_bytes("tests/core/data/xml/xinclude.xml"))
for next_script_mode in ['doc1', 'doc2']:
for order in ['breadth', 'depth']:
with capture_stdin_and_stdout():
command_line.main(['-r',
   order,
   'chain',
   
Global.get_filename("tests/core/data/xml/xinclude.xml"),
   '-u',
   
'http://portonvictor.org/ns/trans/precedence-include',
   '-s',
   next_script_mode])
self.assertEqual(sys.stdout.buffer.getvalue(), 
TestUtility.XInclude_output,
 "for next_script=%s, order=%s" % 
(next_script_mode, order))
~~~

I wrote it in one test method instead of four similar methods.

It has the deficiency that if the first test fails, the three remaining tests 
are skipped.

I propose to add `subtest` context manager to use it like:

~~~
with subtest():
with capture_stdin_and_stdout():
command_line.main(['-r',
   order,
   'chain',
   
Global.get_filename("tests/core/data/xml/xinclude.xml"),
   '-u',
   
'http://portonvictor.org/ns/trans/precedence-include',
   '-s',
   next_script_mode])
self.assertEqual(sys.stdout.buffer.getvalue(), 
TestUtility.XInclude_output,
 "for next_script=%s, order=%s" % 
(next_script_mode, order))
~~~

which would split our test into four independent tests.

--
components: Library (Lib)
messages: 323375
nosy: porton
priority: normal
severity: normal
status: open
title: Subtests (unittest)
type: enhancement
versions: Python 3.7

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



[issue34306] minidom: wrong processing of xmlns attributes

2018-08-01 Thread Victor Porton


New submission from Victor Porton :

The below script prints

http://www.w3.org/2000/xmlns/
aa:aa

It should print

None
aa:aa

because xmlns:z is NOT an attribute of xmlns namespace.

~~~
import xml.dom.minidom

x = xml.dom.minidom.parseString("")

for i in x.documentElement.attributes.values():
print(i.namespaceURI)
~~~

--
components: XML
messages: 322860
nosy: porton
priority: normal
severity: normal
status: open
title: minidom: wrong processing of xmlns attributes
versions: Python 2.7, Python 3.6, Python 3.7

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



[issue34188] Allow dict choices to "transform" values in argpagse

2018-07-22 Thread Victor Porton


Victor Porton  added the comment:

@Raymond:
"Downstream processing or transformation of inputs is beyond the scope of 
argparse which should stick to its core responsibilities of argument 
extraction."

You somehow contradict the official documentation:
"One particularly effective way of handling sub-commands is to combine the use 
of the add_subparsers() method with calls to set_defaults() so that each 
subparser knows which Python function it should execute."

The official documentation seems to recommend to pass real Python functions to 
the parser. So it does do simple "processing or transformation of inputs" which 
you recommend against.

--

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



[issue34191] argparse: Missing subparser error message should be more clear

2018-07-22 Thread Victor Porton


New submission from Victor Porton :

argparse produces a long unreadable, non-understandable for non-programmers 
error message when a subparser is not specified in the command line.

Note that the below message contains Ubuntu specifics, but it seems it would be 
nearly as unclear on other OSes too.

The worst thing about this error message is that to produce something readable 
instead I need to somehow parse the command string (or at least to catch 
TypeError).

$ python3.7 test.py 
Traceback (most recent call last):
  File "test.py", line 10, in 
args = parser.parse_args()
  File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args
args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args
', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found
Error in sys.excepthook:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in 
apport_excepthook
from apport.fileutils import likely_packaged, get_recent_crashes
  File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in 
from apport.report import Report
  File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in 
import apport.fileutils
  File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in 

from apport.packaging_impl import impl as packaging
  File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 24, in 

import apt
  File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in 
import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

Original exception was:
Traceback (most recent call last):
  File "test.py", line 10, in 
args = parser.parse_args()
  File "/usr/lib/python3.7/argparse.py", line 1754, in parse_args
args, argv = self.parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 1786, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
  File "/usr/lib/python3.7/argparse.py", line 2021, in _parse_known_args
', '.join(required_actions))
TypeError: sequence item 0: expected str instance, NoneType found

The script follows.

#!/usr/bin/env python

import argparse

parser = argparse.ArgumentParser(description="Automatically process XML")
subparsers = parser.add_subparsers(title='subcommands')

chain_parser = subparsers.add_parser('chain', aliases=['c'], 
help='Automatically run a chain of transformations')

args = parser.parse_args()

--
components: Library (Lib)
messages: 322164
nosy: porton
priority: normal
severity: normal
status: open
title: argparse: Missing subparser error message should be more clear
type: behavior
versions: Python 3.7

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



[issue34188] Use dicts to "transform" argparse arguments to values

2018-07-22 Thread Victor Porton


New submission from Victor Porton :

The below code produces "rock", but it should produce "a". This (to use dict 
value instead of the key by argparse result) is both to be a new useful feature 
(for example to map strings in a command line to certain functions or classes 
provided as dict values) and conform to intuition better.

My feature proposal breaks backward compatibility, but I think no reasonable 
programmer wrote it in such a way that he relied on the current behavior for 
`dict` values for `choices`.

import argparse

parser = argparse.ArgumentParser(prog='game.py')
parser.add_argument('move', choices={'rock':'a', 'paper':'b', 'scissors':'c'})
print(parser.parse_args(['rock']))

--
components: Library (Lib)
messages: 322142
nosy: porton
priority: normal
severity: normal
status: open
title: Use dicts to "transform" argparse arguments to values
versions: Python 3.7

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



[issue34188] Use dicts to "transform" argparse arguments to values

2018-07-22 Thread Victor Porton


Change by Victor Porton :


--
type:  -> behavior

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



[issue34180] bool(Q) always return True for a priority queue Q

2018-07-21 Thread Victor Porton


New submission from Victor Porton :

It seems that bool(Q) always return True for a priority queue Q.

It should behave the same way as for bool(L) where L is a list, that is return 
False on an empty queue.

Please check also other objects in https://docs.python.org/3/library/queue.html

After the bug is fixed, the documentation should be clear that there was a 
change in the behavior in certain Python version.

--
components: Library (Lib)
messages: 322103
nosy: porton
priority: normal
severity: normal
status: open
title: bool(Q) always return True for a priority queue Q
type: behavior
versions: Python 3.7

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



[issue33343] Subcommand abbreviations

2018-04-23 Thread Victor Porton

New submission from Victor Porton <por...@narod.ru>:

https://docs.python.org/3/library/argparse.html does not allow abbreviations 
for subparsers ("subcommands").

It seems inconsistent that long options can be abbreviated but subcommands 
cannot.

Either implement subcommand abbreviations or explain in the docs why there is 
none.

--
components: Library (Lib)
messages: 315671
nosy: porton
priority: normal
severity: normal
status: open
title: Subcommand abbreviations
type: enhancement
versions: Python 3.6

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue33343>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32875] Add __exit__() method to event loops

2018-02-19 Thread Victor Porton

New submission from Victor Porton <por...@narod.ru>:

Please add `__exit__()` method to event loops, to use them with `with`.

--
components: asyncio
messages: 312360
nosy: asvetlov, porton, yselivanov
priority: normal
severity: normal
status: open
title: Add __exit__() method to event loops
type: enhancement
versions: Python 3.6

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32875>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue32871] Interrupt .communicate() on SIGTERM/INT

2018-02-18 Thread Victor Porton

New submission from Victor Porton <por...@narod.ru>:

At https://docs.python.org/3/library/subprocess.html there is said nothing 
about what happens if our Python program terminates (by SIGTERM or SIGINT) 
while waiting for .communicate().

I assume to do something in this situation is just forgotten.

Usually terminate of our program should also terminate the invoked script. It 
can be made by re-delivery SIGTERM/SIGINT or (on non-POSIX) by .terminate() 
method. Probably, it should be done by .terminate() method even on POSIX 
systems, to handle SIGTERM and SIGINT in the same way.

--
components: Library (Lib)
messages: 312328
nosy: porton
priority: normal
severity: normal
status: open
title: Interrupt .communicate() on SIGTERM/INT
type: behavior
versions: Python 3.6

___
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32871>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue28825] socket.SO_KEEPALIVE does not work on FreeBSD

2016-11-28 Thread Victor Porton

Victor Porton added the comment:

Weird, after I minimized the PHP example, it also has the same bug as the 
Python one. (The real long code in PHP was working without this bug.)

I attach the PHP code for your reference.

Maybe it is a FreeBSD bug?

Please write to por...@narod.ru with advice how to make the server not to 
disconnect after 5 minutes of idle connection.

--
Added file: http://bugs.python.org/file45678/bug.php

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



[issue28825] socket.SO_KEEPALIVE does not work on FreeBSD

2016-11-28 Thread Victor Porton

New submission from Victor Porton:

When I connect

telnet XXX 9000

to the server in attached file, the connection breaks after 5 min (and a few 
seconds), as if SO_KEEPALIVE were not specified.

I run my server on
FreeBSD 9.2-RELEASE-p15 (GENERIC)

So SO_KEEPALIVE does not work in Python 2.7 and 3.5 on FreeBSD.

Specifically, I need my TCP connection not to break in extended periods of time 
and cannot do this with Python.

It seems that similar code does work with PHP (I am going to write a short PHP 
example), so it is likely a Python bug, not FreeBSD bug.

--
components: FreeBSD, IO, Library (Lib)
files: bug.py
messages: 281911
nosy: koobs, porton
priority: normal
severity: normal
status: open
title: socket.SO_KEEPALIVE does not work on FreeBSD
type: behavior
versions: Python 2.7, Python 3.5
Added file: http://bugs.python.org/file45677/bug.py

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