Ticket #64 (closed task: fixed)

Opened 1 year ago

Last modified 1 year ago

yaml.dump and indentation:

Reported by: lal.george@lehman.com Assigned to: xi
Priority: low Component: pyyaml
Severity: normal Keywords:
Cc:

Description

In python, when I have :


y = {'x' : 3, z : [{'val' : 3}, {'val' : 4}]} yaml.dump(y, default_flow_style=False)


The result is: 'x: 3\nz:\n- val: 3\n- val: 4\n'

I believe there should be a space before each hypen.

Best,

Lal

Attachments

Change History

09/27/07 06:33:11 changed by xi

  • status changed from new to closed.
  • resolution set to invalid.

The output is correct, see the production l-block-seq-entry(n,c) and Example 10.4:

http://yaml.org/spec/cvs/current.html#l-block-seq-entry(n,c)

09/27/07 08:12:21 changed by lageorge@lehman.com

  • status changed from closed to reopened.
  • resolution deleted.

Unfortunately, I don't understand the notation very well; but l-block-seq-entry(n,c) ::= s-indent(seq-spaces(n,c)) "-" ...

Since a new block is being started, won't there be an s-indent?

Best,

Lal

p.s. The java version of yaml does not like the dump produced by PyYaml?.

09/27/07 09:56:34 changed by xi

  • status changed from reopened to closed.
  • resolution set to invalid.

Read the next paragraph after the production:

People read the “-” character as part of the indentation. Hence, block sequence entries require one less space of indentation, unless the block sequence is nested within another block sequence (hence the need for the block-in context and block-out context).

See also the example in the specification:

block:
- one
-
·- two

P.S. The YAML loader in Java must be broken then.

09/27/07 10:50:08 changed by anonymous

  • priority changed from highest to low.
  • status changed from closed to reopened.
  • resolution deleted.
  • type changed from defect to task.

Thanks for the quick response ...

I believe you and PyYaml? are correct. The Java implementation is returning null for z in:

'x: 3\nz:\n- val: 3\n- val: 4\n'

Do you know a work around I could use? Perhaps I could turn this feature off, by always having PyYaml? emit " -" wherever it emits "-".

Thanks for your help.

Best,

Lal

09/27/07 11:53:09 changed by xi

  • status changed from reopened to closed.
  • resolution set to fixed.

You can use the following code:

import yaml

class MyDumper(yaml.Dumper):

    def increase_indent(self, flow=False, indentless=False):
        return super(MyDumper, self).increase_indent(flow, False)

y = {'x' : 3, 'z' : [{'val' : 3}, {'val' : 4}]}

print yaml.dump(y, Dumper=MyDumper, default_flow_style=False)

Add/Change #64 (yaml.dump and indentation:)




Change Properties
Action