
    1                     p    S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKr " S S\5      r	 " S S	\5      r
g)
zGeneric debug tag accumulator.    )absolute_import)division)unicode_literalsNc                   P    \ rS rSrSrS r\S 5       rS rS r	S r
S rSS
 jrSrg	)Tag   a  A debug tag object.

Attributes:
  _name: The display name.
  _count: The number of times count() was called.
  _start: Most recent start() time in floating point seconds.
  _text: text() value.
  _intervals: The list or stop()-start() intervals in floating point seconds.
c                 H    Xl         SU l        SU l        S U l        / U l        g )Nr   )_name_count_start_text
_intervals)selfnames     3lib/googlecloudsdk/command_lib/interactive/debug.py__init__Tag.__init__'   s#    JDKDKDJDO    c                 b    SSSSSS.nUS:X  a  gS	U;  a  g
UR                  US   5      US   :g  $ )zAReturns True if text "needs" quotes for pretty printing contents."'}]))r   r   {[( T Fr   )get)clstextpairss      r   needs_quotesTag.needs_quotes.   sD     Cc#>Erz
$99T!Wb))r   c                    [         R                  " 5       nUR                  SR                  U R                  5      5        U R
                  (       a*  UR                  SR                  U R
                  5      5        U R                  (       aL  [        U R                  5      nUR                  SR                  U[        U R                  5      U-  5      5        U R                  bi  U R                  n[        U[        R                  5      (       a  U R                  U5      (       a  SU-   S-   nUR                  SR                  U5      5        UR                  5       $ )z%Returns the tag/value display string.z{}z:{}z
:{}:{:.6f}r   )ioStringIOwriteformatr
   r   r   lensumr   
isinstancesixstring_typesr%   getvalue)r   bufnr#   s       r   contentsTag.contents9   s    
++-CIIdkk$**%&{{	iiT[[)*
doo
a	ii##As4??';a'?@AzzZZd	D#**	+	+0A0A$0G0GTzC	iiT"#<<>r   c                 0    U =R                   S-  sl         U $ )zIncrements the tag count.   )r   r   s    r   count	Tag.countI   s    KK1KKr   c                 :    [         R                   " 5       U l        U $ )zStarts the tag timing interval.)timer   r8   s    r   start	Tag.startN   s    ))+DKKr   c                 |    U R                   R                  [        R                  " 5       U R                  -
  5        U $ )zStops the tag timing interval.)r   appendr<   r   r8   s    r   stopTag.stopS   s(    OO499;45Kr   Nc                     Xl         U $ )z4Sets the tag text value, omit the text arg to unset.)r   )r   ts     r   r#   Tag.textX   s    JKr   )r   r   r
   r   r   )N)__name__
__module____qualname____firstlineno____doc__r   classmethodr%   r4   r9   r=   rA   r#   __static_attributes__ r   r   r   r      s9     * * 


r   r   c                   0    \ rS rSrSrS rS rS rS rSr	g)	Debug^   a  The controlling debug object.

Debug "logger". Object tags (attributes) are created on the fly to preserve
the feel of printf debugging.

Usage:

  debug.foo.count().text(some_object)
  debug.bar.text('some state')
  debug.tag(some_string).count()
  debug.time.start()
  ...
  debug.time.stop()
  ...
  Display(debug.contents())

Attributes:
  _changed: If _contents may have changed.
  _contents: The cached sorted list of tag/value strings.
  _tags: The list of debug tags.
c                 .    SU l         / U l        0 U l        g )NF_changed	_contents_tagsr8   s    r   r   Debug.__init__u   s    DMDNDJr   c                      U R                   U   nSU l        U$ ! [         a    [        U5      nX R                   U'    N.f = f)z;Returns a tag by key name, creates tag in _tags on the fly.T)rU   KeyErrorr   rS   )r   keytags      r   rZ   	Debug.tagz   sG    JJsOc DMJ	  Hcjjos    #A A c                 $    U R                  U5      $ )z>Called when __getattribute__ fails => creates tags on the fly.)rZ   )r   rY   s     r   __getattr__Debug.__getattr__   s    88C=r   c                     U R                   (       aX  SU l         [        [        R                  " U R                  5      5       VVs/ s H  u  pUR                  5       PM     snnU l        U R                  $ s  snnf )z5Returns the sorted list of tag/value display strings.F)rS   sortedr/   	iteritemsrU   r4   rT   )r   _rZ   s      r   r4   Debug.contents   s[    }}dm&,S]]4::-F&GI&GFA &GIdn>>Is   A6rR   N)
rF   rG   rH   rI   rJ   r   rZ   r]   r4   rL   rM   r   r   rO   rO   ^   s    ,
r   rO   )rJ   
__future__r   r   r   r(   r<   r/   objectr   rO   rM   r   r   <module>rf      s5     % &  ' 	  
?& ?D0F 0r   