[issue25895] urllib.parse.urljoin does not handle WebSocket URLs

2015-12-16 Thread Gergely Imreh

Gergely Imreh added the comment:

Just signed it, thanks!

--

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



[issue25895] urllib.parse.urljoin does not handle WebSocket URLs

2015-12-16 Thread Gergely Imreh

New submission from Gergely Imreh:

Handling the "ws" and "wss" schemes of the WebSocket protocol in 
urllib.parse.urlparse was discussed in a previous issue 
http://bugs.python.org/issue13244 Parsing them seems to work correctly:

>>> urllib.parse.urlparse("wss://domain/endpoint")
ParseResult(scheme='wss', netloc='domain', path='/endpoint', params='', 
query='', fragment='')

On the other hand, urllib.parse.urljoin does not know about these schemes and 
thus cannot be used to construct WebSocket URLs (as, for example some streaming 
data APIs now seem to use it, such as 
https://starfighter.readme.io/docs/quotes-ticker-tape-websocket).

Using the example above I get:

>>> urllib.parse.urljoin("wss://domain/","/endpoint")
'/endpoint'

This is not the expected result, 'wss://example.com/endpoint', because these 
WebSocket schemes are not included in the uses_relative and uses_netloc lists 
in the library settings. For clarity, based on the previous issue's discussion 
and RFC6455 Section 11.1 https://tools.ietf.org/html/rfc6455#section-11.1 , 
these are the only two portions that apply, and should not be listed in 
uses_params.

As a workaround, similarly to the previous issue's recommendation, one can use:

>> import urlparse.parse
>> wsschemes = ["ws", "wss"]
>> urlparse.parse.uses_relative.extend(wsschemes)
>> urlparse.parse.uses_netloc.extend(wsschemes)

Attached patch to this effect. Also added tests to cover these schemes, though 
comments are definitely welcome on all of this!

--
files: 0001-urllib.parse-enable-WebSocket-URL-schemes-to-be-corr.patch
keywords: patch
messages: 256581
nosy: imrehg
priority: normal
severity: normal
status: open
title: urllib.parse.urljoin does not handle WebSocket URLs
type: behavior
versions: Python 3.4, Python 3.5
Added file: 
http://bugs.python.org/file41334/0001-urllib.parse-enable-WebSocket-URL-schemes-to-be-corr.patch

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