How to use the jsbeautifier.jsbeautifier.__init__.MissingInputStreamError function in jsbeautifier

To help you get started, we’ve selected a few jsbeautifier 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 Masood-M / yalih / jsbeautifier / jsbeautifier / __init__.py View on Github external
def beautify_file(file_name, opts=default_options()):
    input_string = ''
    if file_name == '-':  # stdin
        if sys.stdin.isatty():
            raise MissingInputStreamError()

        stream = sys.stdin
        if platform.platform().lower().startswith('windows'):
            if sys.version_info.major >= 3:
                # for python 3 on windows this prevents conversion
                stream = io.TextIOWrapper(sys.stdin.buffer, newline='')
            elif platform.architecture()[0] == '32bit':
                # for python 2 x86 on windows this prevents conversion
                import msvcrt
                msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
            else:
                raise 'Pipe to stdin not supported on Windows with Python 2.x 64-bit.'

        input_string = stream.read()

        # if you pipe an empty string, that is a failure
github Masood-M / yalih / jsbeautifier / jsbeautifier / __init__.py View on Github external
# set newline to empty to prevent this
                    with io.open(outfile, 'wt', newline='') as f:
                        print('beautified ' + outfile, file=sys.stdout)
                        try:
                            f.write(pretty)
                        except TypeError:
                            # This is not pretty, but given how we did the version import
                            # it is the only way to do this without having setup.py
                            # fail on a missing six dependency.
                            six = __import__("six")
                            f.write(six.u(pretty))
                else:
                    print('beautified ' + outfile + ' - unchanged', file=sys.stdout)


    except MissingInputStreamError:
        print(
            "Must pipe input or define at least one file.\n",
            file=sys.stderr)
        usage(sys.stderr)
        return 1

    except UnicodeError as ex:
        print("Error while decoding input or encoding output:",
            file=sys.stderr)
        print(ex, file=sys.stderr)
        return 1

    except Exception as ex:
        print(ex, file=sys.stderr)
        return 1
github Masood-M / yalih / jsbeautifier / jsbeautifier / __init__.py View on Github external
if platform.platform().lower().startswith('windows'):
            if sys.version_info.major >= 3:
                # for python 3 on windows this prevents conversion
                stream = io.TextIOWrapper(sys.stdin.buffer, newline='')
            elif platform.architecture()[0] == '32bit':
                # for python 2 x86 on windows this prevents conversion
                import msvcrt
                msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
            else:
                raise 'Pipe to stdin not supported on Windows with Python 2.x 64-bit.'

        input_string = stream.read()

        # if you pipe an empty string, that is a failure
        if input_string == '':
            raise MissingInputStreamError()
    else:
        stream = io.open(file_name, 'rt', newline='')
        input_string = stream.read()

    return beautify(input_string, opts)