How to use the asciinema.asciicast.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.py View on Github external
raise LoadError('unsupported asciicast format')

        return Asciicast(
            attrs['stdout'],
            attrs['width'],
            attrs['height'],
            attrs['duration'],
            attrs['command'],
            attrs['title']
        )
    except (OSError, urllib.error.HTTPError) as e:
        raise LoadError(str(e))
    except JSONDecodeError as e:
        raise LoadError('JSON decoding error: ' + str(e))
    except KeyError as e:
        raise LoadError('asciicast is missing key ' + str(e))
github asciinema / asciinema / asciinema / asciicast.py View on Github external
def load(filename):
    try:
        attrs = json.loads(fetch(filename))

        if type(attrs) != dict:
            raise LoadError('unsupported asciicast format')

        return Asciicast(
            attrs['stdout'],
            attrs['width'],
            attrs['height'],
            attrs['duration'],
            attrs['command'],
            attrs['title']
        )
    except (OSError, urllib.error.HTTPError) as e:
        raise LoadError(str(e))
    except JSONDecodeError as e:
        raise LoadError('JSON decoding error: ' + str(e))
    except KeyError as e:
        raise LoadError('asciicast is missing key ' + str(e))
github asciinema / asciinema / asciinema / asciicast.py View on Github external
if url == "-":
        return sys.stdin.read()

    if url.startswith("http:") or url.startswith("https:"):
        response = urllib.request.urlopen(url)
        data = response.read().decode(errors='replace')

        content_type = response.headers['Content-Type']
        if content_type and content_type.startswith('text/html'):
            parser = Parser()
            parser.feed(data)
            url = parser.url

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

            return fetch(url)

        return data

    with open(url, 'r') as f:
        return f.read()
github asciinema / asciinema / asciinema / asciicast.py View on Github external
try:
        attrs = json.loads(fetch(filename))

        if type(attrs) != dict:
            raise LoadError('unsupported asciicast format')

        return Asciicast(
            attrs['stdout'],
            attrs['width'],
            attrs['height'],
            attrs['duration'],
            attrs['command'],
            attrs['title']
        )
    except (OSError, urllib.error.HTTPError) as e:
        raise LoadError(str(e))
    except JSONDecodeError as e:
        raise LoadError('JSON decoding error: ' + str(e))
    except KeyError as e:
        raise LoadError('asciicast is missing key ' + str(e))