
 ,[c           @   s   d  Z  d Z d d g Z d d l Z d d l m Z e d d d	 d
    Z e d d d d    Z d   Z	 d   Z
 d S(   s	  
****
YAML
****
Read and write NetworkX graphs in YAML format.

"YAML is a data serialization format designed for human readability 
and interaction with scripting languages."
See http://www.yaml.org for documentation.

Format
------
http://pyyaml.org/wiki/PyYAML

s   Aric Hagberg (hagberg@lanl.gov)t	   read_yamlt
   write_yamliN(   t	   open_filei   t   modet   wc         K   sG   y d d l  } Wn t k
 r/ t d   n X| j |  | |  d S(   sw  Write graph G in YAML format to path. 

    YAML is a data serialization format designed for human readability 
    and interaction with scripting languages [1]_.

    Parameters
    ----------
    G : graph
       A NetworkX graph
    path : file or string
       File or filename to write. 
       Filenames ending in .gz or .bz2 will be compressed.

    Notes
    -----
    To use encoding on the output file include e.g. `encoding='utf-8'`
    in the keyword arguments.

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> nx.write_yaml(G,'test.yaml')

    References
    ----------
    .. [1] http://www.yaml.org
    iNs0   write_yaml() requires PyYAML: http://pyyaml.org/(   t   yamlt   ImportErrort   dump(   t   G_to_be_yamlt   path_for_yaml_outputt   kwdsR   (    (    s9   lib/python2.7/site-packages/networkx/readwrite/nx_yaml.pyR      s
    i    t   rc         C   sC   y d d l  } Wn t k
 r/ t d   n X| j |   } | S(   s,  Read graph in YAML format from path.

    YAML is a data serialization format designed for human readability 
    and interaction with scripting languages [1]_.

    Parameters
    ----------
    path : file or string
       File or filename to read.  Filenames ending in .gz or .bz2 
       will be uncompressed.

    Returns
    -------
    G : NetworkX graph

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> nx.write_yaml(G,'test.yaml')
    >>> G=nx.read_yaml('test.yaml')

    References
    ----------
    .. [1] http://www.yaml.org

    iNs/   read_yaml() requires PyYAML: http://pyyaml.org/(   R   R   t   load(   t   pathR   t   G(    (    s9   lib/python2.7/site-packages/networkx/readwrite/nx_yaml.pyR    B   s    c         C   s:   d d l  m } y d d  l } Wn | d   n Xd  S(   Ni(   t   SkipTests   PyYAML not available(   t   noseR   R   (   t   moduleR   R   (    (    s9   lib/python2.7/site-packages/networkx/readwrite/nx_yaml.pyt   setup_moduleh   s
    c         C   s   d d  l  } | j d  d  S(   Nis	   test.yaml(   t   ost   unlink(   R   R   (    (    s9   lib/python2.7/site-packages/networkx/readwrite/nx_yaml.pyt   teardown_moduler   s    (   t   __doc__t
   __author__t   __all__t   networkxt   nxt   networkx.utilsR   R   R    R   R   (    (    (    s9   lib/python2.7/site-packages/networkx/readwrite/nx_yaml.pyt   <module>   s   $&	
