U
    Vc'                     @   s   d Z ddlZddlZddlmZ ddlmZ dZdZdZ	dZ
dd Zdd	 Zd
d Zdd ZdZdZdZdd Zdd Zdd ZG dd dZdS )z1A wrapper for TensorFlow SWIG-generated bindings.    N   )errors)gfilec                 C   s   dS Nr    )attrr   r   X/tmp/pip-unpacked-wheel-g8kmtpbc/tensorboard/compat/tensorflow_stub/pywrap_tensorflow.py__getattr__   s    r	   c                   C   s   dS r   r   r   r   r   r   TF_bfloat16_type#   s    r
   c                 C   s(   t t| }t |d? t |d> B d S )N      l   jE )u32crc32c)dataxr   r   r   masked_crc32c'   s    r   c                 C   s   | d@ S )N    r   )r   r   r   r   r   ,   s    r   (   r   l   d l   pvB iPl   5 i5i&l   d) l   X i۲xi8(kl   ;+3 iCMl   LP~ l   '?X i$<^io^l   lDjD l   7b i4l   pP/ isӯ%i 6l   #)	 l   5 ihiW{l   Tl i]l   ^ l   HxLx iKMNiގ l   % l   )~ i*}3l   NN iLi6il   5jh l   VT iUXi_Kl   %hr iAml   B+? l   1 i~iI0l   J l   F9# iE#l   ^n i]iYBl   Z-RH l   ~tt i}QHia[l   bR ia}l   b l   v79 iuni{Al   !f l   Km@ iH+Rl   
 i	tiTgl   Wyb+ l   sED ip9i5*l   61 il8l   oQ| l   "Z i!hi%Ql   YF l   $*=` i')uBl   M~- idi;=wl   8> l   7 i)i:l   qX ifl    \ l   ez i6ibal   aZ' l   c i`rl   }L i~7TitgGl   wj l   K?V iHtiZ$
l   Y8p i\,l   _= l   E,| iF?iTql   W l   $F! ibl   Cl i@iDi9Wl   0J l   v i*	i5|zl   6#P iݛ<l   ` l   *k; i)h/l   x; i{piKcl   HM# iglEl   d/n l   \H i_<Vic/l   `t l   @(R iCl   tk iw=i_.l   \9 l   |Q% i`isl    ik2Ul   hN l   h ibFiؤql   '4T l   /Tr i,W!l   3? iİ-i0C>l   3@w l   5D i6 PiQpCl   RF6b i"el   !u/ l   NR	 iMсvii(l   jn5 l   S i;l   vz^ iuci
3l   	x l   r*d i~@i>.Sl   =B iul   f l   !i) i"fi*8l   )O l   Z3 iٜ+l   =~ i>=iml   NX l   & iǥ1i3V"l   0U! i۱l   2l l   ,AYJ i/BGi~TIl   }v l   P iZl   i ij|iol   <; l   a' ib!i\2l   _ ivIl   uEL l   Cj i@id
Yl   g:V l   Icp iJZJl   {. = ixli^l   ] l   (aF i+[il   [` i?$l   <- l   O" i7iil   s7 l   "  i!zl   g\ i\i=HOl   >Gz l   uof iviUl   }@ ij4l   i{> l   + i'i7yl   4 l   MG1 iNjl    [| i#FLiR_l   QSZ r   c                 C   sd   t |tjks|jdkr&td|}n|}| tN } |D ]$}| |A d@ }t| | d? A t@ } q6| tA S )zUpdate CRC-32C checksum with data.

    Args:
      crc: 32-bit checksum to update as long.
      data: byte array, string or iterable over bytes.
    Returns:
      32-bit updated CRC-32C as long.
    r   B      )typearrayitemsize_MASK	CRC_TABLE)crcr   bufbZtable_indexr   r   r   
crc_update{   s    
r   c                 C   s   | t @ S )zFinalize CRC-32C checksum.

    This function should be called as last step of crc calculation.
    Args:
      crc: 32-bit checksum as long.
    Returns:
      finalized 32-bit checksum as long
    )r   )r   r   r   r   crc_finalize   s    	r   c                 C   s   t tt| S )zCompute CRC-32C checksum of the data.

    Args:
      data: byte array, string or iterable over bytes.
    Returns:
      32-bit CRC-32C checksum of data as long.
    )r   r   CRC_INIT)r   r   r   r   r      s    r   c                   @   s6   e Zd ZdddZdd Zdd Zd	d
 Zdd ZdS )PyRecordReader_NewNr   c                 C   s   |d krt d d dt|s4t d d d||rFt d d d|rXt d d d|| _|| _|| _|| _	d | _
t| jd| _d| _d| _d S )Nz(No filename provided, cannot read Eventsz&{} does not point to valid Events filez+start offset not supported by compat readerz*compression not supported by compat readerrb    r   )r   ZNotFoundErrorr   existsformatZUnimplementedErrorfilenamestart_offsetcompression_typestatus
curr_eventZGFilefile_handle_buffer_buffer_pos)selfr&   r'   r(   r)   r   r   r   __init__   s@      
    zPyRecordReader_New.__init__c                 C   s4  d| _ d | _| d}|s(td d dt|dk r>| dtd|}| d}t|dk rj| dtd|}t	|}||d krt
d d d	| jt|d }| |}t||k r| d
t	|}| d}	t|	dk r| dtd|	}
||
d kr$t
d d d| j|| _d| _d S )Nr   r   zNo more events to readheaderz<Q   z
header crcz<Iz{} failed header crc32 checkr   zdata crcz{} failed event crc32 checkr#   )r-   r*   _readr   ZOutOfRangeErrorlen_truncation_errorstructunpackr   DataLossErrorr%   r&   intr,   )r.   
header_strr0   Zcrc_header_strZ
crc_headerZheader_crc_calcZ
header_lenZ	event_strZevent_crc_calcZcrc_event_strZ	crc_eventr   r   r   GetNext   sH    



  





zPyRecordReader_New.GetNextc                 C   st   | j | j| j|  }|  jt|7  _|t|8 }|dkrp| j|}||7 }|  j |7  _ |  jt|7  _|S )a"  Read up to n bytes from the underlying file, with buffering.

        Reads are satisfied from a buffer of previous data read starting at
        `self._buffer_pos` until the buffer is exhausted, and then from the
        actual underlying file. Any new data is added to the buffer, and
        `self._buffer_pos` is advanced to the point in the buffer past all
        data returned as part of this read.

        Args:
          n: non-negative number of bytes to read

        Returns:
          bytestring of data read, up to n bytes
        r   )r,   r-   r3   r+   read)r.   nresultZnew_datar   r   r   r2      s    zPyRecordReader_New._readc                 C   s   t d d d| j|S )Nz{} has truncated record in {})r   r7   r%   r&   )r.   sectionr   r   r   r4     s
    z$PyRecordReader_New._truncation_errorc                 C   s   | j S )N)r*   )r.   r   r   r   record  s    zPyRecordReader_New.record)Nr   NN)__name__
__module____qualname__r/   r:   r2   r4   r?   r   r   r   r   r!      s          
!4r!   )__doc__r   r5    r   ior   ZTFE_DEVICE_PLACEMENT_WARNZ%TFE_DEVICE_PLACEMENT_SILENT_FOR_INT32ZTFE_DEVICE_PLACEMENT_SILENTZTFE_DEVICE_PLACEMENT_EXPLICITr	   r
   r   r   r   r    r   r   r   r   r!   r   r   r   r   <module>   s&   E