Merge lp:~javier.collado/utah/bug1071265 into lp:utah

Proposed by Javier Collado
Status: Merged
Approved by: Javier Collado
Approved revision: 722
Merged at revision: 723
Proposed branch: lp:~javier.collado/utah/bug1071265
Merge into: lp:utah
Diff against target: 15 lines (+4/-1)
1 file modified
utah/client/result.py (+4/-1)
To merge this branch: bzr merge lp:~javier.collado/utah/bug1071265
Reviewer Review Type Date Requested Status
Joe Talbott (community) Approve
Review via email: mp+131379@code.launchpad.net

Description of the change

Literal strings don't serialize as such in yaml if they have some trailing
whitespace before the newline character.

This change removes the whitespace on every line to serialize literal strings properly.

To post a comment you must log in.
Revision history for this message
Joe Talbott (joetalbott) wrote :

Nice debugging.

Should we file a bug upstream for this. This seems non-intuitive to me but perhaps yaml doesn't allow trailing whitespace on lines.

review: Approve
Revision history for this message
Javier Collado (javier.collado) wrote :

The specification for literal blocks:
http://www.yaml.org/spec/1.2/spec.html#id2795688

seems to allow whitespace characters (nb-chars+).

In fact, I've seen that trying to `load` a yaml stream that contains
a literal with whitespace before a newline character works fine
(and doesn't remove the whitespace).

Anyway, looking at pyyaml.org, I've seen that the bug is already reported:
http://pyyaml.org/ticket/240

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utah/client/result.py'
2--- utah/client/result.py 2012-10-11 15:29:50 +0000
3+++ utah/client/result.py 2012-10-25 11:15:28 +0000
4@@ -205,7 +205,10 @@
5 Transform long strings into literal blocks
6 """
7 if isinstance(data, str) and '\n' in data:
8- return LiteralString(data)
9+ # Remove trailing whitespace to serialize in yaml
10+ # as a literal string
11+ lines = [line.rstrip() for line in data.splitlines()]
12+ return LiteralString('\n'.join(lines))
13
14 if isinstance(data, dict):
15 for key, value in data.iteritems():

Subscribers

People subscribed via source and target branches