Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.assertFalse(bongacams.can_handle_url("test://bongacams.com/test"))
# invalid stream path
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
# invalid stream path
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https://test.domain/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.co.uk/test'))
# invalid separator
self.assertFalse(bongacams.can_handle_url('http bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(' bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(':///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httptestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httpstestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('testbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https://test.domain/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.co.uk/test'))
# invalid separator
self.assertFalse(bongacams.can_handle_url('http bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(' bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(':///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httptestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httpstestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('testbongacams.com/test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https://test.domain/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.co.uk/test'))
# invalid separator
self.assertFalse(bongacams.can_handle_url('http bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(' bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('//bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https:///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(':///bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httptestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('httpstestbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('testbongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https://test.domain/test'))
self.assertFalse(bongacams.can_handle_url('http://xx.bongacams.com/\\test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('https://xx.bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('bongacams.com/\test'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/ '))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\\'))
self.assertFalse(bongacams.can_handle_url('xx.bongacams.com/\test'))
# invalid domain
self.assertFalse(bongacams.can_handle_url('https:// /test'))
self.assertFalse(bongacams.can_handle_url('https://xxx.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https://x.bongacams/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.jp/test'))
self.assertFalse(bongacams.can_handle_url('https://test.domain/test'))
self.assertFalse(bongacams.can_handle_url('https://bongacams.co.uk/test'))
# invalid separator
self.assertFalse(bongacams.can_handle_url('http bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('https bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url(' bongacams.com/test'))
self.assertFalse(bongacams.can_handle_url('http//bongacams.com/test'))
def _get_streams(self):
parsed = urlparse(self.url)
cls = PROTOCOL_MAP.get(parsed.scheme)
if not cls:
return
split = self.url.split(" ")
url = split[0]
urlnoproto = SCHEME_REGEX.match(url).group(1)
# Prepend http:// if needed.
if cls != RTMPStream and not SCHEME_REGEX.match(urlnoproto):
urlnoproto = "http://{0}".format(urlnoproto)
params = " ".join(split[1:])
params = self._parse_params(params)
# remove \
new_url = url.replace('\\', '')
# repairs broken scheme
if new_url.startswith('http://'):
new_url = 'http:' + new_url[9:]
elif new_url.startswith('https://'):
new_url = 'https:' + new_url[10:]
new_url = unquote(new_url)
# creates a valid url from path only urls
# and adds missing scheme for // urls
if stream_base and new_url[1] != '/':
if new_url[0] == '/':
new_url = new_url[1:]
new_url = urljoin(stream_base, new_url)
else:
new_url = urljoin(base_url, new_url)
return new_url
def repair_url(self, url, base_url, stream_base=''):
# remove \
new_url = url.replace('\\', '')
# repairs broken scheme
if new_url.startswith('http://'):
new_url = 'http:' + new_url[9:]
elif new_url.startswith('https://'):
new_url = 'https:' + new_url[10:]
new_url = unquote(new_url)
# creates a valid url from path only urls
# and adds missing scheme for // urls
if stream_base and new_url[1] != '/':
if new_url[0] == '/':
new_url = new_url[1:]
new_url = urljoin(stream_base, new_url)
else:
new_url = urljoin(base_url, new_url)
return new_url