Source

pyyaml-legacy / patches / load.py.patch

Full commit
--- yaml/load.py	2002-12-26 08:38:51.000000000 -0800
+++ yaml/load.py	2003-10-02 15:53:06.000000000 -0700
@@ -45,10 +45,13 @@
             if ok:
                 return (1, result)
 
 def dumpDictionary(): return {}
 
+_STRIP = 1
+_KEEP = 2
+
 class Parser:
     def __init__(self, stream, typeResolver=None):
         try:
             self.dictionary = dict
         except:
@@ -167,19 +170,16 @@
         if alias:
             self.aliases[alias] = value
         return value          
 
     def parse_unaliased_value(self, value):
-        match = re.match(r"(!\S*)(.*)", value)
+        match = re.match(r"(!\S*) (.*)", value)
         if match:
             (url, value) = match.groups()
-            value = self.parse_untyped_value(value)
             if url[:2] == '!!':
                 return self.typeResolver.resolveType(value, url)
-            else:
-                # XXX - allows syntax, but ignores it
-                return value
+            return self.parse_untyped_value(value)
         return self.parse_untyped_value(value)
 
     def parseInlineArray(self, value):        
         if re.match("\s*\[", value):
             return self.parseInline([], value, ']', 
@@ -231,36 +231,54 @@
 
     def parseNative(self, value):
         return (1, convertImplicit(value))
 
     def parseMultiLineScalar(self, value):
+        # XXX does not handle indentation ex. >2, or |2
         if value == '>':
             return (1, self.parseFolded())
+        elif value == '>-':
+            return (1, self.parseFolded(_STRIP))
+        elif value == '>+':
+            return (1, self.parseFolded(_KEEP))
         elif value == '|':
-            return (1, joinLiteral(self.parseBlock()))
+            return (1, self.parseBlock())
+        elif value == '|-':
+            return (1, self.parseBlock(_STRIP))
         elif value == '|+':
-            return (1, joinLiteral(self.unprunedBlock()))
+            return (1, self.parseBlock(_KEEP))
 
-    def parseFolded(self):
-        data = self.parseBlock()
+    def parseFolded(self, chomping = 0):
+        data = self.unprunedBlock()
+        if chomping != _KEEP:
+            data = pruneTrailingEmpties(data)
         i = 0
         resultString = ''
         while i < len(data)-1:
-            resultString = resultString + data[i]
-            resultString = resultString + foldChar(data[i], data[i+1])
-            i = i + 1
-        return resultString + data[-1] + "\n"        
+            resultString += data[i]
+            resultString += foldChar(data[i], data[i+1])
+            i += 1
+        resultString += data[-1]
+        if chomping ==_STRIP:
+            return resultString
+        return resultString + "\n"
 
     def unprunedBlock(self):
         self.nestedDocs.nestToNextLine()
         data = []
         while self.nestPop():
             data.append(self.line)
         return data
 
-    def parseBlock(self):
-        return pruneTrailingEmpties(self.unprunedBlock())
+    def parseBlock(self, chomping = 0):
+        data = self.unprunedBlock()
+        if chomping != _KEEP:
+            data = pruneTrailingEmpties(data)
+        resultString = string.join(data, "\n")
+        if chomping == _STRIP:
+            return resultString
+        return resultString + "\n"
 
     def testForAlias(self, value):
         match = re.match("&(\S*)\s*(.*)", value)
         if match:
             return match.groups()