Skip to content

RTSPS scheme support in urllib.parse #104554

@zentarim

Description

@zentarim

In accordance with
https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

There are three valid RTSP schemes:

URI Scheme Description Status Reference
rtsp Real-Time Streaming Protocol (RTSP) Permanent [RFC2326][RFC7826]
rtsps Real-Time Streaming Protocol (RTSP) over TLS Permanent [RFC2326][RFC7826]
rtspu Real-Time Streaming Protocol (RTSP) over unreliable datagram transport Permanent [RFC2326]

But in urllib/parse.py only two of them are defined:

  • rtsp
  • rtspu

What make impossible to use functions like urllib.parse.urljoin() upon rtsps://* URLs:

Type "help", "copyright", "credits" or "license" for more information. >>> from urllib.parse import urljoin >>> urljoin('rtsps://127.0.0.1/foo/bar', 'trackID=1') 'trackID=1' 

Expected result is:

Type "help", "copyright", "credits" or "license" for more information. >>> from urllib.parse import urljoin >>> urljoin('rtsps://127.0.0.1/foo/bar', 'trackID=1') 'rtsps://127.0.0.1/foo/trackID=1' >>> 

I was able to get the expected behavior by patching urllib/parsing.py:

--- parse.py.bak 2023-05-16 16:16:01.910634526 +0000 +++ parse.py 2023-05-16 16:17:35.793154580 +0000 @@ -46,17 +46,17 @@ uses_relative = ['', 'ftp', 'http', 'gopher', 'nntp', 'imap', 'wais', 'file', 'https', 'shttp', 'mms', - 'prospero', 'rtsp', 'rtspu', 'sftp', + 'prospero', 'rtsp', 'rtsps', 'rtspu', 'sftp', 'svn', 'svn+ssh', 'ws', 'wss'] uses_netloc = ['', 'ftp', 'http', 'gopher', 'nntp', 'telnet', 'imap', 'wais', 'file', 'mms', 'https', 'shttp', - 'snews', 'prospero', 'rtsp', 'rtspu', 'rsync', + 'snews', 'prospero', 'rtsp', 'rtsps', 'rtspu', 'rsync', 'svn', 'svn+ssh', 'sftp', 'nfs', 'git', 'git+ssh', 'ws', 'wss'] uses_params = ['', 'ftp', 'hdl', 'prospero', 'http', 'imap', - 'https', 'shttp', 'rtsp', 'rtspu', 'sip', 'sips', + 'https', 'shttp', 'rtsp', 'rtsps', 'rtspu', 'sip', 'sips', 'mms', 'sftp', 'tel'] # These are not actually used anymore, but should stay for backwards @@ -66,7 +66,7 @@ 'telnet', 'wais', 'imap', 'snews', 'sip', 'sips'] uses_query = ['', 'http', 'wais', 'imap', 'https', 'shttp', 'mms', - 'gopher', 'rtsp', 'rtspu', 'sip', 'sips'] + 'gopher', 'rtsp', 'rtsps', 'rtspu', 'sip', 'sips'] uses_fragment = ['', 'ftp', 'hdl', 'http', 'gopher', 'news', 'nntp', 'wais', 'https', 'shttp', 'snews', 

The issue presents in Python versions:

  • 3.10.6
  • 3.12.0a7

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions