Changeset 74


Ignore:
Timestamp:
07/08/04 15:35:32 (9 years ago)
Author:
tim
Message:

removed unwanted build

Location:
trunk
Files:
4 added
1 deleted
17 edited

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 
    121--- 
    222- version: 0.30 
  • trunk/Makefile

    r71 r74  
    11test: 
    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 
    86        python TestPluggableDictionary.py 
    97 
  • trunk/TestDumper.py

    r71 r74  
    150150        self.assertEquals(dump(5.2), "--- 5.2\n") 
    151151        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            """) 
    152161        # Single Quoted: 
    153162        self.assertEquals(dump(''), "--- ''\n") 
     
    156165        self.assertEquals(dump('4.3.'), "--- '4.3.'\n") 
    157166        self.assertEquals(dump('12345'), "--- '12345'\n") 
     167        self.assertEquals(dump('-12345'), "--- '-12345'\n") 
    158168        self.assertEquals(dump('key: value'), "--- 'key: value'\n") 
    159         self.assertEquals(dump('- pretend seq'), "--- '- pretend seq'\n") 
    160169        self.assertEquals(dump('ending colon:'), "--- 'ending colon:'\n") 
    161170        self.assertEquals(dump('&foo'), "--- '&foo'\n") 
     171        self.assertEquals(dump(' xx'), "--- ' xx'\n") 
     172        self.assertEquals(dump('*bar'), "--- '*bar'\n") 
    162173        assertEquals(dump('"middle \'quote'), '--- \'"middle \'\'quote\'\n') 
    163174        # Double quoted: 
    164175        self.assertEquals(dump("\thas a tab"), "--- \"\\thas a tab\"\n") 
    165         self.dumpTest( 
    166             [ "a - b", "c" ], 
    167             """ 
    168             --- 
    169             - 'a - b' 
    170             - c 
    171             """) 
    172176        self.dumpTest( 
    173177            { "key: quote": 'normal value' }, 
  • trunk/TestPluggableDictionary.py

    r71 r74  
    1919""" 
    2020 
    21 parser = yaml.Parser(yaml.StringStream(stream)) 
    22 parser.dictionary = OrderedDict 
    23 my_dict = parser.next() 
     21my_dict = yaml.loadOrdered(stream).next() 
    2422assertEquals(my_dict.keys(), ['zzz', 'yyy', 'xxx', 'alpha']) 
    2523 
  • trunk/TestYamlBasics.py

    r71 r74  
    22from here import * 
    33from test import assertEquals 
     4from yaml.load import l 
     5from yaml.dump import d 
    46 
    57class Test(YamlTest.YamlTest): 
     
    153155        ) 
    154156 
     157    def testQuickInterfaces(self): 
     158        assertEquals(l("--- foo"), "foo") 
     159        assertEquals(d({'foo': 'bar'}), "---\nfoo: bar\n") 
     160 
    155161if __name__ == '__main__': 
    156162    import unittest 
  • trunk/TestingSuite/alias.yml

    r71 r74  
    5050      hello 
    5151    ] 
    52  
     52--- 
     53test: Liberal Asterisk Handling 
     54brief: > 
     55    We need to allow strings to begin with asterisks. 
     56yaml: | 
     57    - * Bulleted item 
     58python: | 
     59    [ 
     60        [ '* Bulleted item' ] 
     61    ] 
  • trunk/TestingSuite/error.yml

    r71 r74  
    2828        near line 2: 
    2929        firstline: 1 
    30  
     30--- 
     31test: Duplicate keys 
     32brief: > 
     33    YAML should complain when you have duplicate 
     34    dictionary keys, rather than silently overwriting them. 
     35yaml: | 
     36    foo: 1 
     37    foo: 2 
     38error: 
     39    python: | 
     40        Duplicate key foo: 
     41        near line 2: 
     42        foo: 2 
     43--- 
     44test: Duplicate keys w/complex children 
     45brief: > 
     46    same thing for complex keys 
     47yaml: | 
     48    foo: 
     49        yo: 1 
     50    foo: 
     51        bar: 1 
     52error: 
     53    python: | 
     54        Duplicate key foo: 
     55        near line 3: 
     56        foo: 
     57--- 
     58test: Complain about trailing spaces 
     59brief: > 
     60    root of all evil 
     61yaml: | 
     62    foo: bar  
     63error: 
     64    python: | 
     65        Trailing spaces not allowed without quotes.: 
     66        near line 1: 
     67        foo: bar  
  • trunk/TestingSuite/ruby.yml

    r71 r74  
    148148--- 
    149149test: Extending Kernel::Array 
    150 brief: >  
     150brief: > 
    151151    When extending the Array class, your instances 
    152152    of such a class will dump as YAML sequences, 
  • trunk/TestingSuite/spec.yml

    r71 r74  
    388388   
    389389   What a year! 
    390 ruby: |  
     390ruby: | 
    391391  "Sammy Sosa completed another fine season with great stats.\n\n  63 Home Runs\n  0.288 Batting Average\n\nWhat a year!\n" 
    392392python: | 
     
    544544  false: - 
    545545  string: '12345' 
    546 ruby: |  
     546ruby: | 
    547547  {  
    548548    'null' => nil,  
  • trunk/TestingSuite/ypath.yml

    r71 r74  
    3232    carrot: orange 
    3333ypath: //. 
    34 expected:   
     34expected: 
    3535  - / 
    3636  - /fruit 
     
    5050  apple: red 
    5151ypath: /apple 
    52 expected:  
     52expected: 
    5353 - /apple 
    5454----- 
     
    9999    carrot: orange 
    100100ypath: /fruit/banana 
    101 expected:  
     101expected: 
    102102 - /fruit/banana 
    103103--- 
     
    119119 - /names/0 
    120120--- 
    121 data:  
     121data: 
    122122  names: 
    123123    - first: Clark 
     
    129129  - /names/1/first 
    130130---- 
    131 data:  
     131data: 
    132132  names: 
    133133    - first: Clark 
     
    140140  - /names/1/first 
    141141--- 
    142 data:  
     142data: 
    143143  names: 
    144144    python-heads: 
     
    171171--- 
    172172data: 
    173   - one:  
     173  - one: 
    174174      name: xxx 
    175   - two:  
     175  - two: 
    176176      name: yyy 
    177   - three:  
     177  - three: 
    178178      name: zzz 
    179179ypath: /*/one/name|//three/name 
     
    190190--- 
    191191data: 
    192   - one:  
     192  - one: 
    193193      name: xxx 
    194   - two:  
     194  - two: 
    195195      name: yyy 
    196   - three:  
     196  - three: 
    197197      name: zzz 
    198198ypath: /*/(one|three)/name 
     
    210210  - /2 
    211211--- 
    212 data:  
     212data: 
    213213 - food: Hamburger 
    214214   calories: 900 
  • trunk/YamlTest.py

    r71 r74  
    9898 
    9999 
     100def testVersion(): 
     101    from yaml import __version__ 
     102    assertEquals(__version__, str(yaml.loadFile('CHANGELOG').next()[0]['version'])) 
    100103 
    101104if __name__ == '__main__': 
     
    113116    unittest.TextTestRunner().run(ts) 
    114117    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" 
     2from load import loadFile, load, Parser, l 
     3from dump import dump, dumpToFile, Dumper, d 
    84from stream import YamlLoaderException, StringStream, FileStream 
    95from timestamp import timestamp 
     6import sys 
     7if sys.hexversion >= 0x02020000: 
     8    from redump import loadOrdered 
    109 
    1110try: 
     
    1514        raise NotImplementedError("ypath requires Python 2.2") 
    1615 
    17  
    18 import sys 
    19 if sys.hexversion < 0x02010300: 
    20     raise 'YAML is not tested for pre-2.1.3 versions of Python' 
     16if sys.hexversion < 0x02010000: 
     17    raise 'YAML is not tested for pre-2.1 versions of Python' 
  • trunk/yaml/dump.py

    r71 r74  
    1717def dump(*data): 
    1818    return Dumper().dump(*data) 
     19 
     20def d(data): return dump(data) 
    1921 
    2022def dumpToFile(file, *data): 
     
    257259 
    258260def 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 ['&', ' ']: 
    262266        return 1 
    263267    if data[0] == '"': 
    264268        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)) 
    266272 
    267273def hasSpecialChar(data): 
  • trunk/yaml/implicit.py

    r71 r74  
    44 
    55DATETIME_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]+$") 
     6FLOAT_REGEX      = re.compile("^[-+]?[0-9][0-9,]*\.[0-9]*$") 
     7SCIENTIFIC_REGEX = re.compile("^[-+]?[0-9]+(\.[0-9]*)?[eE][-+][0-9]+$") 
    88OCTAL_REGEX      = re.compile("^[-+]?([0][0-7,]*)$") 
    99HEX_REGEX        = re.compile("^[-+]?0x[0-9a-fA-F,]+$") 
  • trunk/yaml/load.py

    r71 r74  
    33from inline import InlineTokenizer 
    44from 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 """ 
     5from yaml.stream import YamlLoaderException, FileStream, StringStream, NestedDocs 
    126 
    137try: 
     
    3933    return loadStream(StringStream(str), typeResolver) 
    4034 
     35def l(str): return load(str).next() 
     36 
    4137def loadStream(stream, typeResolver): 
    4238    return iter(Parser(stream, typeResolver)) 
     
    130126 
    131127    def parse_map_line_simple(self, items, line): 
    132         map_item = key_value(line) 
     128        map_item = self.key_value(line) 
    133129        if map_item: 
    134130            (key, value) = map_item 
    135131            key = convertImplicit(key) 
     132            if items.has_key(key): 
     133                self.error("Duplicate key "+key) 
    136134            items[key] = self.parse_value(value) 
    137135        else: 
     
    197195 
    198196    def parseInlineHashItem(self, result, token): 
    199         (key, value) = key_value(token) 
     197        (key, value) = self.key_value(token) 
    200198        result[key] = value 
    201199 
     
    270268 
    271269    def testForRepeatOfAlias(self, value): 
    272         match = re.match("\*(\S*)", value) 
     270        match = re.match("\*(\S+)", value) 
    273271        if match: 
    274272            alias = match.groups()[0] 
     
    279277        return (None, value) 
    280278 
     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 
    281294def getToken(regex, value): 
    282295    match = re.search(regex, value) 
    283296    if match: 
    284297        return match.groups()[0] 
    285  
    286 def key_value(str): 
    287     # XXX This allows mis-balanced " vs. ' stuff 
    288     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) 
    299298 
    300299def pruneTrailingEmpties(data): 
  • trunk/yaml/redump.py

    r71 r74  
    22from yaml import Parser, Dumper, StringStream 
    33 
    4 def redump(stream): 
     4def loadOrdered(stream): 
    55    parser = Parser(StringStream(stream)) 
    66    parser.dictionary = OrderedDict 
    7     docs = list(iter(parser)) 
     7    return iter(parser) 
     8 
     9def redump(stream): 
     10    docs = list(loadOrdered(stream)) 
    811    dumper = Dumper() 
    912    dumper.alphaSort = 0 
  • trunk/yaml/stream.py

    r71 r74  
    99 
    1010class LineNumberStream: 
    11     def __init__(self): 
     11    def __init__(self, filename=None): 
    1212        self.curLine = 0 
     13        self.filename = filename 
    1314 
    1415    def get(self): 
     
    2526    def __init__(self, filename): 
    2627        self.fp = open(filename) 
    27         LineNumberStream.__init__(self) 
     28        LineNumberStream.__init__(self, filename) 
    2829 
    2930    def getLine(self): 
     
    142143class YamlLoaderException(Exception): 
    143144    def __init__(self, *args): 
    144         (self.msg, self.lineNum, self.line) = args 
     145        (self.msg, self.lineNum, self.line, self.filename) = args 
    145146 
    146147    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: 
     150near line %(lineNum)d: 
     151%(line)s 
     152""" % self.__dict__ 
     153        if self.filename: 
     154            msg += "file: " + self.filename 
     155        return msg 
    150156 
    151157class NestedDocs(NestedText): 
    152158    def __init__(self, stream): 
     159        self.filename = stream.filename 
    153160        NestedText.__init__(self,stream) 
    154161        line = NestedText.peek(self) 
     
    179186 
    180187    def error(self, msg, line): 
    181         raise YamlLoaderException(msg, self.lastLineRead(), line) 
     188        raise YamlLoaderException(msg, self.lastLineRead(), line, self.filename) 
    182189 
    183190def noLineFeed(s): 
Note: See TracChangeset for help on using the changeset viewer.