Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: python YAML output, perl Loader, which version?

by stonecolddevin (Vicar)
on Apr 16, 2014 at 17:42 UTC ( #1082542=note: print w/ replies, xml ) Need Help??


in reply to python YAML output, perl Loader, which version?

It would be super helpful if we could see an example of the YAML being generated. YAML is YAML, if it's adhering to the YAML standard, there's no reason it can't be parsed by *any* YAML parser that also adheres to said standard.

Three thousand years of beautiful tradition, from Moses to Sandy Koufax, you're god damn right I'm living in the fucking past


Comment on Re: python YAML output, perl Loader, which version?
Re^2: python YAML output, perl Loader, which version?
by mgwmgw (Acolyte) on Apr 16, 2014 at 21:53 UTC

    Here is an example of a string I created in perl that reproduces one of the problems:

    $out = "Things:\n - Name: thing_1\n Sub:\n key1: value1\n + key2: very very very very very very very very very very very very + very very\n long line wrapped value2\nkey3: value3\n";

    When it prints out in the log, it looks like this:

    Things: - Name: thing_1 Sub: key1: value1 key2: very very very very very very very very very very very ver +y very very long line wrapped value2 key3: value3

    If I paste this into yamlint it is valid, but the Loader complains:

    YAML Error: Inconsistent indentation level
      How did you create the string? Why is your indentation level inconsistent? Perl module YAML also complains
      YAML Error: Inconsistent indentation level Code: YAML_PARSE_ERR_INCONSISTENT_INDENTATION Line: 6 Document: 1

        Let me explain again: I am testing product code that is being written in python. The product outputs what it outputs, WITH the inconsistent indentation, and I do not control that. The String is to show the nature of the problem without having to discuss details of the product, which do not matter for this problem and solution. Because the YAML output is considered to be valid by yamlint, the people writing the product code do not consider their code to be broken. I need to write perl tests which extract data from the output, in order to make sure that the content of the output is correct. In order to do this, I need to parse the output WITH the inconsistent indentation, which yamlint can do. The YAML Loader in perl's YAML::Old cannot parse the output and considers the output to be invalid. I strongly suspect that some newer YAML Loaders for perl would parse the output just fine, but there are so many newer YAML Loaders, and I am not sure which are fully working and finished.

        I guess I could blindly try whatever YAML Loaders for perl I can find until one of them works on this peculiarity, but since I expect to need to parse other YAML for these tests, with other peculiarities, I would rather choose the YAML Loader which is in the best shape, which I suspect means the Loader which is most compatible with the most recent or inclusive YAML spec.

        So, which Loader do I want?

        Am I making the problem clear yet?

        As to why the python behaves as it does, I suspect that this has to do with how PyYAML works.

      You want this?

      #!/usr/bin/perl -- use strict; use warnings; use YAML qw/ Load Dump /; use Data::Dump qw/ dd /; my $it = { Things => [ { Name => "thing_1", Sub => { key1 => "value1", key2 => "very very very very very very very very very +very very very very very long line\nwrapped value2", key3 => "value3", }, }, ], }; dd( Dump( $it ) ); print Dump( $it ), "\n"; __END__ "---\nThings:\n - Name: thing_1\n Sub:\n key1: value1\n +key2: |-\n very very very very very very very very very very v +ery very very very long line\n wrapped value2\n key3: val +ue3\n" --- Things: - Name: thing_1 Sub: key1: value1 key2: |- very very very very very very very very very very very very ve +ry very long line wrapped value2 key3: value3

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1082542]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (11)
As of 2014-09-23 22:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (241 votes), past polls