Changeset 25
- Timestamp:
- 08/25/05 01:30:06 (8 years ago)
- Location:
- trunk
- Files:
-
- 7 edited
- 2 copied
-
ext/_syckmodule.c (modified) (15 diffs)
-
lib/syck/__init__.py (modified) (1 diff)
-
lib/syck/dumpers.py (modified) (14 diffs)
-
lib/syck/loaders.py (modified) (8 diffs)
-
sandbox/emit-it/Makefile (modified) (1 diff)
-
sandbox/emit-it/complex-key-bug.c (copied) (copied from trunk/sandbox/emit-it/emit-it.c) (3 diffs)
-
sandbox/emit-it/emit-it.c (modified) (4 diffs)
-
sandbox/emit-it/trailing-space-bug.c (copied) (copied from trunk/sandbox/emit-it/emit-it.c) (3 diffs)
-
tests/test_pickle.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/ext/_syckmodule.c
r20 r25 43 43 PyDoc_STRVAR(PySyckNode_doc, 44 44 "_syck.Node() -> TypeError\n\n" 45 "_syck.Node is an abstract type. It is abase type for _syck.Scalar,\n"45 "_syck.Node is an abstract type. It is the base type for _syck.Scalar,\n" 46 46 "_syck.Seq, and _syck.Map. You cannot create an instance of _syck.Node\n" 47 47 "directly. You may use _syck.Node for type checking or subclassing.\n"); … … 220 220 " -> a Scalar node\n\n" 221 221 "_syck.Scalar represents a scalar node in Syck parser and emitter\n" 222 " graphs. A scalar node points to a single string value.\n");222 "trees. A scalar node points to a single string value.\n"); 223 223 224 224 typedef struct { … … 549 549 "Seq(value=[], tag=None, inline=False) -> a Seq node\n\n" 550 550 "_syck.Seq represents a sequence node in Syck parser and emitter\n" 551 " graphs. A sequence node points to an ordered set of subnodes.\n");551 "trees. A sequence node points to an ordered set of subnodes.\n"); 552 552 553 553 typedef struct { … … 718 718 719 719 PyDoc_STRVAR(PySyckMap_doc, 720 "Map(value= '', tag=None, inline=False) -> a Map node\n\n"720 "Map(value={}, tag=None, inline=False) -> a Map node\n\n" 721 721 "_syck.Map represents a mapping node in Syck parser and emitter\n" 722 " graphs. A mapping node points to an unordered collections of pairs.\n");722 "trees. A mapping node points to an unordered collections of pairs.\n"); 723 723 724 724 typedef struct { … … 833 833 PyDoc_STR("the node kind, always 'map', read-only"), &PySyck_MapKind}, 834 834 {"value", (getter)PySyckNode_getvalue, (setter)PySyckMap_setvalue, 835 PyDoc_STR("the node value, a mapping"), NULL},835 PyDoc_STR("the node value, a list of pairs or a dictionary"), NULL}, 836 836 {"tag", (getter)PySyckNode_gettag, (setter)PySyckNode_settag, 837 837 PyDoc_STR("the node tag, a string or None"), NULL}, … … 893 893 " -> a Parser object\n\n" 894 894 "_syck.Parser is a low-lever wrapper of the Syck parser. It parses\n" 895 "a YAML stream and produces a graphof Nodes.\n");895 "a YAML stream and produces a tree of Nodes.\n"); 896 896 897 897 typedef struct { … … 1017 1017 static PyGetSetDef PySyckParser_getsetters[] = { 1018 1018 {"source", (getter)PySyckParser_getsource, NULL, 1019 PyDoc_STR("IO source, a string or file-like object"), NULL},1019 PyDoc_STR("IO source, a string or a file-like object"), NULL}, 1020 1020 {"implicit_typing", (getter)PySyckParser_getimplicit_typing, NULL, 1021 1021 PyDoc_STR("implicit typing of builtin YAML types"), NULL}, … … 1253 1253 1254 1254 if (self->parsing) { 1255 PyErr_SetString(PyExc_RuntimeError, "do not call Parser.parse while it is already parsing"); 1255 PyErr_SetString(PyExc_RuntimeError, 1256 "do not call Parser.parse while it is already running"); 1256 1257 return NULL; 1257 1258 } … … 1292 1293 PyDoc_STRVAR(PySyckParser_parse_doc, 1293 1294 "parse() -> the root Node object\n\n" 1294 "Parses the source and returns the next document. On EOF, returns None\n" 1295 "and sets the 'eof' attribute on.\n"); 1295 "Parses the source and returns the root of the Node tree. Call it\n" 1296 "several times to retrieve all documents from the source. On EOF,\n" 1297 "returns None and sets the 'eof' attribute on.\n"); 1296 1298 1297 1299 static PyMethodDef PySyckParser_methods[] = { … … 1348 1350 1349 1351 PyDoc_STRVAR(PySyckEmitter_doc, 1350 "Emitter(output, headless=False, use_header=True, explicit_typing=True," 1351 " style=None, best_width=80, indent=2) -> an Emitter object\n\n" 1352 "_syck.Emitter is a low-lever wrapper of the Syck emitter. It emit\n" 1352 "Emitter(output, headless=False, use_header=False, use_version=False,\n" 1353 " explicit_typing=True, style=None, best_width=80, indent=2)\n" 1354 " -> an Emitter object\n\n" 1355 "_syck.Emitter is a low-lever wrapper of the Syck emitter. It emits\n" 1353 1356 "a tree of Nodes into a YAML stream.\n"); 1354 1357 … … 1530 1533 PyDoc_STR("headerless document flag"), NULL}, 1531 1534 {"use_header", (getter)PySyckEmitter_getuse_header, NULL, 1532 PyDoc_STR("force header "), NULL},1535 PyDoc_STR("force header flag"), NULL}, 1533 1536 {"use_version", (getter)PySyckEmitter_getuse_version, NULL, 1534 PyDoc_STR("force version "), NULL},1537 PyDoc_STR("force version flag"), NULL}, 1535 1538 {"explicit_typing", (getter)PySyckEmitter_getexplicit_typing, NULL, 1536 1539 PyDoc_STR("explicit typing for all collections"), NULL}, … … 1752 1755 Py_INCREF(output); 1753 1756 self->output = output; 1754 1755 /*1756 self->emitter = syck_new_emitter();1757 self->emitter->bonus = self;1758 self->emitter->headless = self->headless;1759 self->emitter->use_header = use_header;1760 self->emitter->use_version = use_version;1761 self->emitter->explicit_typing = explicit_typing;1762 self->emitter->style = self->style;1763 self->emitter->best_width = self->best_width;1764 self->emitter->indent = self->indent;1765 1766 syck_emitter_handler(self->emitter, PySyckEmitter_node_handler);1767 syck_output_handler(self->emitter, PySyckEmitter_write_handler);1768 */1769 1757 1770 1758 self->emitting = 0; … … 1974 1962 PyDoc_STRVAR(PySyckEmitter_emit_doc, 1975 1963 "emit(root_node) -> None\n\n" 1976 "Emit the Node tree to the output.\n");1964 "Emits the Node tree to the output.\n"); 1977 1965 1978 1966 static PyMethodDef PySyckEmitter_methods[] = { … … 2033 2021 2034 2022 PyDoc_STRVAR(PySyck_doc, 2035 "low-level wrapper for the Syck YAML parser and emitter"); 2023 "_syck is a low-level wrapper for the Syck YAML parser and emitter.\n" 2024 "Do not use it directly, use the module 'syck' instead.\n"); 2025 2026 static int 2027 add_slotnames(PyTypeObject *type) 2028 { 2029 PyObject *slotnames; 2030 PyObject *name; 2031 PyGetSetDef *getsetter; 2032 2033 if (!type->tp_getset) return 0; 2034 if (!type->tp_dict) return 0; 2035 2036 slotnames = PyList_New(0); 2037 if (!slotnames) return -1; 2038 2039 for (getsetter = type->tp_getset; getsetter->name; getsetter++) { 2040 if (!getsetter->set) continue; 2041 name = PyString_FromString(getsetter->name); 2042 if (!name) { 2043 Py_DECREF(slotnames); 2044 return -1; 2045 } 2046 if (PyList_Append(slotnames, name) < 0) { 2047 Py_DECREF(name); 2048 Py_DECREF(slotnames); 2049 return -1; 2050 } 2051 Py_DECREF(name); 2052 } 2053 2054 if (PyDict_SetItemString(type->tp_dict, "__slotnames__", slotnames) < 0) { 2055 Py_DECREF(slotnames); 2056 return -1; 2057 } 2058 2059 Py_DECREF(slotnames); 2060 return 0; 2061 } 2036 2062 2037 2063 PyMODINIT_FUNC … … 2044 2070 if (PyType_Ready(&PySyckScalar_Type) < 0) 2045 2071 return; 2072 if (add_slotnames(&PySyckScalar_Type) < 0) 2073 return; 2046 2074 if (PyType_Ready(&PySyckSeq_Type) < 0) 2047 2075 return; 2076 if (add_slotnames(&PySyckSeq_Type) < 0) 2077 return; 2048 2078 if (PyType_Ready(&PySyckMap_Type) < 0) 2079 return; 2080 if (add_slotnames(&PySyckMap_Type) < 0) 2049 2081 return; 2050 2082 if (PyType_Ready(&PySyckParser_Type) < 0) -
trunk/lib/syck/__init__.py
r19 r25 1 """ 2 YAML is a data serialization format designed for human readability and 3 interaction with scripting languages. 4 5 Syck is an extension for reading and writing YAML in scripting languages. 6 7 PySyck provides Python bindings for Syck YAML parser and emitter. 8 9 To start working with PySyck, import the package 'syck': 10 >>> from syck import * 11 12 To parse a YAML document into a Python object, use the function 'load()': 13 >>> load(''' 14 ... - Mark McGwire 15 ... - Sammy Sosa 16 ... - Ken Griffey 17 ... ''') 18 ['Mark McGwire', 'Sammy Sosa', 'Ken Griffey'] 19 20 To emit a Python object into a YAML document, use the function 'dump()': 21 >>> print dump(['Mark McGwire', 'Sammy Sosa', 'Ken Griffey']) 22 --- 23 - Mark McGwire 24 - Sammy Sosa 25 - Ken Griffey 26 27 You may get access to the YAML parser tree using the function 'parse()': 28 >>> root_node = parse(''' 29 ... - Mark McGwire 30 ... - Sammy Sosa 31 ... - Ken Griffey 32 ... ''') 33 >>> root_node 34 <_syck.Seq object at 0xb7a1f874> 35 >>> root_node.kind 36 'seq' 37 >>> root_node.value 38 [<_syck.Scalar object at 0xb7a1e5fc>, <_syck.Scalar object at 0xb7a1e65c>, <_syck.Scalar object at 0xb7a1e6bc>] 39 40 You may now use the function 'emit()' to obtain the YAML document again: 41 >>> print emit(root_node) 42 --- 43 - Mark McGwire 44 - Sammy Sosa 45 - Ken Griffey 46 47 What do you get if you apply the function 'dump()' to root_node? Let's try it: 48 >>> print dump(root_node) 49 --- !python/object:_syck.Seq 50 value: 51 - !python/object:_syck.Scalar 52 value: Mark McGwire 53 tag: tag:yaml.org,2002:str 54 - !python/object:_syck.Scalar 55 value: Sammy Sosa 56 tag: tag:yaml.org,2002:str 57 - !python/object:_syck.Scalar 58 value: Ken Griffey 59 tag: tag:yaml.org,2002:str 60 61 As you can see, PySyck allow you to represent complex Python objects. 62 63 You can also dump the generated YAML output into any file-like object: 64 >>> import os 65 >>> stream = os.tmpfile() 66 >>> object = ['foo', 'bar', ['baz']] 67 >>> dump(object, stream) 68 >>> stream.seek(0) 69 >>> print stream.read() 70 --- 71 - foo 72 - bar 73 - - baz 74 75 To load several documents from a single YAML stream, use the function 76 'load_documents()': 77 >>> source = ''' 78 ... --- 79 ... american: 80 ... - Boston Red Sox 81 ... - Detroit Tigers 82 ... - New York Yankees 83 ... national: 84 ... - New York Mets 85 ... - Chicago Cubs 86 ... - Atlanta Braves 87 ... --- 88 ... - [name , hr, avg ] 89 ... - [Mark McGwire, 65, 0.278] 90 ... - [Sammy Sosa , 63, 0.288] 91 ... ''' 92 >>> for document in load_documents(source): 93 ... print document 94 ... 95 {'national': ['New York Mets', 'Chicago Cubs', 'Atlanta Braves'], 'american': ['Boston Red Sox', 'Detroit Tigers', 'New York Yankees']} 96 [['name', 'hr', 'avg'], ['Mark McGwire', 65, 0.27800000000000002], ['Sammy Sosa', 63, 0.28799999999999998]] 97 98 See the source code for more details. 99 """ 100 1 101 2 102 from _syck import * -
trunk/lib/syck/dumpers.py
r24 r25 1 """ 2 syck.dumpers is a high-level wrapper for the Syck YAML emitter. 3 Do not use it directly, use the module 'syck' instead. 4 """ 1 5 2 6 import _syck … … 10 14 'emit', 'dump', 'emit_documents', 'dump_documents'] 11 15 12 INF = 1e30000013 NEGINF = -INF14 NAN = INF/INF15 16 17 16 class GenericDumper(_syck.Emitter): 17 """ 18 GenericDumper dumps native Python objects into YAML documents. 19 """ 18 20 19 21 def dump(self, object): 22 """Dumps the given Python object as a YAML document.""" 20 23 self.emit(self._convert(object, {})) 21 24 … … 30 33 node.value[index] = self._convert(item, object_to_node) 31 34 elif node.kind == 'map': 32 for key in node.value.keys(): 33 value = node.value[key] 34 del node.value[key] 35 node.value[self._convert(key, object_to_node)] = \ 36 self._convert(value, object_to_node) 35 if isinstance(node.value, dict): 36 for key in node.value.keys(): 37 value = node.value[key] 38 del node.value[key] 39 node.value[self._convert(key, object_to_node)] = \ 40 self._convert(value, object_to_node) 41 elif isinstance(node.value, list): 42 for index in range(len(node.value)): 43 key, value = node.value[index] 44 node.value[index] = (self._convert(key, object_to_node), 45 self._convert(value, object_to_node)) 37 46 # # Workaround against a Syck bug: 38 47 # if node.kind == 'scalar' and node.style not in ['1quote', '2quote'] \ … … 42 51 43 52 def represent(self, object): 53 """Represents the given Python object as a 'Node'.""" 44 54 if isinstance(object, dict): 45 55 return _syck.Map(object.copy(), tag="tag:yaml.org,2002:map") … … 50 60 51 61 def allow_aliases(self, object): 62 """Checks whether the given object can be aliased.""" 52 63 return True 53 64 54 65 class Dumper(GenericDumper): 55 56 def __init__(self, *args, **kwds): 57 super(Dumper, self).__init__(*args, **kwds) 66 """ 67 Dumper dumps native Python objects into YAML documents. 68 """ 69 70 INF = 1e300000 71 inf_value = repr(INF) 72 neginf_value = repr(-INF) 73 nan_value = repr(INF/INF) 58 74 59 75 def find_representer(self, object): 76 """ 77 For the given object, find a method that can represent it as a 'Node' 78 object. 79 80 If the type of the object has the form 'package.module.type', 81 find_representer() returns the method 'represent_package_module_type'. 82 If this method does not exist, it checks the base types. 83 """ 60 84 for object_type in type(object).__mro__: 61 85 if object_type.__module__ == '__builtin__': … … 68 92 69 93 def represent(self, object): 94 """Represents the given Python object as a 'Node'.""" 70 95 representer = self.find_representer(object) 71 96 if representer: … … 97 122 def represent_float(self, object): 98 123 value = repr(object) 99 if value == repr(INF):124 if value == self.inf_value: 100 125 value = '.inf' 101 elif value == repr(NEGINF):126 elif value == self.neginf_value: 102 127 value = '-.inf' 103 elif value == repr(NAN):128 elif value == self.nan_value: 104 129 value = '.nan' 105 130 return _syck.Scalar(value, tag="tag:yaml.org,2002:float") … … 107 132 def represent_sets_Set(self, object): 108 133 return _syck.Seq(list(object), tag="tag:yaml.org,2002:set") 134 represent_set = represent_sets_Set 109 135 110 136 def represent_datetime_datetime(self, object): … … 121 147 122 148 def represent_type(self, object): 123 # TODO: Python 2.2 does not provide the module name of a function124 149 name = '%s.%s' % (object.__module__, object.__name__) 125 150 return _syck.Scalar('', tag="tag:python.yaml.org,2002:name:"+name) 126 151 represent_classobj = represent_type 127 152 represent_class = represent_type 153 # TODO: Python 2.2 does not provide the module name of a function 128 154 represent_function = represent_type 129 155 represent_builtin_function_or_method = represent_type … … 200 226 tag="tag:python.yaml.org,2002:apply:"+class_name) 201 227 228 def represent__syck_Node(self, object): 229 object_type = type(object) 230 type_name = '%s.%s' % (object_type.__module__, object_type.__name__) 231 state = [] 232 if hasattr(object_type, '__slotnames__'): 233 for name in object_type.__slotnames__: 234 value = getattr(object, name) 235 if value: 236 state.append((name, value)) 237 return _syck.Map(state, 238 tag="tag:python.yaml.org,2002:object:"+type_name) 239 202 240 def allow_aliases(self, object): 241 """Checks whether the given object can be aliased.""" 203 242 if object is None or type(object) in [int, bool, float]: 204 243 return False … … 210 249 211 250 def emit(node, output=None, Dumper=Dumper, **parameters): 251 """ 252 Emits the given node to the output. 253 254 If output is None, returns the produced YAML document. 255 """ 212 256 if output is None: 213 257 dumper = Dumper(StringIO.StringIO(), **parameters) … … 219 263 220 264 def dump(object, output=None, Dumper=Dumper, **parameters): 265 """ 266 Dumps the given object to the output. 267 268 If output is None, returns the produced YAML document. 269 """ 221 270 if output is None: 222 271 dumper = Dumper(StringIO.StringIO(), **parameters) … … 228 277 229 278 def emit_documents(nodes, output=None, Dumper=Dumper, **parameters): 279 """ 280 Emits the list of nodes to the output. 281 282 If output is None, returns the produced YAML document. 283 """ 230 284 if output is None: 231 285 dumper = Dumper(StringIO.StringIO(), **parameters) … … 238 292 239 293 def dump_documents(objects, output=None, Dumper=Dumper, **parameters): 294 """ 295 Dumps the list of objects to the output. 296 297 If output is None, returns the produced YAML document. 298 """ 240 299 if output is None: 241 300 dumper = Dumper(StringIO.StringIO(), **parameters) -
trunk/lib/syck/loaders.py
r22 r25 1 """ 2 syck.loaders is a high-level wrapper for the Syck YAML parser. 3 Do not use it directly, use the module 'syck' instead. 4 """ 1 5 2 6 # Python 2.2 compatibility … … 27 31 28 32 class GenericLoader(_syck.Parser): 33 """ 34 GenericLoader constructs primitive Python objects from YAML documents. 35 """ 29 36 30 37 def load(self): 38 """ 39 Loads a YAML document from the source and return a native Python 40 object. On EOF, returns None and set the eof attribute on. 41 """ 31 42 node = self.parse() 32 43 if self.eof: … … 71 82 72 83 def construct(self, node): 84 """Constructs a Python object by the given node.""" 73 85 return node.value 74 86 75 87 class Merge: 88 """Represents the merge key '<<'.""" 76 89 pass 77 90 78 91 class Default: 92 """Represents the default key '='.""" 79 93 pass 80 94 81 95 class Loader(GenericLoader): 96 """ 97 Loader constructs native Python objects from YAML documents. 98 """ 82 99 83 100 inf_value = 1e300000 … … 109 126 110 127 def find_constructor(self, node): 128 """ 129 Returns the contructor for generating a Python object for the given 130 node. 131 132 The node tags are mapped to constructors by the following rule: 133 134 Tag Constructor 135 --- ----------- 136 tag:yaml.org,2002:type construct_type 137 tag:python.yaml.org,2002:type construct_python_type 138 x-private:type construct_private_type 139 tag:domain.tld,2002:type construct_domain_tld_2002_type 140 141 See the method code for more details. 142 """ 111 143 parts = [] 112 144 if node.tag: … … 130 162 131 163 def construct(self, node): 164 """Constructs a Python object by the given node.""" 132 165 if node.kind == 'map' and self.merge_key in node.value: 133 166 self.merge_maps(node) … … 301 334 if isinstance(state, tuple) and len(state) == 2: 302 335 state, slotstate = state 303 object.__dict__.update(state) 336 if hasattr(object, '__dict__'): 337 object.__dict__.update(state) 338 elif state: 339 slotstate.update(state) 304 340 for key, value in slotstate.items(): 305 341 setattr(object, key, value) … … 349 385 350 386 def parse_documents(source, Loader=Loader, **parameters): 351 """Iterates over 'source' and yields the root node ofeach document."""387 """Iterates over 'source' and yields the root 'Node' for each document.""" 352 388 loader = Loader(source, **parameters) 353 389 while True: … … 358 394 359 395 def load_documents(source, Loader=Loader, **parameters): 360 """Iterates over 'source' and yields the root object ofeach document."""396 """Iterates over 'source' and yields the root object for each document.""" 361 397 loader = Loader(source, **parameters) 362 398 while True: -
trunk/sandbox/emit-it/Makefile
r11 r25 1 2 ALL = emit-it complex-key-bug trailing-space-bug 1 3 2 4 .PHONY: default clean 3 5 4 default: emit-it6 default: $(ALL) 5 7 6 8 clean: 7 rm -f emit-it8 rm -f emit-it.o9 rm -f *.o 10 rm -f $(ALL) 9 11 10 emit-it: emit-it.o 11 gcc emit-it.o -o emit-it -lsyck -L${HOME}/lib -Wall -Wstrict-prototypes12 %.o: %.c 13 gcc -c $< -o $@ -Wall -Wstrict-prototypes -I${HOME}/include 12 14 13 emit-it.o: emit-it.c 14 gcc -c emit-it.c -o emit-it.o -I${HOME}/include 15 15 $(ALL): %: %.o 16 gcc $< -o $@ -lsyck -L${HOME}/lib -Wall -Wstrict-prototypes -
trunk/sandbox/emit-it/complex-key-bug.c
r17 r25 1 1 2 #include <stdlib.h>3 2 #include <stdio.h> 4 #include <stdarg.h>5 #include <error.h>6 #include <string.h>7 3 8 4 #include <syck.h> … … 16 12 { 17 13 switch (id) { 14 18 15 case 1: 19 syck_emit_ seq(e, "tag:domainmyseq.tld,2002:zz", seq_none);16 syck_emit_map(e, NULL, map_none); 20 17 syck_emit_item(e, 2); 21 18 syck_emit_item(e, 3); 22 syck_emit_item(e, 4);23 /* syck_emit_item(e, 2);24 syck_emit_item(e, 1);*/25 19 syck_emit_end(e); 26 20 break; 21 27 22 case 2: 28 syck_emit_scalar(e, "tag:yaml.org,2002:str", scalar_none, 0, 0, 0, "Mark McGwire ", strlen("Mark McGwire ")); 23 syck_emit_map(e, "x-private:key", map_none); 24 syck_emit_item(e, 4); 25 syck_emit_item(e, 5); 26 syck_emit_end(e); 29 27 break; 28 30 29 case 3: 31 syck_emit_scalar(e, "tag:python.yaml.org,2002:object", scalar_none, 0, 0, 0, "Sammy Sosa", strlen("Sammy Sosa"));32 break;33 30 case 4: 34 syck_emit_scalar(e, "x-private:myowntype", scalar_none, 0, 0, 0, "Ken Griffey", strlen("Ken Griffey")); 31 case 5: 32 syck_emit_scalar(e, NULL, scalar_none, 0, 0, 0, "foo", 3); 35 33 break; 36 34 } 35 37 36 } 38 37 … … 48 47 syck_emitter_mark_node(e, 3); 49 48 syck_emitter_mark_node(e, 4); 50 /* syck_emitter_mark_node(e, 2); 51 syck_emitter_mark_node(e, 1);*/ 49 syck_emitter_mark_node(e, 5); 52 50 syck_emit(e, 1); 53 51 syck_emitter_flush(e, 0); -
trunk/sandbox/emit-it/emit-it.c
r17 r25 16 16 { 17 17 switch (id) { 18 /* 18 19 case 1: 19 20 syck_emit_seq(e, "tag:domainmyseq.tld,2002:zz", seq_none); … … 21 22 syck_emit_item(e, 3); 22 23 syck_emit_item(e, 4); 23 /* syck_emit_item(e, 2);24 syck_emit_item(e, 1);*/25 24 syck_emit_end(e); 26 25 break; … … 34 33 syck_emit_scalar(e, "x-private:myowntype", scalar_none, 0, 0, 0, "Ken Griffey", strlen("Ken Griffey")); 35 34 break; 35 */ 36 37 case 1: 38 syck_emit_map(e, NULL, map_none); 39 syck_emit_item(e, 2); 40 syck_emit_item(e, 3); 41 syck_emit_end(e); 42 break; 43 44 case 2: 45 syck_emit_map(e, "x-private:key", map_none); 46 syck_emit_item(e, 4); 47 syck_emit_item(e, 5); 48 syck_emit_end(e); 49 break; 50 51 case 3: 52 case 4: 53 case 5: 54 syck_emit_scalar(e, NULL, scalar_none, 0, 0, 0, "foo", 3); 55 break; 36 56 } 57 37 58 } 38 59 … … 48 69 syck_emitter_mark_node(e, 3); 49 70 syck_emitter_mark_node(e, 4); 71 syck_emitter_mark_node(e, 5); 50 72 /* syck_emitter_mark_node(e, 2); 51 73 syck_emitter_mark_node(e, 1);*/ -
trunk/sandbox/emit-it/trailing-space-bug.c
r17 r25 1 1 2 #include <stdlib.h>3 2 #include <stdio.h> 4 #include <stdarg.h>5 #include <error.h>6 3 #include <string.h> 7 4 8 5 #include <syck.h> 6 7 #define VALUE "this scalar contains traling spaces " 9 8 10 9 void output_handler(SyckEmitter *e, char *str, long len) … … 17 16 switch (id) { 18 17 case 1: 19 syck_emit_seq(e, "tag:domainmyseq.tld,2002:zz", seq_none); 20 syck_emit_item(e, 2); 21 syck_emit_item(e, 3); 22 syck_emit_item(e, 4); 23 /* syck_emit_item(e, 2); 24 syck_emit_item(e, 1);*/ 25 syck_emit_end(e); 26 break; 27 case 2: 28 syck_emit_scalar(e, "tag:yaml.org,2002:str", scalar_none, 0, 0, 0, "Mark McGwire ", strlen("Mark McGwire ")); 29 break; 30 case 3: 31 syck_emit_scalar(e, "tag:python.yaml.org,2002:object", scalar_none, 0, 0, 0, "Sammy Sosa", strlen("Sammy Sosa")); 32 break; 33 case 4: 34 syck_emit_scalar(e, "x-private:myowntype", scalar_none, 0, 0, 0, "Ken Griffey", strlen("Ken Griffey")); 18 syck_emit_scalar(e, "tag:yaml.org,2002:str", scalar_none, 0, 0, 0, VALUE, strlen(VALUE)); 35 19 break; 36 20 } 21 37 22 } 38 23 … … 45 30 syck_output_handler(e, output_handler); 46 31 syck_emitter_mark_node(e, 1); 47 syck_emitter_mark_node(e, 2);48 syck_emitter_mark_node(e, 3);49 syck_emitter_mark_node(e, 4);50 /* syck_emitter_mark_node(e, 2);51 syck_emitter_mark_node(e, 1);*/52 32 syck_emit(e, 1); 53 33 syck_emitter_flush(e, 0); -
trunk/tests/test_pickle.py
r24 r25 288 288 ] 289 289 290 NODES = """ 291 - foo 292 - [bar, baz] 293 """ 294 295 BUGGY_NODES = """ 296 - foo 297 - { bar: baz } 298 """ 299 290 300 class ExLoader(syck.Loader): 291 301 … … 332 342 self.assertEqual(left, right) 333 343 344 class TestNodesReduce(unittest.TestCase): 345 346 def testNodesReduce(self): 347 object = syck.load(NODES) 348 nodes = syck.parse(NODES) 349 output = syck.dump(nodes) 350 print output 351 nodes2 = syck.load(output) 352 output2 = syck.emit(nodes2) 353 object2 = syck.load(output2) 354 self.assertEqual(object, object2) 355 356 def testBuggyNodesReduce(self): 357 object = syck.load(BUGGY_NODES) 358 nodes = syck.parse(BUGGY_NODES) 359 output = syck.dump(nodes) 360 print output 361 nodes2 = syck.load(output) 362 output2 = syck.emit(nodes2) 363 object2 = syck.load(output2) 364 self.assertEqual(object, object2) 365
Note: See TracChangeset
for help on using the changeset viewer.
