
    q&fB                     N    d dl Z 	 ddlmZ dZd ZddZy# e$ r	 ddlmZ Y w xY w)	    N   )bser)pybsers        c                     d}t        |      }|dkD  rK| j                  t        j                  |z  j	                  ||            }||dk(  r|S ||z  }||z  }|dkD  rK|S )zRead bytes from a file-like object

    @param fp: File-like object that implements read(int)
    @type fp: file

    @param buf: Buffer to read into
    @type buf: bytes

    @return: buf
    r   )lenreadintoctypesc_charfrom_buffer)fpbufoffset	remainingls        A/usr/lib/python3/dist-packages/hgext/fsmonitor/pywatchman/load.py_read_bytesr   )   so     FCI
a-KK2??VLM9QM!Q	 a- M    c                 b   t        j                  d      }t        t              }t         j                  |z  j                  |      }t        | |      }|t        |      k  ryt        j                  |      }|t        |      kD  rt        j                  ||       t         j                  |t        |      z
  z  j                  |t        |            }	t        | |	      }|t        |	      k  rt        d      t        j                  t         j                  |z  j                  |d      |||      S )at  Deserialize a BSER-encoded blob.

    @param fp: The file-object to deserialize.
    @type file:

    @param mutable: Whether to return mutable results.
    @type mutable: bool

    @param value_encoding: Optional codec to use to decode values. If
                           unspecified or None, return values as bytestrings.
    @type value_encoding: str

    @param value_errors: Optional error handler for codec. 'strict' by default.
                         The other most common argument is 'surrogateescape' on
                         Python 3. If value_encoding is None, this is ignored.
    @type value_errors: str
    i    Nzbser data ended earlyr   )r	   create_string_bufferr   EMPTY_HEADERr
   r   r   r   pdu_lenresizeRuntimeErrorloads)
r   mutablevalue_encodingvalue_errorsr   SNIFF_BUFFER_SIZEheaderread_len	total_lenbodys
             r   loadr#   A   s    $ 
%
%d
+CL)mm//<<SAF2v&H#f+S!I3s8c9%MMYV45BBS[D 2t$H#d)233::		"//Q7	 r   )TNN)r	    r   ImportErrorr   r   r   r#    r   r   <module>r'      s7   : !
 /0)?  ! !s    $$