B
    +²ô`M  ã               @   sX   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlmZ G dd„ de	ƒZ
dS )	z@Visitor restricting traversal to only the public tensorflow API.é    )Úabsolute_import)Údivision)Úprint_functionN)Ú
tf_inspectc               @   sR   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZdd	„ Zddd„Z	dd„ Z
dd„ Zd
S )ÚPublicAPIVisitorzBVisitor to use with `traverse` to visit exactly the public TF API.c             C   sD   || _ d| _dddgdgdœ| _ddd	d
dddgdgdgdœ| _dS )zàConstructor.

    `visitor` should be a callable suitable as a visitor for `traverse`. It will
    be called only for members of the public TensorFlow API.

    Args:
      visitor: A visitor to call for the public API.
    ÚtfÚcompilerÚcoreÚpythonZ	cpp_flags)r   ztf.flagsZexamplesÚflagsÚplatformZpywrap_tensorflowZuser_opsZtoolsZtensorboardZmock)r   ztf.appztf.testN)Ú_visitorÚ
_root_nameÚ_private_mapÚ_do_not_descend_map)ÚselfZvisitor© r   úQ/home/dcms/DCMS/lib/python3.7/site-packages/tensorflow/tools/common/public_api.pyÚ__init__    s    	zPublicAPIVisitor.__init__c             C   s   | j S )zÙA map from parents to symbols that should not be included at all.

    This map can be edited, but it should not be edited once traversal has
    begun.

    Returns:
      The map marking symbols to not include.
    )r   )r   r   r   r   Úprivate_mapP   s    
zPublicAPIVisitor.private_mapc             C   s   | j S )zØA map from parents to symbols that should not be descended into.

    This map can be edited, but it should not be edited once traversal has
    begun.

    Returns:
      The map marking symbols to not explore.
    )r   )r   r   r   r   Údo_not_descend_map\   s    
z#PublicAPIVisitor.do_not_descend_mapc             C   s
   || _ dS )z'Override the default root name of 'tf'.N)r   )r   Z	root_namer   r   r   Úset_root_nameh   s    zPublicAPIVisitor.set_root_nameNc             C   sF   ~|| j kr|| j | kpDt |¡ d¡r>t dt |¡¡ pD|dkS )z!Return whether a name is private.Ú_z__.*__$)Ú__base__Ú	__class__)r   ÚsixÚ
ensure_strÚ
startswithÚreÚmatch)r   ÚpathÚnameÚobjr   r   r   Ú_is_privatel   s
    zPublicAPIVisitor._is_privatec             C   s   || j ko|| j | kS )zESafely queries if a specific fully qualified name should be excluded.)r   )r   r    r!   r   r   r   Ú_do_not_descendu   s    
z PublicAPIVisitor._do_not_descendc             C   sÂ   t  |¡r4tt |¡ d¡ƒdkr4td| j|f ƒ‚|rHd | j|g¡n| j}x0t	|ƒD ]$\}}|  
|||¡rX| ||f¡ qXW |  |||¡ x.t	|ƒD ]"\}}|  ||¡r˜| ||f¡ q˜W dS )z.Visitor interface, see `traverse` for details.Ú.é
   zZModules nested too deep:
%s.%s

This is likely a problem with an accidental public import.N)r   ÚismoduleÚlenr   r   ÚsplitÚRuntimeErrorr   ÚjoinÚlistr#   Úremover   r$   )r   r    ÚparentÚchildrenÚ	full_pathr!   Úchildr   r   r   Ú__call__z   s    zPublicAPIVisitor.__call__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r#   r$   r2   r   r   r   r   r      s   0
	r   )r6   Ú
__future__r   r   r   r   r   Ztensorflow.python.utilr   Úobjectr   r   r   r   r   Ú<module>   s   