[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread R. David Murray


Change by R. David Murray :


--
resolution:  -> not a bug

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread Abhilash Raj


Change by Abhilash Raj :


--
stage:  -> resolved
status: open -> closed

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread Abhilash Raj


Abhilash Raj  added the comment:

Ah! But blank lists aren't.

That makes sense! Thank you!

--

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread R. David Murray


R. David Murray  added the comment:

It would be odd to do that, since blank values are kept by default.

--

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread Abhilash Raj


Abhilash Raj  added the comment:

Would it then make sense to add a similar flag, keep_blank_values, in urlencode 
to achieve similar behavior as parse_qas?

--

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-30 Thread R. David Murray


R. David Murray  added the comment:

If a sequence as a value means repeated instances of a key with each value from 
the list, then logically an empty list means no instances of the key, as 
documented.  Blank values aren't really part of the standard (such as it is): 
the absence of a parameter is supposed to be equivalent to the value being 
empty.  Because of this, you have to pass keep_blank_values=True to parse_qs to 
retain keys with blank values.  I think it is reasonable that you have to take 
extra action if you want an empty list of values to instead result in a single 
key with a blank value.

So, this is working as designed and desired, I think.

--
nosy: +r.david.murray

___
Python tracker 

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



[issue33690] urlib.parse.urlencode with empty list and doseq=True drops the parameter

2018-05-29 Thread Abhilash Raj


New submission from Abhilash Raj :

When using `urllib.parse.urlencode` it is impossible to pass an empty list when 
doseq=True.

So, I see the following behavior when using urlencode:

In [3]: urlencode({'key': ['value']}, doseq=True)
Out[3]: 'key=value'

In [4]: urlencode({'key': []}, doseq=True)
Out[4]: ''

So, in our source code, we do urlecode(params, doseq=True), which can have keys 
with empty list as values and it gets dropped completely. To get it to work 
properly, I instead pass around an empty string as a value when the length of 
list is 0, which conveys the server that the value of the key is empty.

I wonder if it would make sense for urlencode to do that by default given 
doseq=True is meant to encode lists properly.

--
messages: 318153
nosy: maxking
priority: normal
severity: normal
status: open
title: urlib.parse.urlencode with empty list and doseq=True drops the parameter
type: behavior
versions: Python 3.6

___
Python tracker 

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