[issue9640] Improved doctest REPORT_*DIFFs with ELLIPSIS and/or NORMALIZE_WHITESPACE

2010-08-19 Thread W. Trevor King

New submission from W. Trevor King :

I had been struggling to find the failure-causing mismatch in a doctest with 
lots of output.  REPORT_UDIFF gave lots of false mismatches because I was also 
using NORMALIZE_WHITESPACE.  Looking through the doctest.py source, I saw a 
comment suggesting a nicer diff in the similar REPORT_*DIFF and ELLIPSIS 
situation.  So I went ahead and implemented one.  I'm not super happy with the 
cleanliness of the implementation, but it ended up being a bit trickier than 
I'd initially expected.

--
components: Library (Lib)
messages: 114340
nosy: labrat
priority: normal
severity: normal
status: open
title: Improved doctest REPORT_*DIFFs with ELLIPSIS and/or NORMALIZE_WHITESPACE
type: feature request
versions: Python 2.7

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



[issue9640] Improved doctest REPORT_*DIFFs with ELLIPSIS and/or NORMALIZE_WHITESPACE

2010-08-19 Thread W. Trevor King

W. Trevor King  added the comment:

Here's my patch, or pull from my Mercurial repository
  
http://www.physics.drexel.edu/~wking/code/hg/hgwebdir.cgi/python/rev/6638df20c1a4

--
keywords: +patch
Added file: http://bugs.python.org/file18575/doctest_diff.patch

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



[issue33003] urllib: Document parse_http_list

2018-03-05 Thread W. Trevor King

New submission from W. Trevor King :

Python has had a parse_http_list helper since urllib2 landed in 6d7e47b8ea 
(EXPERIMENTAL, 2000-01-20).  With Python3 it was moved into urllib.request, and 
the implementation hasn't changed since (at least as of 4c19b9573, 2018-03-05). 
 External projects depend on the currently undocumented function [1,2], so it 
would be nice to have some user-facing documentation for it.  If that sounds 
appealing, I'm happy to work up a pull request.

[1]: https://github.com/requests/requests/blob/v2.18.4/requests/compat.py#L42
[2]: https://github.com/requests/requests/blob/v2.18.4/requests/compat.py#L58

--
assignee: docs@python
components: Documentation
messages: 313294
nosy: docs@python, labrat
priority: normal
severity: normal
status: open
title: urllib: Document parse_http_list
type: enhancement
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

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



[issue33008] urllib.request.parse_http_list incorrectly strips backslashes

2018-03-05 Thread W. Trevor King

New submission from W. Trevor King :

Python currently strips backslashes from inside quoted strings:

  $ echo 'a="b\"c",d=e' | python3 -c 'from sys import stdin; from 
urllib.request import parse_http_list; print(parse_http_list(stdin.read()))'
  ['a="b"c"', 'd=e']

It should be printing:

  ['a="b\"c"', 'd=e']

The bug is this continue [1], which should be removed.  This was not a problem 
with the original implementation [2].  It was introduced in [3] as a fix for 
#735248 with explicit tests asserting the broken behavior [3].  Stripping 
backslashes from the insides of quoted strings is not appropriate, because it 
breaks explicit unquoting with email.utils.unquote [4]:

  import email.utils
  import urllib.request
  list = r'"b\\"c"'
  entry = urllib.request.parse_http_list(list)[0]
  entry  # '"b\\"c"', should be '"b"c"'
  email.utils.unquote(entry)  # 'b"c', should be 'b\\"c'

I'm happy to file patches against the various branches if that would help, but 
as a one-line removal (plus adjusting the tests), it might be easier if a 
maintainer files the patches.

[1]: https://github.com/python/cpython/blob/v3.7.0b2/Lib/urllib/request.py#L1420
[2]: 
https://github.com/python/cpython/commit/6d7e47b8ea1b8cf82927dacc364689b8eeb8708b#diff-33f7983ed1a69d290366fe426880581cR777
[3]: 
https://github.com/python/cpython/commit/e1b13d20199f79ffd3407bbb14cc09b1b8fd70d2#diff-230a8abfedeaa9ae447490df08172b15R52
[4]: https://docs.python.org/3.5/library/email.util.html#email.utils.unquote

--
components: Library (Lib)
messages: 313308
nosy: labrat
priority: normal
severity: normal
status: open
title: urllib.request.parse_http_list incorrectly strips backslashes
versions: Python 2.7, Python 3.4, Python 3.5, Python 3.6, Python 3.7, Python 3.8

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



[issue9253] argparse: optional subparsers

2013-01-18 Thread W. Trevor King

W. Trevor King added the comment:

Since [1] it seems like subparsers *are* optional by default.  At least I get 
“error: too few arguments” for version 70740 of Lib/argparse.py, but no error 
for version 70741.  It looks like this may be an unintentional side effect, 
since I see no mention of subparsers in #10424.

[1]: http://hg.python.org/cpython/rev/cab204a79e09

--
nosy: +labrat
Added file: http://bugs.python.org/file28778/check.py

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



[issue19226] distutils/command/upload.py show response gives: TypeError: sequence item 1: expected str instance, bytes found

2013-10-11 Thread W. Trevor King

New submission from W. Trevor King:

Avoid:

Traceback (most recent call last):
  File "setup.py", line 61, in 
'html2text (>=3.0.1)',
  File "/.../python3.2/distutils/core.py", line 148, in setup
dist.run_commands()
  File "/.../python3.2/distutils/dist.py", line 917, in run_commands
self.run_command(cmd)
  File "/.../python3.2/distutils/dist.py", line 936, in run_command
cmd_obj.run()
  File "/.../python3.2/distutils/command/upload.py", line 66, in run
self.upload_file(command, pyversion, filename)
  File "/.../python3.2/distutils/command/upload.py", line 201, in 
upload_file
msg = '\n'.join(('-' * 75, r.read(), '-' * 75))
TypeError: sequence item 1: expected str instance, bytes found

by converting the bytes returned by HTTPResponse.read [1] to a string
before joinging it with other strings.  HTTPResponse.headers supports
the Message interface [2], so we can use get_param to extract the
charset [3], falling back on ISO-8859-1 [4].

[1]: 
http://docs.python.org/3/library/http.client.html#http.client.HTTPResponse.read
[2]: http://docs.python.org/3/library/http.client.html#httpmessage-objects
[3]: 
http://docs.python.org/3/library/email.message.html#email.message.Message.get_param
[4]: http://tools.ietf.org/html/rfc2616#section-3.7.1

--
assignee: eric.araujo
components: Distutils
files: show-response-string.patch
keywords: patch
messages: 199489
nosy: eric.araujo, labrat, tarek
priority: normal
severity: normal
status: open
title: distutils/command/upload.py show response gives: TypeError: sequence 
item 1: expected str instance, bytes found
versions: Python 3.2, Python 3.3, Python 3.4, Python 3.5
Added file: http://bugs.python.org/file32045/show-response-string.patch

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



[issue19226] distutils/command/upload.py show response gives: TypeError: sequence item 1: expected str instance, bytes found

2013-10-11 Thread W. Trevor King

W. Trevor King added the comment:

On Fri, Oct 11, 2013 at 05:21:15PM +, Ned Deily wrote:
> This problem has been reported previously as Issue17354, a duplicate
> of Issue12853 which is still open at the moment.

Ah, I searched for a fwe possible subject lines, but didn't hit those
:p.  I thought that if it wasn't fixed in the master branch it must
not have an associated issue…

I like my patch better than Issue17354's, because PyPI servers may not
always use UTF-8.  I'll ping Issue12853 about the patches, because
either one would fix Issue12853, and it's currently "needs patch".

--

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



[issue12853] global name 'r' is not defined in upload.py

2013-10-11 Thread W. Trevor King

W. Trevor King added the comment:

I just posted a patch fixing this in the current master branch [1].  Ned Deily 
pointed out that my Issue19226 duplicated an earlier Issue17354, which also has 
a patch fixing this problem.  Merging either one of these patches should close 
this issue.  I like my patch's generic charset handling better, but for PyPI 
uploads either one would work fine.

I've looked through the Mercurial logs, but it looks like this r *has* been 
around since 34794 (Implement the Distutils 'upload' subcommand (upload package 
to PyPI), 2005-03-21), so I don't know where the "global name 'r' is not 
defined" message came from.

--
nosy: +labrat

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



[issue6612] 'import site' fails when called from an unlinked directory

2009-07-31 Thread W. Trevor King

New submission from W. Trevor King :

I don't imagine this comes up very often, but:

$ mkdir /tmp/a; cd /tmp/a; rmdir /tmp/a; python -c 'import site';
rmdir: removing directory, /tmp/a
'import site' failed; use -v for traceback
Traceback (most recent call last):
  File "", line 1, in 
  File "/home/wking/lib/python/site.py", line 73, in 
__boot()
  File "/home/wking/lib/python/site.py", line 33, in __boot
imp.load_module('site',stream,path,descr)
  File "/usr/lib/python2.5/site.py", line 408, in 
main()
  File "/usr/lib/python2.5/site.py", line 392, in main
paths_in_sys = removeduppaths()
  File "/usr/lib/python2.5/site.py", line 96, in removeduppaths
dir, dircase = makepath(dir)
  File "/usr/lib/python2.5/site.py", line 72, in makepath
dir = os.path.abspath(os.path.join(*paths))
  File "/usr/lib/python2.5/posixpath.py", line 403, in abspath
path = join(os.getcwd(), path)
OSError: [Errno 2] No such file or directory

--
messages: 91129
nosy: labrat
severity: normal
status: open
title: 'import site' fails when called from an unlinked directory
versions: Python 2.5

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



[issue6612] 'import site' fails when called from an unlinked directory

2010-07-29 Thread W. Trevor King

W. Trevor King  added the comment:

I just fixed it myself ;).  As I said before, not really a big deal, but it was 
an easy fix.  I've attached a patch, or you can merge my hg branch f 
python-trunk at

  http://www.physics.drexel.edu/~wking/code/hg/hgwebdir.cgi/python/

--
keywords: +patch
versions: +Python 2.6, Python 2.7
Added file: http://bugs.python.org/file18264/issue6612.patch

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



[issue5752] xml.dom.minidom does not escape CR, LF and TAB characters within attribute values

2010-08-02 Thread W. Trevor King

W. Trevor King  added the comment:

As a workaround until the patch gets included, you can import this monkey patch 
module.

--
nosy: +labrat
Added file: http://bugs.python.org/file18325/minidom.py

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



[issue5752] xml.dom.minidom does not escape CR, LF and TAB characters within attribute values

2010-08-03 Thread W. Trevor King

W. Trevor King  added the comment:

And while we're at it, we should also

   .replace('&', '&').replace('"', """).replace('<', '<')

which would have to go at the beginning to avoid double-escaping the '&'.

We could use xml.sax.saxutils.escape to do all the escaping rather than 
chaining replaces:

   data = escape(data, {'"':'"', '\r':'
', '\n':'
', '\t':'	'})

which also escapes '>' (not strictly required for attribute values, but 
shouldn't be harmful either).

--

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



[issue22684] message.as_bytes() produces recursion depth exceeded

2014-11-07 Thread W. Trevor King

W. Trevor King added the comment:

Here's an example from the notmuch list.  You can trigger the exception in 
Python 3.4 with:

  >>> import email.policy
  >>> import mailbox
  >>> mbox = mailbox.mbox('msg.mbox', factory=None, create=False)
  >>> message = mbox[0]
  >>> message.as_bytes(policy=email.policy.SMTP)
  Traceback (most recent call last):
File "", line 1, in 
File "/home/wking/src/notmuch/ssoma_mda.py", line 319, in deliver
  message_bytes = message.as_bytes(policy=_email_policy.SMTP)
File "/usr/lib64/python3.4/email/message.py", line 179, in as_bytes
  g.flatten(self, unixfrom=unixfrom)
File "/usr/lib64/python3.4/email/generator.py", line 112, in flatten
  self._write(msg)
File "/usr/lib64/python3.4/email/generator.py", line 192, in _write
  self._write_headers(msg)
…
File "/usr/lib64/python3.4/email/_header_value_parser.py", line 195, in 

  return ''.join(str(x) for x in self)
  RuntimeError: maximum recursion depth exceeded while getting the str of an 
object

Interestingly, it serializes fine using the default policy:

  >>> message.as_bytes()
  b'Return-Path: …-\n'

--
nosy: +labrat
Added file: http://bugs.python.org/file37143/msg.mbox

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



[issue22684] message.as_bytes() produces recursion depth exceeded

2014-11-07 Thread W. Trevor King

W. Trevor King added the comment:

The troublesome header formatting is:

  >>> import email.policy
  >>> email.policy.SMTP.fold_binary('Cc', 
'notmuch\n\t,\n\tpublic-notmuch-gxuj+tv9eo5zyzon3hd...@plane.gmane.org,\n\tRainer
 M Krug ,\n\tJeremy 
Nickurak\n\t')
  Traceback (most recent call last):
…
  RuntimeError: maximum recursion depth exceeded while getting the str of an 
object

Trimming that down a bit, a minimal trigger seems to be:

  >>> email.policy.SMTP.fold_binary('Cc', 
'a\n\ta,\n\ta')
  Traceback…

Where removing much of anything gives a working fold.

--

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



[issue22684] message.as_bytes() produces recursion depth exceeded

2014-11-07 Thread W. Trevor King

W. Trevor King added the comment:

In email._header_value_parser._Folded.append_if_fits, if I shift:

if token.has_fws:
ws = token.pop_leading_fws()
if ws is not None:
self.stickyspace += str(ws)
stickyspace_len += len(ws)
token._fold(self)
return True

to:

if token.has_fws:
ws = token.pop_leading_fws()
if ws is not None:
self.stickyspace += str(ws)
stickyspace_len += len(ws)
token._fold(self)
return True

I can avoid the recursion.

The problem seems to be that the "a …aaa" token/part contains folding white 
space, but doesn't *start* with folding whitespace.  Maybe the folding should 
try to split on existing FWS, instead of just trying to pop leading FWS?

--

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



[issue25852] smtplib's SMTP.connect() should store the server name in ._host for .starttls()

2015-12-12 Thread W. Trevor King

New submission from W. Trevor King:

With the current tip, starttls uses ._host when calling wrap_socket [1], but 
._host is only setup in SMTP.__init__ [2].  Before #22921 [3] starttls would 
ignore ._host when SNI wasn't available locally.  But as far as I can tell, 
starttls has never used _host when connection happens via an explicit connect() 
call.  This leads to errors like [4]:

  >>> smtp = smtplib.SMTP()
  >>> smtp.connect(host="smtp.gmail.com", port=587)
  >>> smtp.ehlo()
  >>> smtp.starttls()
  File "smtp_test.py", line 10, in 
smtp.starttls()
  File "/usr/lib/python3.4/smtplib.py", line 676, in starttls
server_hostname=server_hostname)
  File "/usr/lib/python3.4/ssl.py", line 344, in wrap_socket
_context=self)
  File "/usr/lib/python3.4/ssl.py", line 540, in __init__
self.do_handshake()
  File "/usr/lib/python3.4/ssl.py", line 767, in do_handshake
self._sslobj.do_handshake()
  ssl.SSLError: [SSL: TLSV1_ALERT_DECODE_ERROR] tlsv1 alert decode error 
(_ssl.c:598)

I think a better approach would be to move the ._host set into .connect (patch 
attached).  It would still happen in SMTP(host=…) because [5], but would also 
allow starttls when users use SMTP() and then call connect(host=…) explicitly.

I've formatted the patch with Git, but its simple enough that it should be easy 
to apply in Mercurial.  Still, let me know if I can make applying it easier by 
rerolling the patch.

[1]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l766
[2]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l244
[3]: http://bugs.python.org/issue22921
[4]: 
http://stackoverflow.com/questions/23616803/smtplib-smtp-starttls-fails-with-tlsv1-alert-decode-error
[5]: https://hg.python.org/cpython/file/323c10701e5d/Lib/smtplib.py#l251

--
components: Library (Lib)
files: 0001-smtplib-Set-SMTP._host-in-.connect.patch
keywords: patch
messages: 256299
nosy: labrat
priority: normal
severity: normal
status: open
title: smtplib's SMTP.connect() should store the server name in ._host for 
.starttls()
type: behavior
versions: Python 3.3, Python 3.4, Python 3.5
Added file: 
http://bugs.python.org/file41291/0001-smtplib-Set-SMTP._host-in-.connect.patch

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



[issue26080] "abandonned" -> "abandoned" in PEP 510's https://hg.python.org/peps/rev/b463c740990c

2016-01-11 Thread W. Trevor King

New submission from W. Trevor King:

In the recently-landed [1],

  There was also the Unladen Swallow project, but it was abandonned in 2011.

Should have used “abandoned” instead of “abandonned”.

[1]: https://hg.python.org/peps/rev/b463c740990c
 changeset: 6155:b463c740990c
 user: Victor Stinner gmail.com>
 date: Sun Jan 10 14:58:17 2016 +0100
 summary: PEP 510: rationale for static optimize vs JIT compiler
 http://permalink.gmane.org/gmane.comp.python.cvs/114604

--
assignee: docs@python
components: Documentation
messages: 257974
nosy: docs@python, labrat
priority: normal
severity: normal
status: open
title: "abandonned" -> "abandoned" in PEP 510's 
https://hg.python.org/peps/rev/b463c740990c
type: enhancement

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