Changes between Version 48 and Version 49 of PyYAMLDocumentation
- Timestamp:
- 07/08/12 18:18:58 (11 months ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
PyYAMLDocumentation
v48 v49 240 240 241 241 Note that the ability to construct an arbitrary Python object may be dangerous 242 if you receive a YAML document from an untrusted source such as Internet.242 if you receive a YAML document from an untrusted source such as the Internet. 243 243 The function '''`yaml.safe_load`''' limits this ability to simple Python objects 244 244 like integers or lists. … … 409 409 410 410 411 The default representation for '''`Dice`''' objects is not nice:411 The default representation for '''`Dice`''' objects is not pretty: 412 412 {{{ 413 413 #!python … … 426 426 }}} 427 427 428 First we define a representer that convert a dice object toscalar node429 with the tag `!dice` andregister it.428 First we define a representer that converts a dice object to a scalar node 429 with the tag `!dice`, then we register it. 430 430 {{{ 431 431 #!python … … 464 464 }}} 465 465 466 You might want to notspecify the tag `!dice` everywhere. There is a way467 to teach PyYAML that any untagged plain scalar thatlooks like XdY has466 You might not want to specify the tag `!dice` everywhere. There is a way 467 to teach PyYAML that any untagged plain scalar which looks like XdY has 468 468 the implicit tag `!dice`. Use '''`add_implicit_resolver`''': 469 469 {{{ … … 535 535 --- 536 536 - C 537 - C# # Note that comments are denoted with ' #' (space and#).537 - C# # Note that comments are denoted with ' #' (space then #). 538 538 - C++ 539 539 - Cold Fusion … … 543 543 === Block sequences === 544 544 545 In the block context, sequence entries are denoted by '''`- `''' (dash andspace):545 In the block context, sequence entries are denoted by '''`- `''' (dash then space): 546 546 {{{ 547 547 # YAML … … 616 616 === Block mappings === 617 617 618 In the block context, keys and values of mappings are separated by '''`: `''' (colon andspace):618 In the block context, keys and values of mappings are separated by '''`: `''' (colon then space): 619 619 {{{ 620 620 # YAML … … 631 631 }}} 632 632 633 Complex keys are denoted with '''`? `''' (question mark andspace):633 Complex keys are denoted with '''`? `''' (question mark then space): 634 634 {{{ 635 635 # YAML … … 744 744 745 745 Using single-quoted scalars, you may express any value that does not contain special characters. 746 No escaping occurs for single quoted scalars except that duplicate quotes '''`''`''' arereplaced747 with a single quote '''`'`'''.746 No escaping occurs for single quoted scalars except that a pair of adjacent quotes '''`''`''' is replaced 747 with a lone single quote '''`'`'''. 748 748 749 749 Double-quoted is the most powerful style and the only style that can express any scalar value. … … 753 753 There are two kind of block scalar styles: '''literal''' and '''folded'''. The literal style is 754 754 the most suitable style for large block of text such as source code. The folded style is similar 755 to the literal style, but two consequent non-empty lines are joined to a single line separated755 to the literal style, but two adjacent non-empty lines are joined to a single line separated 756 756 by a space character. 757 757 … … 808 808 }}} 809 809 810 Plain scalars without explicitly defined tag are subject to implicit tag810 Plain scalars without explicitly defined tags are subject to implicit tag 811 811 resolution. The scalar value is checked against a set of regular expressions 812 812 … … 960 960 961 961 '''`emit(events, stream=None)`''' serializes the given sequence of parsing `events` and 962 write them to the `stream`. if `stream` is `None`, it returns the produced stream.962 writes them to the `stream`. if `stream` is `None`, it returns the produced stream. 963 963 964 964 {{{ … … 1069 1069 }}} 1070 1070 1071 '''`add_constructor(tag, constructor)`''' allows to specifya `constructor` for the given `tag`.1071 '''`add_constructor(tag, constructor)`''' specifies a `constructor` for the given `tag`. 1072 1072 A constructor is a function that converts a node of a YAML representation graph to a native Python object. 1073 1073 A constructor accepts an instance of `Loader` and a node and returns a Python object. 1074 1074 1075 '''`add_multi_constructor(tag_prefix, multi_constructor)`''' allows to specifya `multi_constructor`1075 '''`add_multi_constructor(tag_prefix, multi_constructor)`''' specifies a `multi_constructor` 1076 1076 for the given `tag_prefix`. A multi-constructor is a function that converts a node of a YAML 1077 1077 representation graph to a native Python object. A multi-constructor accepts an instance of `Loader`, … … 1092 1092 }}} 1093 1093 1094 '''`add_representer(data_type, representer)`''' allows to specifya `representer` for Python objects1094 '''`add_representer(data_type, representer)`''' specifies a `representer` for Python objects 1095 1095 of the given `data_type`. A representer is a function that converts a native Python object to a node 1096 1096 of a YAML representation graph. A representer accepts an instance of `Dumper` and an object and returns a node. 1097 1097 1098 '''`add_multi_representer(base_data_type, multi_representer)`''' allows to specifya `multi_representer`1098 '''`add_multi_representer(base_data_type, multi_representer)`''' specifies a `multi_representer` 1099 1099 for Python objects of the given `base_data_type` or any of its subclasses. A multi-representer is 1100 1100 a function that converts a native Python object to a node of a YAML representation graph. … … 1587 1587 }}} 1588 1588 1589 '''`Dumper.emit(event)`''' serializes the given `event` and write it to the output stream.1589 '''`Dumper.emit(event)`''' serializes the given `event` and writes it to the output stream. 1590 1590 1591 1591 {{{
