Current File : //usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyo
�
.�t_c@sHdZddlZddlZejd�dejfd��YZdS(s}

  YAMLObject - Provides mapping to/from YAML.

  $Id: //eng/vdo-releases/magnesium/src/python/vdo/utils/YAMLObject.py#2 $

i����Ntutilst
YAMLObjectcBs�eZdZejZed��Zed��Zd�Z	ed��Z
ed��Zed��Z
d�Zed��Zd	�ZRS(
s�Provides conversion of objects to and from YAML representations.

  The attributes that are included in the YAML representation are taken
  from an instance's __dict__ filtered through the list returned from the
  _yamlAttributeKeys property.

  The list from the _yamlAttributeKeys property is used to check for missing
  attributes when generating the YAML representation.  It is also used
  to check for missing or extraneous attributes when constructing an instance
  from the YAML representation.
  Subclasses must override _yamlAttributeKeys.

  Subclasses must specify the class attribute yaml_tag which indicates the type
  of the instance in the YAML representation.

  Class attributes:
    yaml_tag (unicode string) - YAML representation identfifier;
                                must be specified by subclasses
    yaml_loader               - The loader to use; set to yaml.SafeLoader
                                to allow yaml.load_safe() to instantiate
                                objects
  ccs1|j�}|V|j|�}|j|�dS(s�Constructs and returns an instance from its YAML representation.

    Returns:
      instance constructed from YAML representation.
    N(t_yamlMakeInstancetconstruct_mappingt_yamlSetAttributes(tclstloadertnodetinstancetmapping((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyt	from_yaml>scCs|j}|j|j|�S(sgReturns a YAML representation of the instance.

    Returns:
      YAML representation of instance
    (t	_yamlDatatrepresent_mappingtyaml_tag(RtdumpertdatatyamlData((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pytto_yamlKs	cCs tt|�j�i|_dS(N(tsuperRt__init__t_preservedExtraAttributes(tself((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyRVscCs|�S(sReturns an instance of the class specifying placeholder values for
    any arguments required by the __init__ method.

    The default implementation is to instantiate without arguments.
    Subclasses must override if their __init__ method takes arguments.
    ((R((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyR]scCsftg|jj�D]6\}}||jkr||jkr||f^q�}|j|j�|S(s
Returns a dictionary containing the data to include in generating
    the instance's YAML representation.

    The base implementation uses the contents of the instance's __dict__
    filtered through the list of keys returned from _yamlAttributeKeys
    excluding any that require special handling (subclasses must override this
    method to add those) and adds any entries from the preserved extra
    attributes.

    Returns:
      dictionary of data to use in generating the instance's YAML
      representation
    (tdictt__dict__t	iteritemst_yamlAttributeKeyst_yamlSpeciallyHandledAttributestupdateR(RtkeytvalueR((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyRhs$cCs
t�dS(s�Returns a list of the keys for the attributes to include in the
    instance's YAML representation.

    Must be overridden by subclasses.

    Returns:
      list of keys for attributes to include in the instance's YAML
      representation
    N(tNotImplementedError(R((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyR�scCs�tg|j�D]'\}}||jkr||f^q�}|jj|�g|j�D]*}||jkr]||jkr]|^q]}x"|D]}t||||�q�WdS(s�Sets the instance's internal attributes from the YAML attributes.

    By default, the attributes are set via invoking setattr() targeted
    to the instance.  If a subclass uses different internal names or
    computes the attributes in some way it must override this method
    to handle the attributes appropriately.  The subclass must also account
    for the possibility that the attributes it receives may not contain the
    entirety of such specially handled attributes; in other words, it must
    check for each attribute's existence in the attributes dictionary it
    receives.  Any unspecified attributes must be given a default value in
    whatever manner the subclass chooses.

    Any entries in the specified attributes which are unknown to the entity
    being constructed are preserved for later use in generating YAML output.

    Arguments:
      attributes (dictionary) - the attributes from the YAML representation
    N(RtitemsRRRtkeysRtsetattr(Rt
attributesRRtextraR ((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyR�s$
cCsgS(sReturns a list of attributes that are specially handled by subclasses.
    These attributes are skipped by _yamlData and _yamlSetAttributes
    implemented by YAMLObject.

    Subclasses must override both _yamlData and _yamlSetAttributes to handle
    these attributes.
    ((R((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyR�s	cCsAt|t|��s*ttd���n|jj|j�dS(s�Updates the current object (self) from the specified instance.
    This is for classes that perform indirect construction using the results
    of the YAML load.  Instances of such classes are required to invoke this
    method themselves.

    The specified instance must be the same class (or a subclass) of the
    current object to guarantee that any attributes the current object attempts
    to update will be available from the instance.

    Arguments:
      instance (YAMLObject) - object source for update

    Raises:
      TypeError - specified instance is not the same class (or a subclass)
                  of the current object
    s(attempt to update from incompatible typeN(t
isinstancettypet	TypeErrort_RR(RR((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyt_yamlUpdateFromInstance�s(t__name__t
__module__t__doc__tyamlt
SafeLoadertyaml_loadertclassmethodR
RRRtpropertyRRRRR((((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyR"s	
		(R+tgettextR,tinstallR(((s8/usr/lib/python2.7/site-packages/vdo/utils/YAMLObject.pyt<module>s