Changeset 74
- Timestamp:
- 07/08/04 15:35:32 (9 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 1 deleted
- 17 edited
-
CHANGELOG (modified) (1 diff)
-
Makefile (modified) (1 diff)
-
TestDumper.py (modified) (2 diffs)
-
TestFileNamesInErrors.py (added)
-
TestPluggableDictionary.py (modified) (1 diff)
-
TestYamlBasics.py (modified) (2 diffs)
-
TestingSuite/alias.yml (modified) (1 diff)
-
TestingSuite/error.yml (modified) (1 diff)
-
TestingSuite/ruby.yml (modified) (1 diff)
-
TestingSuite/spec.yml (modified) (2 diffs)
-
TestingSuite/ypath.yml (modified) (9 diffs)
-
YAML.vim (added)
-
YamlTest.py (modified) (2 diffs)
-
assets (added)
-
assets/pyyaml_banner.png (added)
-
build (deleted)
-
yaml/__init__.py (modified) (2 diffs)
-
yaml/dump.py (modified) (2 diffs)
-
yaml/implicit.py (modified) (1 diff)
-
yaml/load.py (modified) (6 diffs)
-
yaml/redump.py (modified) (1 diff)
-
yaml/stream.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/CHANGELOG
r71 r74 1 --- 2 - version: 0.32 3 date: 2002-12-26 4 changes: 5 - report filenames in loadFile exceptions 6 - added loadOrdered() method 7 --- 8 - version: 0.31 9 date: 2002-11-17 10 changes: 11 - dumper doesn't quote strings just because they have dashes 12 - dumper does quote strings that look like negative numbers 13 - dumper does quote strings w/*, &, and white space on edges 14 - dumper doesn't quote strings starting with "* " 15 - loader can tolerate "* " unquoted 16 - complain about duplicate keys in dictionary 17 - complain about trailing spaces 18 - l() and d() convenience methods 19 - applied Tim Hochberg's FLOAT/SCIENTIFIC patch 20 - sync __version__ to CHANGELOG 1 21 --- 2 22 - version: 0.30 -
trunk/Makefile
r71 r74 1 1 test: 2 python2.1 YamlTest.py 3 python2.1 TestYpath.py 4 python2.1 TestClasses.py 5 python YamlTest.py 6 python TestYpath.py 7 python TestClasses.py 2 @for n in YamlTest TestYpath TestClasses TestFileNamesInErrors; do \ 3 echo $$n.py; \ 4 python2.1 $$n.py; \ 5 python2.2 $$n.py; done 8 6 python TestPluggableDictionary.py 9 7 -
trunk/TestDumper.py
r71 r74 150 150 self.assertEquals(dump(5.2), "--- 5.2\n") 151 151 self.assertEquals(dump(1234), "--- 1234\n") 152 self.assertEquals(dump('harmless-dash'), "--- harmless-dash\n") 153 self.assertEquals(dump('* harmless bullet'), "--- * harmless bullet\n") 154 self.dumpTest( 155 [ "a - b", "another-harmless-dash" ], 156 """ 157 --- 158 - a - b 159 - another-harmless-dash 160 """) 152 161 # Single Quoted: 153 162 self.assertEquals(dump(''), "--- ''\n") … … 156 165 self.assertEquals(dump('4.3.'), "--- '4.3.'\n") 157 166 self.assertEquals(dump('12345'), "--- '12345'\n") 167 self.assertEquals(dump('-12345'), "--- '-12345'\n") 158 168 self.assertEquals(dump('key: value'), "--- 'key: value'\n") 159 self.assertEquals(dump('- pretend seq'), "--- '- pretend seq'\n")160 169 self.assertEquals(dump('ending colon:'), "--- 'ending colon:'\n") 161 170 self.assertEquals(dump('&foo'), "--- '&foo'\n") 171 self.assertEquals(dump(' xx'), "--- ' xx'\n") 172 self.assertEquals(dump('*bar'), "--- '*bar'\n") 162 173 assertEquals(dump('"middle \'quote'), '--- \'"middle \'\'quote\'\n') 163 174 # Double quoted: 164 175 self.assertEquals(dump("\thas a tab"), "--- \"\\thas a tab\"\n") 165 self.dumpTest(166 [ "a - b", "c" ],167 """168 ---169 - 'a - b'170 - c171 """)172 176 self.dumpTest( 173 177 { "key: quote": 'normal value' }, -
trunk/TestPluggableDictionary.py
r71 r74 19 19 """ 20 20 21 parser = yaml.Parser(yaml.StringStream(stream)) 22 parser.dictionary = OrderedDict 23 my_dict = parser.next() 21 my_dict = yaml.loadOrdered(stream).next() 24 22 assertEquals(my_dict.keys(), ['zzz', 'yyy', 'xxx', 'alpha']) 25 23 -
trunk/TestYamlBasics.py
r71 r74 2 2 from here import * 3 3 from test import assertEquals 4 from yaml.load import l 5 from yaml.dump import d 4 6 5 7 class Test(YamlTest.YamlTest): … … 153 155 ) 154 156 157 def testQuickInterfaces(self): 158 assertEquals(l("--- foo"), "foo") 159 assertEquals(d({'foo': 'bar'}), "---\nfoo: bar\n") 160 155 161 if __name__ == '__main__': 156 162 import unittest -
trunk/TestingSuite/alias.yml
r71 r74 50 50 hello 51 51 ] 52 52 --- 53 test: Liberal Asterisk Handling 54 brief: > 55 We need to allow strings to begin with asterisks. 56 yaml: | 57 - * Bulleted item 58 python: | 59 [ 60 [ '* Bulleted item' ] 61 ] -
trunk/TestingSuite/error.yml
r71 r74 28 28 near line 2: 29 29 firstline: 1 30 30 --- 31 test: Duplicate keys 32 brief: > 33 YAML should complain when you have duplicate 34 dictionary keys, rather than silently overwriting them. 35 yaml: | 36 foo: 1 37 foo: 2 38 error: 39 python: | 40 Duplicate key foo: 41 near line 2: 42 foo: 2 43 --- 44 test: Duplicate keys w/complex children 45 brief: > 46 same thing for complex keys 47 yaml: | 48 foo: 49 yo: 1 50 foo: 51 bar: 1 52 error: 53 python: | 54 Duplicate key foo: 55 near line 3: 56 foo: 57 --- 58 test: Complain about trailing spaces 59 brief: > 60 root of all evil 61 yaml: | 62 foo: bar 63 error: 64 python: | 65 Trailing spaces not allowed without quotes.: 66 near line 1: 67 foo: bar -
trunk/TestingSuite/ruby.yml
r71 r74 148 148 --- 149 149 test: Extending Kernel::Array 150 brief: > 150 brief: > 151 151 When extending the Array class, your instances 152 152 of such a class will dump as YAML sequences, -
trunk/TestingSuite/spec.yml
r71 r74 388 388 389 389 What a year! 390 ruby: | 390 ruby: | 391 391 "Sammy Sosa completed another fine season with great stats.\n\n 63 Home Runs\n 0.288 Batting Average\n\nWhat a year!\n" 392 392 python: | … … 544 544 false: - 545 545 string: '12345' 546 ruby: | 546 ruby: | 547 547 { 548 548 'null' => nil, -
trunk/TestingSuite/ypath.yml
r71 r74 32 32 carrot: orange 33 33 ypath: //. 34 expected: 34 expected: 35 35 - / 36 36 - /fruit … … 50 50 apple: red 51 51 ypath: /apple 52 expected: 52 expected: 53 53 - /apple 54 54 ----- … … 99 99 carrot: orange 100 100 ypath: /fruit/banana 101 expected: 101 expected: 102 102 - /fruit/banana 103 103 --- … … 119 119 - /names/0 120 120 --- 121 data: 121 data: 122 122 names: 123 123 - first: Clark … … 129 129 - /names/1/first 130 130 ---- 131 data: 131 data: 132 132 names: 133 133 - first: Clark … … 140 140 - /names/1/first 141 141 --- 142 data: 142 data: 143 143 names: 144 144 python-heads: … … 171 171 --- 172 172 data: 173 - one: 173 - one: 174 174 name: xxx 175 - two: 175 - two: 176 176 name: yyy 177 - three: 177 - three: 178 178 name: zzz 179 179 ypath: /*/one/name|//three/name … … 190 190 --- 191 191 data: 192 - one: 192 - one: 193 193 name: xxx 194 - two: 194 - two: 195 195 name: yyy 196 - three: 196 - three: 197 197 name: zzz 198 198 ypath: /*/(one|three)/name … … 210 210 - /2 211 211 --- 212 data: 212 data: 213 213 - food: Hamburger 214 214 calories: 900 -
trunk/YamlTest.py
r71 r74 98 98 99 99 100 def testVersion(): 101 from yaml import __version__ 102 assertEquals(__version__, str(yaml.loadFile('CHANGELOG').next()[0]['version'])) 100 103 101 104 if __name__ == '__main__': … … 113 116 unittest.TextTestRunner().run(ts) 114 117 yaml.dumpToFile(sys.stdout, {'TESTING dumpToFile': 'ok'}) 118 testVersion() -
trunk/yaml/__init__.py
r71 r74 1 __version__ = "0.25" 2 from load import loadFile 3 from load import load 4 from load import Parser 5 from dump import dump 6 from dump import dumpToFile 7 from dump import Dumper 1 __version__ = "0.32" 2 from load import loadFile, load, Parser, l 3 from dump import dump, dumpToFile, Dumper, d 8 4 from stream import YamlLoaderException, StringStream, FileStream 9 5 from timestamp import timestamp 6 import sys 7 if sys.hexversion >= 0x02020000: 8 from redump import loadOrdered 10 9 11 10 try: … … 15 14 raise NotImplementedError("ypath requires Python 2.2") 16 15 17 18 import sys 19 if sys.hexversion < 0x02010300: 20 raise 'YAML is not tested for pre-2.1.3 versions of Python' 16 if sys.hexversion < 0x02010000: 17 raise 'YAML is not tested for pre-2.1 versions of Python' -
trunk/yaml/dump.py
r71 r74 17 17 def dump(*data): 18 18 return Dumper().dump(*data) 19 20 def d(data): return dump(data) 19 21 20 22 def dumpToFile(file, *data): … … 257 259 258 260 def needsSingleQuote(data): 259 if re.match(r"^\d", data): 260 return 1 261 if data[0] == '&': 261 if re.match(r"^-?\d", data): 262 return 1 263 if re.match(r"\*\S", data): 264 return 1 265 if data[0] in ['&', ' ']: 262 266 return 1 263 267 if data[0] == '"': 264 268 return 1 265 return (re.search(r'[-:]', data) or re.search(r'(\d\.){2}', data)) 269 if data[-1] == ' ': 270 return 1 271 return (re.search(r'[:]', data) or re.search(r'(\d\.){2}', data)) 266 272 267 273 def hasSpecialChar(data): -
trunk/yaml/implicit.py
r71 r74 4 4 5 5 DATETIME_REGEX = re.compile("^[0-9]{4}-[0-9]{2}-[0-9]{2}$") 6 FLOAT_REGEX = re.compile("^[-+]?[0-9][0-9,]*\.[0-9 ,]*$")7 SCIENTIFIC_REGEX = re.compile("^[-+]?[0-9] [0-9,]*\.[0-9.]*[eE][-+][0-9]+$")6 FLOAT_REGEX = re.compile("^[-+]?[0-9][0-9,]*\.[0-9]*$") 7 SCIENTIFIC_REGEX = re.compile("^[-+]?[0-9]+(\.[0-9]*)?[eE][-+][0-9]+$") 8 8 OCTAL_REGEX = re.compile("^[-+]?([0][0-7,]*)$") 9 9 HEX_REGEX = re.compile("^[-+]?0x[0-9a-fA-F,]+$") -
trunk/yaml/load.py
r71 r74 3 3 from inline import InlineTokenizer 4 4 from yaml.klass import DefaultResolver 5 from yaml.stream import FileStream, StringStream, NestedDocs 6 7 PRIVATE_NOTICE = """ 8 This module is considered to be private implementation 9 details and is subject to change. Please only use the 10 objects and methods exported to the top level yaml package. 11 """ 5 from yaml.stream import YamlLoaderException, FileStream, StringStream, NestedDocs 12 6 13 7 try: … … 39 33 return loadStream(StringStream(str), typeResolver) 40 34 35 def l(str): return load(str).next() 36 41 37 def loadStream(stream, typeResolver): 42 38 return iter(Parser(stream, typeResolver)) … … 130 126 131 127 def parse_map_line_simple(self, items, line): 132 map_item = key_value(line)128 map_item = self.key_value(line) 133 129 if map_item: 134 130 (key, value) = map_item 135 131 key = convertImplicit(key) 132 if items.has_key(key): 133 self.error("Duplicate key "+key) 136 134 items[key] = self.parse_value(value) 137 135 else: … … 197 195 198 196 def parseInlineHashItem(self, result, token): 199 (key, value) = key_value(token)197 (key, value) = self.key_value(token) 200 198 result[key] = value 201 199 … … 270 268 271 269 def testForRepeatOfAlias(self, value): 272 match = re.match("\*(\S *)", value)270 match = re.match("\*(\S+)", value) 273 271 if match: 274 272 alias = match.groups()[0] … … 279 277 return (None, value) 280 278 279 def key_value(self, str): 280 if str[-1] == ' ': 281 self.error("Trailing spaces not allowed without quotes.") 282 # XXX This allows mis-balanced " vs. ' stuff 283 match = re.match("[\"'](.+)[\"']\s*:\s*(.*)", str) 284 if match: 285 (key, value) = match.groups() 286 return (key, value) 287 match = re.match("(.+?)\s*:\s*(.*)", str) 288 if match: 289 (key, value) = match.groups() 290 if len(value) and value[0] == '#': 291 value = '' 292 return (key, value) 293 281 294 def getToken(regex, value): 282 295 match = re.search(regex, value) 283 296 if match: 284 297 return match.groups()[0] 285 286 def key_value(str):287 # XXX This allows mis-balanced " vs. ' stuff288 match = re.match("[\"'](.+)[\"']\s*:\s*(.*)", str)289 if match:290 (key, value) = match.groups()291 return (key, value)292 293 match = re.match("(.+?)\s*:\s*(.*)", str)294 if match:295 (key, value) = match.groups()296 if len(value) and value[0] == '#':297 value = ''298 return (key, value)299 298 300 299 def pruneTrailingEmpties(data): -
trunk/yaml/redump.py
r71 r74 2 2 from yaml import Parser, Dumper, StringStream 3 3 4 def redump(stream):4 def loadOrdered(stream): 5 5 parser = Parser(StringStream(stream)) 6 6 parser.dictionary = OrderedDict 7 docs = list(iter(parser)) 7 return iter(parser) 8 9 def redump(stream): 10 docs = list(loadOrdered(stream)) 8 11 dumper = Dumper() 9 12 dumper.alphaSort = 0 -
trunk/yaml/stream.py
r71 r74 9 9 10 10 class LineNumberStream: 11 def __init__(self ):11 def __init__(self, filename=None): 12 12 self.curLine = 0 13 self.filename = filename 13 14 14 15 def get(self): … … 25 26 def __init__(self, filename): 26 27 self.fp = open(filename) 27 LineNumberStream.__init__(self )28 LineNumberStream.__init__(self, filename) 28 29 29 30 def getLine(self): … … 142 143 class YamlLoaderException(Exception): 143 144 def __init__(self, *args): 144 (self.msg, self.lineNum, self.line ) = args145 (self.msg, self.lineNum, self.line, self.filename) = args 145 146 146 147 def __str__(self): 147 return "%s:\n" "near line %d:\n" "%s\n" % \ 148 (self.msg, self.lineNum, self.line) 149 148 msg = """\ 149 %(msg)s: 150 near line %(lineNum)d: 151 %(line)s 152 """ % self.__dict__ 153 if self.filename: 154 msg += "file: " + self.filename 155 return msg 150 156 151 157 class NestedDocs(NestedText): 152 158 def __init__(self, stream): 159 self.filename = stream.filename 153 160 NestedText.__init__(self,stream) 154 161 line = NestedText.peek(self) … … 179 186 180 187 def error(self, msg, line): 181 raise YamlLoaderException(msg, self.lastLineRead(), line )188 raise YamlLoaderException(msg, self.lastLineRead(), line, self.filename) 182 189 183 190 def noLineFeed(s):
Note: See TracChangeset
for help on using the changeset viewer.
