How to use the asciinema.asciicast.__init__.LoadError function in asciinema

To help you get started, we’ve selected a few asciinema examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github asciinema / asciinema / asciinema / asciicast / __init__.py View on Github external
url = response.geturl()  # final URL after redirects

        if response.headers['Content-Encoding'] == 'gzip':
            body = gzip.open(body)

        utf8_reader = codecs.getreader('utf-8')
        content_type = response.headers['Content-Type']

        if content_type and content_type.startswith('text/html'):
            html = utf8_reader(body, errors='replace').read()
            parser = Parser()
            parser.feed(html)
            new_url = parser.url

            if not new_url:
                raise LoadError(""" not found in fetched HTML document""")

            if "://" not in new_url:
                base_url = urlparse(url)

                if new_url.startswith("/"):
                    new_url = urlunparse((base_url[0], base_url[1], new_url, '', '', ''))
                else:
                    path = os.path.dirname(base_url[2]) + '/' + new_url
                    new_url = urlunparse((base_url[0], base_url[1], path, '', '', ''))

            return open_url(new_url)

        return utf8_reader(body, errors='strict')

    return open(url, mode='rt', encoding='utf-8')
github asciinema / asciinema / asciinema / asciicast / __init__.py View on Github external
def __enter__(self):
        try:
            self.file = open_url(self.url)
            first_line = self.file.readline()

            try:  # try v2 first
                self.context = v2.open_from_file(first_line, self.file)
                return self.context.__enter__()
            except v2.LoadError:
                try:  # try v1 next
                    self.context = v1.open_from_file(first_line, self.file)
                    return self.context.__enter__()
                except v1.LoadError:
                    raise LoadError(self.FORMAT_ERROR)

        except (OSError, urllib.error.HTTPError) as e:
            raise LoadError(str(e))
github asciinema / asciinema / asciinema / asciicast / __init__.py View on Github external
try:
            self.file = open_url(self.url)
            first_line = self.file.readline()

            try:  # try v2 first
                self.context = v2.open_from_file(first_line, self.file)
                return self.context.__enter__()
            except v2.LoadError:
                try:  # try v1 next
                    self.context = v1.open_from_file(first_line, self.file)
                    return self.context.__enter__()
                except v1.LoadError:
                    raise LoadError(self.FORMAT_ERROR)

        except (OSError, urllib.error.HTTPError) as e:
            raise LoadError(str(e))