Module: rtclite.std.ietf.rfc7065
# Copyright (c) 2016, Kundan Singh. All rights reserved. See LICENSE for details.
This file implements RFC7065 (TURN URI)
''' TURN URI It modifies URI class from rfc2396 module to include "turn" in list of schemes, so that the "secure" property of the URI object can be used to convert "turn" to "turns" scheme, and to test whether the URI is "turns" scheme. ''' from .rfc2396 import URI def patch(): if 'turn' not in URI._schemes: URI._schemes.append('turn') patch() def parts(uri): '''Return TURN URI specific components in a tuple, (host, port, transport, secure). Here transport is one of 'udp', 'tcp', 'tls' or 'dtls'; secure is boolean, host is str and port is int. >>> print parts(URI('')) ('', 8000, 'tcp', False) >>> for s in ('', '', '', ... '', '', ... '', ''): ... print parts(URI(s)) ('', 3478, 'udp', False) ('', 5349, 'tls', True) ('', 8000, 'udp', False) ('', 3478, 'udp', False) ('', 3478, 'tcp', False) ('', 5349, 'tls', True) ('', 5349, 'dtls', True) ''' if not uri or uri.scheme not in ('turn', 'turns'): raise ValueError('not a turn uri') transport, host, port, secure = 'udp' if not else 'tcp',, uri.port, if not uri.port: port = 5349 if uri.scheme == 'turns' else 3478 if uri.header: transports = [h[10:] for h in uri.header if h.startswith('transport=')] if len(transports) > 1: raise ValueError('more than one transport header') if transports: transport = transports[0] if transport = {'udp': 'dtls', 'tcp': 'tls'}.get(transport, transport) return (host, port, transport, secure) if __name__ == '__main__': import doctest doctest.testmod()