Example #1
0
def test_emitter_styles(data_filename, canonical_filename, verbose=False):
    for filename in [data_filename, canonical_filename]:
        with open(filename, 'rb') as fp0:
            events = list(yaml.parse(fp0))
        for flow_style in [False, True]:
            for style in ['|', '>', '"', "'", ""]:
                styled_events = []
                for event in events:
                    if isinstance(event, yaml.ScalarEvent):
                        event = yaml.ScalarEvent(
                            event.anchor, event.tag, event.implicit, event.value, style=style
                        )
                    elif isinstance(event, yaml.SequenceStartEvent):
                        event = yaml.SequenceStartEvent(
                            event.anchor, event.tag, event.implicit, flow_style=flow_style
                        )
                    elif isinstance(event, yaml.MappingStartEvent):
                        event = yaml.MappingStartEvent(
                            event.anchor, event.tag, event.implicit, flow_style=flow_style
                        )
                    styled_events.append(event)
                output = yaml.emit(styled_events)
                if verbose:
                    print(
                        'OUTPUT (filename=%r, flow_style=%r, style=%r)'
                        % (filename, flow_style, style)
                    )
                    print(output)
                new_events = list(yaml.parse(output))
                _compare_events(events, new_events)
Example #2
0
def test_emitter_on_data(data_filename, canonical_filename, verbose=False):
    with open(data_filename, 'rb') as fp0:
        events = list(yaml.parse(fp0))
    output = yaml.emit(events)
    if verbose:
        print('OUTPUT:')
        print(output)
    new_events = list(yaml.parse(output))
    _compare_events(events, new_events)
Example #3
0
def test_emitter_on_canonical(canonical_filename, verbose=False):
    with open(canonical_filename, 'rb') as fp0:
        events = list(yaml.parse(fp0))
    for canonical in [False, True]:
        output = yaml.emit(events, canonical=canonical)
        if verbose:
            print('OUTPUT (canonical=%s):' % canonical)
            print(output)
        new_events = list(yaml.parse(output))
        _compare_events(events, new_events)
Example #4
0
def test_emitter_events(events_filename, verbose=False):
    with open(events_filename, 'rb') as fp0:
        events = list(yaml.load(fp0, Loader=EventsLoader))
    output = yaml.emit(events)
    if verbose:
        print('OUTPUT:')
        print(output)
    new_events = list(yaml.parse(output))
    _compare_events(events, new_events)
Example #5
0
def test_unicode_transfer(unicode_filename, verbose=False):
    with open(unicode_filename, 'rb') as fp:
        data = fp.read().decode('utf-8')
    for encoding in [None, 'utf-8', 'utf-16-be', 'utf-16-le']:
        input = data
        if PY3:
            if encoding is not None:
                input = ('\ufeff' + input).encode(encoding)
            output1 = yaml.emit(yaml.parse(input), allow_unicode=True)
            if encoding is None:
                stream = StringIO()
            else:
                stream = BytesIO()
            yaml.emit(yaml.parse(input), stream, allow_unicode=True)
            output2 = stream.getvalue()
            assert isinstance(output1, str), (type(output1), encoding)
            if encoding is None:
                assert isinstance(output2, str), (type(output1), encoding)
            else:
                assert isinstance(output2, bytes), (type(output1), encoding)
                output2.decode(encoding)
        else:
            if encoding is not None:
                input = (u'\ufeff' + input).encode(encoding)
            output1 = yaml.emit(yaml.parse(input), allow_unicode=True)
            stream = StringIO()
            yaml.emit(yaml.parse(input),
                      _unicode_open(stream, 'utf-8'),
                      allow_unicode=True)
            output2 = stream.getvalue()
            if encoding is None:
                assert isinstance(output1,
                                  unicode), (type(output1), encoding)  # NOQA
            else:
                assert isinstance(output1, str), (type(output1), encoding)
                output1.decode(encoding)
            assert isinstance(output2, str), (type(output2), encoding)
            output2.decode('utf-8')
def _parse_unsafe(*args: Any, **kwargs: Any) -> None:
    _exhaust(yaml.parse(*args, **kwargs))
Example #7
0
def _parse_unsafe(*args, **kwargs):  # type: (*Any, **Any) -> None
    _exhaust(yaml.parse(*args, **kwargs))
Example #8
0
def _parse_unsafe(*args, **kwargs):  # type: (*Any, **Any) -> None
    _exhaust(yaml.parse(*args, **kwargs))
Example #9
0
def _parse_unsafe(*args, **kwargs):
    _exhaust(yaml.parse(*args, **kwargs))