
    gޘ                        d Z ddlZddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZmZmZmZmZmZmZ ddlmZ d	d
lmZ d	dlmZ d	dlmZ d	dlmZm Z m!Z!m"Z"m#Z# d	dl$m%Z%m&Z&m'Z' d	dl(m)Z)m*Z*m+Z+m,Z,m-Z- d	dl.m/Z/m0Z0  ed      Z1 e       Z2 edd	d	ejf                        Z4 edd	d	      Z5dee6e'f   fdZ7d Z8d Z9dddi fdZ:dldZ;dddi fdZ<dldZ=dddi fdZ>dldZ?dddi fdZ@dldZAdddi fd ZBdld!ZCdddi fd"ZDdld#ZEdddi fd$ZFdld%ZGdddi fd&ZHdld'ZIddi fd(ZJdmd)ZKdi fd*ZLd+ ZMdi fd,ZNd- ZOdi fd.ZPd/ ZQdi fd0ZRd1 ZSdi fd2ZTd3 ZUi d4e:d5e<d6eHd7e>d8e@d9eBd:eDd;eFd<eJd=eLd>eNd?ePd@eRdAeRdBeTdCeTdDeTZVi d4e;d5e=d6eId7e?d8eAd9eCd:eEd;eGd<eKd=eMd>eOd?eQd@eSdAeSdBeUdCeUdDeUZWdE ZXdi fdFZYdG ZZdH Z[dI Z\dJ Z]dK Z^dL Z_e\e]e^e_dMZ`dN Za	 ddOlbmcZc ecj                  Zeeae`dP<   dS Zi	 ddljZjeie`dT<   dU Zk	 ddllZmeke`dV<   dW ZndX Zo G dY dZ      Zp G d[ d\ee1         Zq G d] d^eqe&         Zr G d_ d`eqep         Zs	 	 	 	 	 	 dndaedbe%dcee%   ddetdeetdfe6dgetdhetde&fdiZudjee6ef   detfdkZvy# ef$ r: 	 ddlcZcecj                  Ze edQeh       eae`dP<   n# ef$ r  e-dPdR      e`dP<   Y nw xY wY w xY w# ef$ r  e-dTdT      e`dT<   Y w xY w# ef$ r  e-dVdV      e`dV<   Y w xY w)oz"Python code for reading AVRO files    N)datetimetimezone)Context)BytesIO)error)IOUnionOptionalGenericTypeVarIteratorDict)warn   )BinaryDecoder)AvroJSONDecoder)LOGICAL_READERS)extract_record_typeis_single_record_unionis_single_name_unionextract_logical_typeparse_schema)SchemaAvroMessageNamedSchemas)SchemaResolutionErrorMAGIC	SYNC_SIZEHEADER_SCHEMAmissing_codec_lib)NAMED_TYPES
AVRO_TYPESTi  )tzinforeturnc                      i i dS )N)writerreader r)       F/var/www/openai/venv/lib/python3.12/site-packages/fastavro/_read_py.py_default_named_schemasr,   -   s    B''r*   c                    t        | t              st        |t              ryt        | t              st        |t              r	 t        | ||      S | |k(  ry| dk(  r|dv ry| dk(  r|dv ry| dk(  r|dk(  ry| d	k(  r|d
k(  ry| d
k(  r|d	k(  ry|d   j                  |       }|d   j                  |      }||t        |||      S y# t        $ r Y yw xY w)NTFint)longfloatdoubler/   )r0   r1   r0   r1   stringbytesr'   r(   )
isinstancelistdictmatch_schemasr   getmatch_types)writer_typereader_typenamed_schemaswriter_schemareader_schemas        r+   r9   r9   1   s   +t$
;(E+t$
;(E	 k=II k!		+1L"L		;2E#E		K8$;		 [G%;		K8$;!(+//<M!(+//<M ]%>=-GG' % 		s   C 	CCc                     d|  d| }t        | t              r|S t        |t              r#|D ]  }t        | ||      s|c S  t        |      t        | t              r| d   }n| }t        |t              r|d   }n|}||cxk(  rdk(  rn nt        | d   |d   |      r|S ||cxk(  rdk(  rn nt        | d   |d   |      r|S |t
        v r|t
        v r}||cxk(  rdk(  r n n| d	   |d	   k7  rt        d|  d
| d      | d   j                  d      d   }|d   j                  d      d   }|j                  dg       }	||k(  s| d   |	v s||	v r6|S |t        vr|t
        v rt        ||d   |      r|d   S t        |||      r|S t        |      )NzSchema mismatch: z is not typemapvaluesarrayitemsfixedsizez size is different than z sizename.aliases)	r4   r5   r9   r   r6   r!   splitr8   r"   )
w_schemar_schemar<   	error_msgschemaw_typer_typew_unqual_namer_unqual_name	r_aliasess
             r+   r7   r7   M   s   #H:XhZ@I(D! 	Hd	# F8V];  (	22 h%f%FFh%f%FFV$u$8H-x/A=Qv((8G,hw.?O{"v'<*7*x/?8FCS/S+'z1I(SXY  %V,2237;M$V,2237;M Y3I.F#y0 I-:%&K*?68F#3]C''7O#I..r*   c                 "    | j                         S N	read_nulldecoderr=   r<   r>   optionss        r+   rX   rX           r*   c                 $    | j                          y rV   rW   rZ   r=   r<   s      r+   	skip_nullr_          r*   c                 "    | j                         S rV   read_booleanrY   s        r+   rc   rc      s     !!r*   c                 $    | j                          y rV   rb   r^   s      r+   skip_booleanre      s    r*   c                 "    | j                         S rV   read_intrY   s        r+   rh   rh      s     r*   c                 $    | j                          y rV   rg   r^   s      r+   skip_intrj      s    r*   c                 "    | j                         S rV   	read_longrY   s        r+   rm   rm      r\   r*   c                 $    | j                          y rV   rl   r^   s      r+   	skip_longro      r`   r*   c                 "    | j                         S rV   
read_floatrY   s        r+   rr   rr           r*   c                 $    | j                          y rV   rq   r^   s      r+   
skip_floatru          r*   c                 "    | j                         S rV   read_doublerY   s        r+   ry   ry      s       r*   c                 $    | j                          y rV   rx   r^   s      r+   skip_doubler{      s    r*   c                 "    | j                         S rV   
read_bytesrY   s        r+   r~   r~      rs   r*   c                 $    | j                          y rV   r}   r^   s      r+   
skip_bytesr      rv   r*   c                 F    | j                  |j                  dd            S )Nhandle_unicode_errorsstrict)r   )	read_utf8r8   rY   s        r+   r   r      s+     %kk*A8L   r*   c                 $    | j                          y rV   )r   r^   s      r+   	skip_utf8r      r`   r*   c                 .    |d   }| j                  |      S NrF   
read_fixed)rZ   r=   r<   r>   r[   rF   s         r+   r   r      s      Dd##r*   c                 0    |d   }| j                  |       y r   r   )rZ   r=   r<   rF   s       r+   
skip_fixedr      s     Dtr*   c                     |d   | j                            }|r9||d   vr2|j                  d      }|r|S |d   }| d|d    d| }t        |      |S )Nsymbolsdefaultz! not found in reader symbol list rG   z, known symbols: )	read_enumr8   r   )	rZ   r=   r<   r>   r[   symbolr   symlistmsgs	            r+   r   r     s}     9%g&7&7&9:F}Y'??##I.N#I.GH=mF>S=TTefmenoC',,Mr*   c                 $    | j                          y rV   )r   r^   s      r+   	skip_enumr     r`   r*   c           	          |rfd}nfd}g }| j                          | j                         D ]  }|j                   || |||              | j                          |S )Nc                 .    t        | |d   |d   |      S NrD   	read_datarZ   rL   rM   r[   r<   s       r+   item_readerzread_array.<locals>.item_reader%  s)    !! r*   c                 (    t        | |d   d |      S r   r   r   s       r+   r   zread_array.<locals>.item_reader0  s$    ! r*   )read_array_start
iter_arrayappendread_array_end)rZ   r=   r<   r>   r[   r   
read_itemsitems     `     r+   
read_arrayr     sn     		 J""$		
 % r*   c                     | j                          | j                         D ]  }t        | |d   |        | j                          y r   )r   r   	skip_datar   rZ   r=   r<   r   s       r+   
skip_arrayr   L  s@    ""$'=1=A % r*   c                     |rfd}nfd}i }| j                          | j                         D ]  }| j                         } || ||      ||<   ! | j                          |S )Nc                 .    t        | |d   |d         S NrB   r   rZ   rL   rM   r<   r[   s      r+   r   zread_map.<locals>.item_reader^  s)    "" r*   c                 (    t        | |d   d       S r   r   r   s      r+   r   zread_map.<locals>.item_readeri  s$    " r*   )read_map_startiter_mapr   read_map_end)	rZ   r=   r<   r>   r[   r   r   r   keys	     ` `    r+   read_mapr   U  sl     		 J  "!%g}mL
3 # r*   c                     | j                          | j                         D ]"  }| j                          t        | |d   |       $ | j	                          y r   )r   r   r   r   r   r   s       r+   skip_mapr     sL      "'=2MB # r*   c                 @   | j                         }||   }d }|rrd| d| }t        |t              s(t        |||      rt	        | ||||      }	nLt        |      |D ]"  }
t        ||
|      s|
}t	        | |||
|      }	 n t        |      t	        | ||d |      }	|j                  d      }|j                  d      }|j                  d      }|j                  d      }|rt        |      r|	S |r!t        |      t        v r|r|d   n|d   }||	fS |r-t        |      t        vr|r|d   |   d   n
|d	   |   d   }||	fS |rt        |      r|	S |rt        |      d
k(  r|r|d   n|d   }||	fS |r-t        |      t        vr|r|d   |   d   n
|d	   |   d   }||	fS |	S )Nzschema mismatch: z not found in return_record_name_overridereturn_record_namereturn_named_type_overridereturn_named_typerG   r(   r'   record)
read_indexr4   r5   r9   r   r   r8   r   r   r!   r"   r   )rZ   r=   r<   r>   r[   index
idx_schemaidx_reader_schemar   resultrO   r   r   r   r   schema_names                   r+   
read_unionr     s5     Eu%J!-}oN-.:}mD"!! ,C00'z6=A(.%&"%F  ( ,C007JtWM")++.K"L %9:!(-I!J$78!&:=&I	2:>+M):f%
6@R 	 V$$	2:>jP ! (#$56v>x(4V< 	
 V$$	$)?)N	 3J ?8 K):f%
6@R 	 V$$	 3J ?z Q ! (#$56v>x(4V< 	
 V$$r*   c                 D    | j                         }t        | ||   |       y rV   )r   r   )rZ   r=   r<   r   s       r+   
skip_unionr     s!     Eg}U+];r*   c                 n   i }|$|d   D ]  }t        | |d   |d|      ||d   <    |S i }i }|d   D ]&  }	|	||	d   <   |	j                  dg       D ]  }
|	||
<   	 ( |d   D ]W  }|j                  |d   |j                  |d               }|rt        | |d   ||d   |      ||d   <   Ht        | |d   |       Y t        |      t        |      kD  r_|d   D 	cg c]  }	|	d   	 }}	|j	                         D ]7  \  }}||vs||vsd|v r|d   ||d   <    d|d    d|d    }t        |       |S c c}	w )	a  A record is encoded by encoding the values of its fields in the order
    that they are declared. In other words, a record is encoded as just the
    concatenation of the encodings of its fields.  Field values are encoded per
    their schema.

    Schema Resolution:
     * the ordering of fields may be different: fields are matched by name.
     * schemas for fields with the same name in both records are resolved
         recursively.
     * if the writer's record contains a field with a name not present in the
         reader's record, the writer's value for that field is ignored.
     * if the reader's record schema has a field that contains a default value,
         and writer's schema does not have a field with the same name, then the
         reader should use the default value from its field.
     * if the reader's record schema has a field with no default value, and
         writer's schema does not have a field with the same name, then the
         field's value is unset.
    Nfieldsr@   rG   rJ   r   zNo default value for field z in )r   r8   r   lenrD   r   )rZ   r=   r<   r>   r[   r   fieldreaders_field_dictaliases_field_dictfaliasreaders_fieldwriter_fieldsf_namer   s                  r+   read_recordr     s   2 F"8,E$-f%F5=! -V ME  x(A,-qy)y"-,-"5) . )
 #8,E.22f"&&uV}5M 09&M!!&)1}V,- '5=-@ -" !"S[00=h0GH0G1QvY0GMH!3!9!9!;.63G E)05i0@uV}- ;E&M?$}]cOdNef3C88 "< M Is   D2c                 8    |d   D ]  }t        | |d   |        y )Nr   r@   )r   )rZ   r=   r<   r   s       r+   skip_recordr   )  s!    x('5=-8 )r*   nullbooleanr2   r.   r/   r0   r1   r3   rE   enumrC   rA   unionerror_unionr   r   requestc                     |dk(  r|dk(  s|dk(  rt        |       S |dk(  r|dk(  s|dk(  rt        |       S |dk(  r|dk(  r| j                         S |dk(  r|dk(  r| j                         S | S )Nr.   r0   r1   r/   r2   r3   )r0   encodedecode)datar:   r;   s      r+   maybe_promoter   W  s    e'![H%<;f'![H%<;h;'#9{{}g+"9{{}Kr*   c                    t        |      }|rt        |||      }t        j                  |      }|rW	  || ||||      }d|v r,t        |      }t        j                  |      }	|	r
 |	|||      S |t        ||t        |            S |S t        | |d   |   ||d   j                  |      |      S # t        $ r t        d| d| j                         w xY w)z/Read data from file object according to schema.zcannot read z from logicalTyper'   r(   )r   r7   READERSr8   StructErrorEOFErrorfor   r   r   r   )
rZ   r=   r<   r>   r[   record_type	reader_fnr   logical_typefns
             r+   r   r   f  s    &m4K%
 K(I		KD M)/>L $$\2B$}==$ {4G4VWWK(#K0(#''6
 	
  	K\+fWZZLIJJ	Ks   B0 0%Cc                     t        |      }t        j                  |      }|r || ||       y t        | |d   |   |       y )Nr'   )r   SKIPSr8   r   )rZ   r=   r<   r   r   s        r+   r   r     s?    %m4K		+&I'=-8'=2;?Or*   c                 J    | j                  t              |k7  rt        d      y)z=Skip an expected sync marker, complaining if it doesn't matchzexpected sync marker not foundN)readr   
ValueError)r   sync_markers     r+   	skip_syncr     s$    	wwy[(9:: )r*   c                 4    t        | j                               S )zRead block in "null" codec.)r   r~   )rZ   s    r+   null_read_blockr     s    7%%'((r*   c                 |    | j                         }t        t        j                  d      j	                  |            S )zRead block in "deflate" codec.i)r~   r   zlibdecompressobj
decompressrZ   r   s     r+   deflate_read_blockr     s3    D 4%%c*55d;<<r*   c                 ^    | j                         }t        t        j                  |            S )zRead block in "bzip2" codec.)r~   r   bz2r   r   s     r+   bzip2_read_blockr     s$    D3>>$'((r*   c                 v    t        |       }| j                  |      }t        t        j                  |            S rV   )rm   r   r   lzmar   rZ   lengthr   s      r+   xz_read_blockr     s0    wFf%D4??4())r*   )r   deflatebzip2xzc                     t        |       }| j                  |dz
        }| j                  d       t        t        |            S )N   )rm   r   r   snappy_decompressr   s      r+   snappy_read_blockr    s?    wFfqj)Dq$T*++r*   )snappyr  zbSnappy compression will use `cramjam` in the future. Please make sure you have `cramjam` installedcramjamc                     t        |       }| j                  |      }t        t        j                         j                         j                  |            S rV   )rm   r   r   	zstandardZstdDecompressorr   r   r   s      r+   zstandard_read_blockr
    sD    wFf%D9--/==?JJ4PQQr*   r  c                     t        |       }| j                  |      }t        t        j                  j                  |            S rV   )rm   r   r   lz4blockr   r   s      r+   lz4_read_blockr    s6    wFf%D399''-..r*   r  c              #   6  K   |d   }t         j                  |      }|st        d|       d}		 	 | j                         }	 ||       }
t        |	      D ]  }t        t        |
      ||||        t        | j                  |       Z# t        $ r Y yw xY ww)z"Return iterator over avro records.syncUnrecognized codec: r   N)
BLOCK_READERSr8   r   rm   r   ranger   r   r   r   )rZ   headercodecr=   r<   r>   r[   r   
read_blockblock_countblock_fois               r+   _iter_avro_recordsr    s      .K""5)J/w788K
	!++-K g&{#Ah'  $ 	'**k*#   		s)   .BB
 A	B
	BBBBc              #   v  K   |d   }t         j                  |      }|st        d|       	 | j                  j	                         }		 | j                         }
 ||       }t        | j                  |       | j                  j	                         |	z
  }t        ||
|||||	||	       |# t        $ r Y yw xY ww)z!Return iterator over avro blocks.r  r  N)	r  r8   r   r   tellrm   r   r   Block)rZ   r  r  r=   r<   r>   r[   r   r  offsetnum_block_recordsblock_bytesrF   s                r+   _iter_avro_blocksr!  '  s      .K""5)J/w788
"	 ' 1 1 3 !)'**k*zz 6)

 
	
   		s+   AB9	B* AB9*	B63B95B66B9c                   "    e Zd ZdZd Zd Zd Zy)r  a  An avro block. Will yield records when iterated over

    .. attribute:: num_records

        Number of records in the block

    .. attribute:: writer_schema

        The schema used when writing

    .. attribute:: reader_schema

        The schema used when reading (if provided)

    .. attribute:: offset

        Offset of the block from the beginning of the avro file

    .. attribute:: size

        Size of the block in bytes
    c
                     || _         || _        || _        || _        || _        || _        || _        || _        |	| _        y rV   )	bytes_num_recordsr  r>   r=   _named_schemasr  rF   r[   )
selfr$  r%  r  r>   r=   r<   r  rF   r[   s
             r+   __init__zBlock.__init__i  sG     &
**+	r*   c              #      K   t        | j                        D ]N  }t        t        | j                        | j
                  | j                  | j                  | j                         P y wrV   )	r  r%  r   r   r$  r=   r&  r>   r[   )r'  r  s     r+   __iter__zBlock.__iter__  sV     t''(Adkk*""##""  )s   A(A*c                     dt        | j                         d| j                   dz   d| j                   d| j                   d| j
                   z   S )NzAvro block: z bytes, z
 records, zcodec: z, position +)r   r$  r%  r  r  rF   r'  s    r+   __str__zBlock.__str__  s[    3t{{+,H5!!"*-.

|;t{{m1TYYKHI	
r*   N)__name__
__module____qualname____doc__r(  r*  r.  r)   r*   r+   r  r  Q  s    .,
r*   r  c                   L    e Zd Zdi fdZd Zed        Zdee   fdZ	defdZ
y)file_readerNc                     t        |t              r|| _        nt        |      | _        t	               | _        |r!t        || j
                  d   d      | _        nd | _        || _        d | _	        y )Nr(   F)_write_hint)
r4   r   rZ   r   r,   r&  r   r>   r[   _elems)r'  fo_or_decoderr>   r[   s       r+   r(  zfile_reader.__init__  sh     m_5(DL )7DL46!-t228<%"D
 "&Dr*   c                 @   	 t        | j                  t        | j                  d | j                        | _        | j
                  d   j                         D ci c]  \  }}||j                          c}}| _
        t        j                  | j                  d         | _        | j                  j                  dd      | _        | j                   d}nd}t#        | j                  | j                  d   dd|	      | _        y # t        $ r t        d      w xY wc c}}w )
Nz(cannot read header - is it an avro file?metazavro.schemaz
avro.codecr   TFr'   )r6  _force_ignore_default_error)r   rZ   r   r&  r[   _headerr   r   rD   r   metadatajsonloads_schemar8   r  r>   r   r=   )r'  kvignore_default_errors       r+   _read_headerzfile_reader._read_header  s   		I$##DL 48<<3G3M3M3OP3O41aAHHJ3OPzz$--">?]]&&|V<
 )#' #(  *LL)"6
+  	IGHH	I Qs   6D DDc                 N    dd l }|j                  dt               | j                  S )Nr   z@The 'schema' attribute is deprecated. Please use 'writer_schema')warningsr   DeprecationWarningrA  )r'  rG  s     r+   rO   zfile_reader.schema  s#    N	
 ||r*   r%   c                 >    | j                   st        | j                   S rV   )r7  NotImplementedErrorr-  s    r+   r*  zfile_reader.__iter__  s    {{%%{{r*   c                 ,    t        | j                        S rV   )nextr7  r-  s    r+   __next__zfile_reader.__next__  s    DKK  r*   )r/  r0  r1  r(  rE  propertyrO   r   r#   r*  rM  r)   r*   r+   r4  r4    sE     	.$
L  (1+ 
!! !r*   r4  c                   ^     e Zd ZdZ	 	 	 	 	 	 d
deeef   dee   de	de	de
de	de	f fd	Z xZS )r(   a	  Iterator over records in an avro file.

    Parameters
    ----------
    fo
        File-like object to read from
    reader_schema
        Reader schema
    return_record_name
        If true, when reading a union of records, the result will be a tuple
        where the first value is the name of the record and the second value is
        the record itself
    return_record_name_override
        If true, this will modify the behavior of return_record_name so that
        the record name is only returned for unions where there is more than
        one record. For unions that only have one record, this option will make
        it so that the record is returned by itself, not a tuple with the name.
    return_named_type
        If true, when reading a union of named types, the result will be a tuple
        where the first value is the name of the type and the second value is
        the record itself
        NOTE: Using this option will ignore return_record_name and
        return_record_name_override
    return_named_type_override
        If true, this will modify the behavior of return_named_type so that
        the named type is only returned for unions where there is more than
        one named type. For unions that only have one named type, this option
        will make it so that the named type is returned by itself, not a tuple
        with the name
    handle_unicode_errors
        Default `strict`. Should be set to a valid string that can be used in
        the errors argument of the string decode() function. Examples include
        `replace` and `ignore`


    Example::

        from fastavro import reader
        with open('some-file.avro', 'rb') as fo:
            avro_reader = reader(fo)
            for record in avro_reader:
                process_record(record)

    The `fo` argument is a file-like object so another common example usage
    would use an `io.BytesIO` object like so::

        from io import BytesIO
        from fastavro import writer, reader

        fo = BytesIO()
        writer(fo, schema, records)
        fo.seek(0)
        for record in reader(fo):
            process_record(record)

    .. attribute:: metadata

        Key-value pairs in the header metadata

    .. attribute:: codec

        The codec used when writing

    .. attribute:: writer_schema

        The schema used when writing

    .. attribute:: reader_schema

        The schema used when reading (if provided)
    r   r>   r   r   r   r   r   c           	      V    |||||d}t         
   |||       t         j                  t              r j                  j                   j                   j                  d           j                   _        d  _         j                  d    j                  d<   i  j                  d<    fd}	 |	        _	        y  j                          t         j                   j                   j                   j                   j                   j                   j                         _	        y )Nr   r   r   r   r   r(   r'   c               3   $  K    j                   j                  sut         j                    j                   j                   j
                   j                          j                   j                           j                   j                  sty y wrV   )rZ   doner   r=   r&  r>   r[   drainr-  s   r+   r7  zreader.__init__.<locals>._elemsF  sk     ,,++#**++**  LL&&( ,,++s   B
BB)superr(  r4   rZ   r   	configurer>   r&  r=   r7  rE  r  r=  r  r[   )r'  r   r>   r   r   r   r   r   r[   r7  	__class__s   `         r+   r(  zreader.__init__+  s    #5+F%:!2*D
 	]G4dllO4LL""4#5#5t7J7J87TU!%!3!3D!%D,0,?,?,ID),.D)	) !(DK ,

""##""DKr*   NFFr   FF)r/  r0  r1  r2  r	   r   r   r
   r   boolstrr(  __classcell__rW  s   @r+   r(   r(     s{    FV +/#(,1%-"'+03"o%&3  '3 !	3
 &*3  #3  3 %)3 3r*   r(   c                   T     e Zd ZdZ	 	 	 	 	 	 d
dedee   dededededef fd	Z	 xZ
S )block_readera?  Iterator over :class:`.Block` in an avro file.

    Parameters
    ----------
    fo
        Input stream
    reader_schema
        Reader schema
    return_record_name
        If true, when reading a union of records, the result will be a tuple
        where the first value is the name of the record and the second value is
        the record itself
    return_record_name_override
        If true, this will modify the behavior of return_record_name so that
        the record name is only returned for unions where there is more than
        one record. For unions that only have one record, this option will make
        it so that the record is returned by itself, not a tuple with the name.
    return_named_type
        If true, when reading a union of named types, the result will be a tuple
        where the first value is the name of the type and the second value is
        the record itself
        NOTE: Using this option will ignore return_record_name and
        return_record_name_override
    return_named_type_override
        If true, this will modify the behavior of return_named_type so that
        the named type is only returned for unions where there is more than
        one named type. For unions that only have one named type, this option
        will make it so that the named type is returned by itself, not a tuple
        with the name
    handle_unicode_errors
        Default `strict`. Should be set to a valid string that can be used in
        the errors argument of the string decode() function. Examples include
        `replace` and `ignore`


    Example::

        from fastavro import block_reader
        with open('some-file.avro', 'rb') as fo:
            avro_reader = block_reader(fo)
            for block in avro_reader:
                process_block(block)

    .. attribute:: metadata

        Key-value pairs in the header metadata

    .. attribute:: codec

        The codec used when writing

    .. attribute:: writer_schema

        The schema used when writing

    .. attribute:: reader_schema

        The schema used when reading (if provided)
    r   r>   r   r   r   r   r   c           	         |||||d}t         	|   |||       | j                          t        | j                  | j
                  | j                  | j                  | j                  | j                  | j                        | _        y )NrQ  )rU  r(  rE  r!  rZ   r=  r  r=   r&  r>   r[   r7  )
r'  r   r>   r   r   r   r   r   r[   rW  s
            r+   r(  zblock_reader.__init__  s}     #5+F%:!2*D
 	]G4'LLLLJJLL
r*   rX  )r/  r0  r1  r2  r   r
   r   rY  rZ  r(  r[  r\  s   @r+   r^  r^  a  sp    :~ +/#(,1%-"'+0

  '
 !	

 &*
  #
  
 %)
 
r*   r^  r   r=   r>   r   r   r   r   r   c                     ||k(  rd}t               }t        ||d         }|rt        ||d         }t        |       }	|||||d}
t        |	||||
      S )a  Reads a single record written using the
    :meth:`~fastavro._write_py.schemaless_writer`

    Parameters
    ----------
    fo
        Input stream
    writer_schema
        Schema used when calling schemaless_writer
    reader_schema
        If the schema has changed since being written then the new schema can
        be given to allow for schema migration
    return_record_name
        If true, when reading a union of records, the result will be a tuple
        where the first value is the name of the record and the second value is
        the record itself
    return_record_name_override
        If true, this will modify the behavior of return_record_name so that
        the record name is only returned for unions where there is more than
        one record. For unions that only have one record, this option will make
        it so that the record is returned by itself, not a tuple with the name.
    return_named_type
        If true, when reading a union of named types, the result will be a tuple
        where the first value is the name of the type and the second value is
        the record itself
        NOTE: Using this option will ignore return_record_name and
        return_record_name_override
    return_named_type_override
        If true, this will modify the behavior of return_named_type so that
        the named type is only returned for unions where there is more than
        one named type. For unions that only have one named type, this option
        will make it so that the named type is returned by itself, not a tuple
        with the name
    handle_unicode_errors
        Default `strict`. Should be set to a valid string that can be used in
        the errors argument of the string decode() function. Examples include
        `replace` and `ignore`


    Example::

        parsed_schema = fastavro.parse_schema(schema)
        with open('file', 'rb') as fp:
            record = fastavro.schemaless_reader(fp, parsed_schema)

    Note: The ``schemaless_reader`` can only read a single record.
    Nr'   r(   rQ  )r,   r   r   r   )r   r=   r>   r   r   r   r   r   r<   rZ   r[   s              r+   schemaless_readerra    s    r %-C-EM h0GHM$]M(4KLBG 1'B!6.&@G  r*   path_or_bufferc                     t        | t              rt        | d      }d}n| }d}	 |j                  t	        t
                    }|t
        k(  |r|j                          S S # |r|j                          w w xY w)a  Return True if path (or buffer) points to an Avro file. This will only
    work for avro files that contain the normal avro schema header like those
    create from :func:`~fastavro._write_py.writer`. This function is not intended
    to be used with binary data created from
    :func:`~fastavro._write_py.schemaless_writer` since that does not include the
    avro header.

    Parameters
    ----------
    path_or_buffer
        Path to file
    rbTF)r4   rZ  openr   r   r   close)rb  fprf  r  s       r+   is_avrorh    sj     .#&.$'U$HHJ 5HHJ s   &A A4)NNrV   rX  )wr2  r   r?  r   r   r   r   decimalr   ior   structr   r   typingr   r	   r
   r   r   r   r   rG  r   io.binary_decoderr   io.json_decoderr   logical_readersr   rO   r   r   r   r   r   typesr   r   r   _read_commonr   r   r   r   r    constr!   r"   r#   decimal_contextutcepochepoch_naiverZ  r,   r9   r7   rX   r_   rc   re   rh   rj   rm   ro   rr   ru   ry   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  decompress_rawr  ImportErrorr   rH  r
  r  r  	lz4.blockr  r  r!  r  r4  r(   r^  rY  ra  rh  r)   r*   r+   <module>rz     s   (     '   ' H H H  , , ,  5 4  +CL)q!HLL1tQ"(S,%6 7 (83/p  "     !   	 $ & -` 'T Nb< FR9

I| i 
8	
 I Z k Z Z I Z 
8 Z : k  [!" {#(	
I	|	 i	 
8		
 I	 Z	 k	 Z	 Z	 I	 Z	 
8	 Z	 :	 k	  [!	" {#	*& 0
fP;)
=)* !
	,0-- 0M(R6 "6M+/* *M%"+J'
T=
 =
@N!'!* N!b|[% |~Z
;u% Z
@ '+$(-!)#',S
SS F#S 	S
 "&S S S !%S SlE#r'N t   44"--p	
 #4h  I"3Hi"HhI42  M!2;!LM+M  ;,UE:M%;sZ   -J K K KJ+%K+J?<K>J??KKKKK32K3