
    6                     &   S r SSKJ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J	r
  SSKJr   " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rg)zAThread message classes.

Messages are added to the status queue.
    )absolute_import)print_function)division)unicode_literalsN)Error)errorc                   (    \ rS rSrSrSS jrS rSrg)StatusMessage    zTGeneral StatusMessage class.

All Message classes inherit this StatusMessage class.
Nc                     Xl         U=(       d    [        R                  " 5       U l        U=(       d    [        R
                  " 5       R                  U l        g)zCreates a Message.

Args:
  message_time: Time that this message was created (since Epoch).
  process_id: Process ID that produced this message (overridable for
      testing).
  thread_id: Thread ID that produced this message (overridable for testing).
N)timeosgetpid
process_id	threadingcurrent_threadident	thread_id)selfmessage_timer   r   s       'platform/gsutil/gslib/thread_message.py__init__StatusMessage.__init__&   s6     I /BIIKDOB)":":"<"B"BDN    c                     U R                   R                  < SU R                  < SU R                  < SU R                  < S3$ );Returns a string with a valid constructor for this message.(, process_id=, thread_id=))	__class____name__r   r   r   r   s    r   __str__StatusMessage.__str__3   s/     
	 	 $))T__dnn	NOr   )r   r   r   )NN)r"   
__module____qualname____firstlineno____doc__r   r$   __static_attributes__ r   r   r
   r
       s    
COr   r
   c                   >   ^  \ rS rSrSr    SU 4S jjrS rSrU =r$ )RetryableErrorMessage:   zMessage class for retryable errors encountered by the JSON API.

This class contains information about the retryable error encountered to
report to analytics collection and to display in the UI.
c                 x  > [         [        U ]  UUUS9  UR                  R                  U l        UR                  R                  S;   a,  SUR                  R                  R                  5       -   U l        [        U[        5      (       d  [        U[        5      (       a  SU l        OSU l        X0l        X@l        g)a  Creates a RetryableErrorMessage.

Args:
  exception: The retryable error that was thrown.
  message_time: Float representing when message was created (seconds since
      Epoch).
  num_retries: The number of retries consumed so far.
  total_wait_sec: The total amount of time waited so far in retrying.
  process_id: Process ID that produced this message (overridable for
      testing).
  thread_id: Thread ID that produced this message (overridable for testing).
r   r   )socket_socketSocketTFN)superr-   r   r!   r"   
error_typer&   
capitalize
isinstanceapitools_service_errorsix_service_erroris_service_errornum_retriestotal_wait_sec)r   	exceptionr   r;   r<   r   r   r!   s          r   r   RetryableErrorMessage.__init__A   s    & 

/;E:C 0 E  ))22DO %%)>> 9#6#6#?#?#J#J#LLdo94559/00"d#d # )r   c                     U R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < SU R                  < SU R                  < S3$ )r   r   z(), num_retries=z, total_wait_sec=z, time=r   r   r    )r!   r"   r5   r;   r<   r   r   r   r#   s    r   r$   RetryableErrorMessage.__str__k   sF     ^^$$doot7G7G  $))T__dnnN Or   )r5   r:   r;   r<   )r   r   NN	r"   r&   r'   r(   r)   r   r$   r*   __classcell__r!   s   @r   r-   r-   :   s(     ()TO Or   r-   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )FinalMessages   z^Creates a FinalMessage.

A FinalMessage simply indicates that we have finished our operation.
c                 ,   > [         [        U ]  U5        g)zxCreates a FinalMessage.

Args:
  message_time: Float representing when message was created (seconds since
      Epoch).
N)r4   rE   r   r   r   r!   s     r   r   FinalMessage.__init__y   s     
,&|4r   r+   r"   r&   r'   r(   r)   r   r*   rB   rC   s   @r   rE   rE   s   s    
5 5r   rE   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )MetadataMessage   zCreates a MetadataMessage.

A MetadataMessage simply indicates that a metadata operation on a given object
has been successfully done. The only passed argument is the time when such
operation has finished.
c                 ,   > [         [        U ]  U5        g)z{Creates a MetadataMessage.

Args:
  message_time: Float representing when message was created (seconds since
      Epoch).
N)r4   rL   r   rH   s     r   r   MetadataMessage.__init__   s     
/4),7r   r+   rJ   rC   s   @r   rL   rL      s    8 8r   rL   c                   p   ^  \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSr       SU 4S jjrS rSrU =r$ )FileMessage   zMarks start or end of an operation for a file, cloud object or component.

This class contains general information about each file/component. With that,
information such as total size and estimated time remaining may be calculated
beforehand.
                        	   
      c                    > [         [        U ]  UU	U
S9  Xl        X l        X@l        X`l        XPl        Xpl        Xl	        g)a>  Creates a FileMessage.

Args:
  src_url: FileUrl/CloudUrl representing the source file.
  dst_url: FileUrl/CloudUrl representing the destination file.
  message_time: Float representing when message was created (seconds since
      Epoch).
  size: Total size of this file/component, in bytes.
  finished: Boolean to indicate whether this is starting or finishing
      a file/component transfer.
  component_num: Component number, if dealing with a component.
  message_type: Type of the file/component.
  bytes_already_downloaded: Specific field for resuming downloads. When
      starting a component download, it tells how many bytes were already
      downloaded.
  process_id: Process ID that produced this message (overridable for
      testing).
  thread_id: Thread ID that produced this message (overridable for testing).
r0   N)
r4   rQ   r   src_urldst_urlsizecomponent_numfinishedmessage_typebytes_already_downloaded)r   r_   r`   r   ra   rc   rb   rd   re   r   r   r!   s              r   r   FileMessage.__init__   sI    > 
+t%l1;09 & ; LLI&M$$<!r   c                 N   U R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < SU R                  < SU R                  < SU R                  < SU R                  < S	U R                  < S
U R                  < S3$ )r   z('z', '', z, size=, finished=, component_num=z, message_type=z, bytes_already_downloaded=r   r   r    )r!   r"   r_   r`   r   ra   rc   rb   rd   re   r   r   r#   s    r   r$   FileMessage.__str__   sa    
 ^^$$dllDLL$))YYt'9'94;L;L**DOOT^^M Nr   )re   rb   r`   rc   rd   ra   r_   )NFNNNNN)r"   r&   r'   r(   r)   FILE_DOWNLOADFILE_UPLOADFILE_CLOUD_COPYFILE_LOCAL_COPYFILE_DAISY_COPYFILE_REWRITE	FILE_HASHCOMPONENT_TO_UPLOADEXISTING_COMPONENTCOMPONENT_TO_DOWNLOADEXISTING_OBJECT_TO_DELETEr   r$   r*   rB   rC   s   @r   rQ   rQ      sp     -+///,)   ! (,(=TN Nr   rQ   c                   @   ^  \ rS rSrSr     SU 4S jjrS rSrU =r$ )ProgressMessage   zMessage class for a file/object/component progress.

This class contains specific information about the current progress of a file,
cloud object or single component.
c
                    > [         [        U ]  U5        Xl        X l        X`l        X0l        XPl        X:H  U l        Xpl	        g)a!  Creates a ProgressMessage.

Args:
  size: Integer for total size of this file/component, in bytes.
  processed_bytes: Integer for number of bytes already processed from that
      specific component, which means processed_bytes <= size.
  src_url: FileUrl/CloudUrl representing the source file.
  message_time: Float representing when message was created (seconds since
      Epoch).
  dst_url: FileUrl/CloudUrl representing the destination file, or None
      for unary operations like hashing.
  component_num: Indicates the component number, if any.
  operation_name: Name of the operation that is being made over that
      component.
  process_id: Process ID that produced this message (overridable for
      testing).
  thread_id: Thread ID that produced this message (overridable for testing).
N)
r4   rx   r   ra   processed_bytesrb   r_   r`   rc   operation_name)r   ra   r{   r_   r   r`   rb   r|   r   r   r!   s             r   r   ProgressMessage.__init__   s?    8 
/4),7I*&LL,DM(r   c                    U R                   (       a  SU R                   -  OSnU R                  (       a  SU R                  -  OSnU R                  R                  < SU R                  < SU R
                  < SU R                  < SU R                  < SU< SU R                  < S	U< S
U R                  < SU R                  < S3$ )r   z'%s'Nr   , z, 'rh   z
, dst_url=rj   z, operation_name=r   r   r    )r`   r|   r!   r"   ra   r{   r_   r   rb   r   r   )r   dst_url_stringoperation_name_strings      r   r$   ProgressMessage.__str__  s     37,,h-DN+/+>+>4&&&D  ^^$$dii1E1E\\499nd6H6H"DOOT^^	E Fr   )rb   r`   rc   r|   r{   ra   r_   )NNNNNrA   rC   s   @r   rx   rx      s+     !"#)J
F 
Fr   rx   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )SeekAheadMessagei  a  Message class for results obtained by SeekAheadThread().

It estimates the number of objects and total size in case the task_queue
cannot hold all tasks at once (only used in large operations).
This class contains information about all the objects yet to be processed.
c                 D   > [         [        U ]  U5        Xl        X l        g)a-  Creates a SeekAheadMessage.

Args:
  num_objects: Number of total objects that the SeekAheadThread estimates.
  size: Total size corresponding to the sum of the size of objects iterated
      by SeekAheadThread.
  message_time: Float representing when message was created (seconds since
      Epoch).
N)r4   r   r   num_objectsra   )r   r   ra   r   r!   s       r   r   SeekAheadMessage.__init__$  s      

D*<8"Ir   c                     U R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < SU R                  < S3$ )r   r   r   r   r   r    )r!   r"   r   ra   r   r   r   r#   s    r   r$   SeekAheadMessage.__str__2  s<     ^^$$d&6&6		499__dnn. /r   )r   ra   rA   rC   s   @r   r   r     s    / /r   r   c                   6   ^  \ rS rSrSrSU 4S jjrS rSrU =r$ )ProducerThreadMessagei9  a  Message class for results obtained by calculations made on ProducerThread.

It estimates the number of objects and total size currently dealty by
task_queue. If the task_queue cannot support all objects at once, the
SeekAheadThread will be responsible for sending an accurate message.
c                 P   > [         [        U ]  U5        Xl        X l        X@l        g)a2  Creates a SeekAheadMessage.

Args:
  num_objects: Number of total objects that the task_queue has.
  size: Total size corresponding to the sum of the size of objects iterated
      by the task_queue
  message_time: Float representing when message was created (seconds since
      Epoch).
  finished: Boolean to indicate whether this is the final message from the
      ProducerThread. The difference is that this message displays
      the correct total size and number of objects, whereas the
      previous ones were periodic (on the number of files) updates.
N)r4   r   r   r   ra   rc   )r   r   ra   r   rc   r!   s        r   r   ProducerThreadMessage.__init__A  s%     

/="IMr   c           
          U R                   R                  < SU R                  < SU R                  < SU R                  < SU R
                  < S3
$ )r   r   r   ri   r    )r!   r"   r   ra   r   rc   r#   s    r   r$   ProducerThreadMessage.__str__T  s6     ^^$$d&6&6		499]] r   )rc   r   ra   )FrA   rC   s   @r   r   r   9  s    & r   r   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )PerformanceSummaryMessagei[  zMessage class to log PerformanceSummary parameters.

This class acts as a relay between a multiprocess/multithread situation and
the global status queue, from which the PerformanceSummary info gets consumed.
c                 8   > [         [        U ]  USSS9  X l        g)zCreates a PerformanceSummaryMessage.

Args:
  message_time: Float representing when message was created (seconds since
      Epoch).
  uses_slice: True if the command uses slice parallelism.
Nr0   )r4   r   r   
uses_slice)r   r   r   r!   s      r   r   "PerformanceSummaryMessage.__init__b  s*     

#T3L?C>B 4 D !Or   c                 n    U R                   R                  < SU R                  < SU R                  < S3$ )r   r   r   r    )r!   r"   r   r   r#   s    r   r$   !PerformanceSummaryMessage.__str__o  s)     ^^$$diiB Cr   )r   rA   rC   s   @r   r   r   [  s    !C Cr   r   )r)   
__future__r   r   r   r   r   r   apitools.base.py.exceptionsr   r8   six.moves.http_clientr   r9   objectr
   r-   rE   rL   rQ   rx   r   r   r   r+   r   r   <module>r      s   
 ' %  ' 	  G <OF O46OM 6Or5= 5 8m 8$KN- KN\6Fm 6Fr/} /:M DC Cr   