Changes between Version 2 and Version 3 of PyYAMLDocumentation


Ignore:
Timestamp:
04/23/06 07:49:43 (8 years ago)
Author:
xi
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • PyYAMLDocumentation

    v2 v3  
    33''work in progress'' 
    44 
     5''Some RPG-ish descriptions are stolen from [http://www.thangorodrim.net/ the Angband rogue-like game]. 
     6 
    57[[PageOutline]] 
    68 
    79== Basic usage == 
    810 
     11Start with importing the '''`yaml`''' package. 
     12 
     13{{{ 
     14#!python 
     15>>> import yaml 
     16}}} 
     17 
    918=== load() === 
    1019 
     20'''Warning: It is not safe to call `yaml.load` with any data received from an untrusted source! 
     21`yaml.load` is as powerful as `pickle.load` and so may call any Python function.''' 
     22Check the '''`yaml.safe_load`''' function though. 
     23 
     24The function '''`yaml.load`''' converts a YAML document to a Python object. 
     25 
     26{{{ 
     27#!python 
     28>>> yaml.load(""" 
     29... - Hesperiidae 
     30... - Papilionidae 
     31... - Apatelodidae 
     32... - Epiplemidae 
     33... """) 
     34 
     35['Hesperiidae', 'Papilionidae', 'Apatelodidae', 'Epiplemidae'] 
     36}}} 
     37 
     38'''`yaml.load`''' accepts a string, a Unicode string, an open file object, or 
     39an open Unicode file object. A string or a file must be encoded with '''utf-8''', 
     40'''utf-16-be''' or '''utf-16-le''' encoding. '''`yaml.load`''' detects the encoding 
     41by checking the '''BOM''' (byte order mark) sequence at the beginning of the 
     42string/file. If no '''BOM''' is present, the '''utf-8''' encoding is assumed. 
     43{{{ 
     44#!python 
     45>>> yaml.load(u""" 
     46... hello: Привет! 
     47... """) 
     48 
     49{'hello': u'\u041f\u0440\u0438\u0432\u0435\u0442!'} 
     50 
     51>>> stream = file('document.yaml', 'r')    # 'document.yaml' contains a single YAML document. 
     52>>> yaml.load(stream) 
     53[...]    # A Python object corresponding to the document. 
     54}}} 
     55 
     56if a string or a file contains several documents, you may load them all with the 
     57'''`yaml.load_all`''' function. 
     58 
     59{{{ 
     60#!python 
     61>>> documents = """ 
     62... --- 
     63... name: The Set of Gauntlets 'Pauraegen' 
     64... description: > 
     65...     A set of handgear with sparks that crackle 
     66...     across its knuckleguards. 
     67... --- 
     68... name: The Set of Gauntlets 'Paurnen' 
     69... description: > 
     70...   A set of gauntlets that gives off a foul, 
     71...   acrid odour yet remains untarnished. 
     72... --- 
     73... name: The Set of Gauntlets 'Paurnimmen' 
     74... description: > 
     75...   A set of handgear, freezing with unnatural cold. 
     76... """ 
     77 
     78>>> for data in yaml.load_all(documents): 
     79...     print data 
     80 
     81{'description': 'A set of handgear with sparks that crackle across its knuckleguards.\n', 
     82'name': "The Set of Gauntlets 'Pauraegen'"} 
     83{'description': 'A set of gauntlets that gives off a foul, acrid odour yet remains untarnished.\n', 
     84'name': "The Set of Gauntlets 'Paurnen'"} 
     85{'description': 'A set of handgear, freezing with unnatural cold.\n', 
     86'name': "The Set of Gauntlets 'Paurnimmen'"} 
     87}}} 
     88 
    1189=== dump() === 
    1290 
     
    47125==== Resolver interface ==== 
    48126 
    49 ==== The yaml package ==== 
     127=== YAMLObject === 
     128 
     129=== The yaml package === 
    50130 
    51131== Deviations from the specification ==