+
    ?i                        R t ^ RIHtHtHt ^ RIt^ RIt^ RIt^ RIt^ RI	t	^ RI
t
^ RIt^ RIt^ RIt^ RIHt ]P                   ! ]4      tRtRP)                  R ] 4       4      t]P,                  ^ ,          ^8  t]'       d   ]t]t]t]t]tM)]P@                  ! 4        ]!t]"t]!t]]#3t]]PH                  3t]
PJ                  t&]
PN                  t(R t)R t*R t+R	 t, ! R
 R]-4      t. ! R R]-4      t/ ! R R]/4      t0 ! R R]-4      t1RR lt2RR lt3RR lt4RR lt5]4t6]2t7 ! R R]-4      t8 ! R R]84      t9 ! R R]84      t:]9]:.t;]R8X  d   ^ RI<t<]<Pz                  ! 4        R# R# )a!  
Python implementation of the Binary Structured Data Format (BSDF).

BSDF is a binary format for serializing structured (scientific) data.
See http://bsdf.io for more information.

This is the reference implementation, which is relatively relatively
sophisticated, providing e.g. lazy loading of blobs and streamed
reading/writing. A simpler Python implementation is available as
``bsdf_lite.py``.

This module has no dependencies and works on Python 2.7 and 3.4+.

Note: on Legacy Python (Python 2.7), non-Unicode strings are encoded as bytes.
)absolute_importdivisionprint_functionN)BytesIO.c              #   8   "   T F  p\        V4      x  K  	  R # 5iN)str).0is   & S/var/www/html/photoedit/myenv/lib/python3.14/site-packages/imageio/plugins/_bsdf.py	<genexpr>r   0   s     /w!s1vvws   c                B    V ^8:  d   \        RV 4      # \        R^V 4      # )z?Encode an unsigned integer into a variable sized blob of bytes.<B<BQ)spack)xs   &r   lencoder   J   s(     	CxT1~ UC##    c                    \        RV P                  ^4      4      ^ ,          pV^8X  d#   \        RV P                  ^4      4      ^ ,          pV# )z'Decode an unsigned integer from a file.r   <Q)	strunpackread)fns   & r   	lendecoder   Y   s@    $q	"1%ACxdAFF1I&q)Hr   c                    VeB   VP                  R4      pV P                  4       \        \        V4      4      ,           V,           # V # )z9Encode the type identifier, with or without extension id.UTF-8)encodeupperr   len)bext_idbbs   && r   encode_type_idr$   a   s:    ]]7#wwy73r7++b00r   c                    \        V \        4      ;'       dH    \        P                  ! RV \        P                  4      ;'       d    \        P                  ! RV 4      RJ # )z8Use of str.isidentifier() for Legacy Python, but slower.z^\w+$z^[0-9]N)
isinstancestring_typesrematchUNICODE)ss   &r   _isidentifierr,   j   sN     	1l# 	+ 	+HHXq"**-	+ 	+HHY"d*r   c                   h   a  ] tR t^tt o RtRR ltRR ltR tR tR t	R t
R	 tR
 tR tR tRtV tR# )BsdfSerializera"  Instances of this class represent a BSDF encoder/decoder.

It acts as a placeholder for a set of extensions and encoding/decoding
options. Use this to predefine extensions and options for high
performance encoding/decoding. For general use, see the functions
`save()`, `encode()`, `load()`, and `decode()`.

This implementation of BSDF supports streaming lists (keep adding
to a list after writing the main file), lazy loading of blobs, and
in-place editing of blobs (for streams opened with a+).

Options for encoding:

* compression (int or str): ``0`` or "no" for no compression (default),
  ``1`` or "zlib" for Zlib compression (same as zip files and PNG), and
  ``2`` or "bz2" for Bz2 compression (more compact but slower writing).
  Note that some BSDF implementations (e.g. JavaScript) may not support
  compression.
* use_checksum (bool): whether to include a checksum with binary blobs.
* float64 (bool): Whether to write floats as 64 bit (default) or 32 bit.

Options for decoding:

* load_streaming (bool): if True, and the final object in the structure was
  a stream, will make it available as a stream in the decoded object.
* lazy_blob (bool): if True, bytes are represented as Blob objects that can
  be used to lazily access the data, and also overwrite the data if the
  file is open in a+ mode.
Nc                    / V n         / V n        Vf   \        pV F  pV P                  V4       K  	  V P                  ! R/ VB  R # )N )_extensions_extensions_by_clsstandard_extensionsadd_extension_parse_options)self
extensionsoptions	extensions   &&, r   __init__BsdfSerializer.__init__   sF    "$,J#Iy) $&g&r   c                2   \        V\        4      '       d)   R ^ R^R^/pVP                  VP                  4       V4      pVR9  d   \	        R4      hWn        \        V4      V n        \        V4      V n        \        V4      V n	        \        V4      V n
        R# )nozlibbz2z3Compression must be 0, 1, 2, "no", "zlib", or "bz2"N)          )r&   r'   getlower	TypeError_compressionbool_use_checksum_float64_load_streaming
_lazy_blob)r6   compressionuse_checksumfloat64load_streaming	lazy_blobms   &&&&&& r   r5   BsdfSerializer._parse_options   s     k<00q&!UA.A%% 1 1 3[AKi'TUU' ",/W  $N3y/r   c                   \        V\        4      '       d   \        V\        4      '       g   \	        R4      hV! 4       pVP
                  p\        V\        4      '       g   \	        R4      h\        V4      ^ 8X  g   \        V4      ^8  d   \        R4      hW0P                  9   d   \        P                  RV,          4       VP                  pV'       g   . pM"\        V\        \        34      '       d   TpMV.pV F$  p\        V\        4      '       d   K  \	        R4      h	  V F  pW2P                   3V P"                  V&   K  	  W P                  V&   V# )zqAdd an extension to this serializer instance, which must be
a subclass of Extension. Can be used as a decorator.
z*add_extension() expects a Extension class.Extension name must be str.z<Extension names must be nonempty and shorter than 251 chars.zABSDF warning: overwriting extension "%s", consider removing firstz Extension classes must be types.)r&   type
issubclass	ExtensionrE   namer	   r    	NameErrorr1   loggerwarningclstuplelist
classtypesr   r2   )r6   extension_classr9   rX   r\   clsss   &&    r   r4   BsdfSerializer.add_extension   s-    --*_i2X2XHII#%	 ~~$$$9::t9>SY_Q  ###NN*,01 mmDeT]++D5DCc:.. BCC 
 C+/1A1A+AD##C( !*r   c                j   \        V\        4      '       g   \        R4      hWP                  9   d   V P                  P	                  V4       \        V P                  P                  4       4       F?  pV P                  V,          ^ ,          V8X  g   K$  V P                  P	                  V4       KA  	  R# )z&Remove a converted by its unique name.rT   N)r&   r	   rE   r1   popr^   r2   keys)r6   rX   r\   s   && r   remove_extensionBsdfSerializer.remove_extension   s    $$$9::###  &//4467C&&s+A.$6''++C0 8r   c                
   \         pVf   VP                  V! RV4      4       R# VRJ d   VP                  V! RV4      4       R# VRJ d   VP                  V! RV4      4       R# \        V\        4      '       di   RTu;8:  d   R8:  d/   M M+VP                  V! RV4      \	        R	V4      ,           4       R# VP                  V! R
V4      \	        RV4      ,           4       R# \        V\
        4      '       di   V P                  '       d,   VP                  V! RV4      \	        RV4      ,           4       R# VP                  V! RV4      \	        RV4      ,           4       R# \        V\        4      '       dV   VP                  R4      pVP                  V! RV4      \        \        V4      4      ,           4       VP                  V4       R# \        V\        \        34      '       dP   VP                  V! RV4      \        \        V4      4      ,           4       V F  pV P                  WVR4       K  	  R# \        V\        4      '       d   VP                  V! RV4      \        \        V4      4      ,           4       VP                  4        F  w  r\         '       d   VP#                  4       '       g   Q hM\%        V4      '       g   Q hVP                  R4      p	VP                  \        \        V	4      4      4       VP                  V	4       V P                  WVR4       K  	  R# \        V\&        4      '       dM   VP                  V! RV4      4       \)        W P*                  V P,                  R7      p
V
P/                  V4       R# \        V\(        4      '       d,   VP                  V! RV4      4       VP/                  V4       R# \        V\0        4      '       d   VP2                  R8w  d   \5        R4      h\        V\6        4      '       d,   VP                  V! RV4      \	        R^^ 4      ,           4       M\9        R4      h\        V4      ^ 8  d   \5        R4      hVP;                  V4       VP=                  WP                  V P>                  4       R# Ve   \5        RV,          4      hV P@                  PC                  VPD                  R4      pVfL   V PF                  P                  4        F+  w  rVPI                  W4      '       g   K  WP                  3p M	  RpVe   Vw  rV P                  W! W4      W>4       R# Rp\9        VVPD                  PJ                  ,          4      h)zMain encoder function.N   vT   yF   ni     hh   i<q   d<d   f<fr      s   l   m   b)rL   rM   wz$Cannot serialize a read-mode stream.r   zOnly ListStream is supportedz"Can only have one stream per file.zExtension %s wronfully encodes object to another extension object (though it may encode to a list/dict that contains other extension objects).zJClass %r is not a valid base BSDF type, nor is it handled by an extension.i )&r$   writer&   integer_typesr   floatrI   unicode_typesr   r   r    r^   r]   _encodedictitemsPY3isidentifierr,   bytesBlobrF   rH   _to_file
BaseStreammode
ValueError
ListStreamrE   append	_activate_decoder2   rC   	__class__r1   r)   __name__)r6   r   valuestreamsr"   r   r#   vkeyname_bblobexrX   cext_id2extension_encodets   &&&&&            r   r}   BsdfSerializer._encode   s   =GGAdFO$d]GGAdFO$e^GGAdFO$}--'%'$%U*;;<$%e*<<=u%%}}}$%e*<<=$%e*<<=}--g&BGGAdFOgc"g&667GGBKe}--GGAdFOgc%j&99:Q7D1 t$$GGAdFOgc%j&99:++-3++----(----G,F,-Q7D1 ( u%%GGAdFO$#4#44CUCUD MM!t$$GGAdFO$NN1z**zzS  !GHHE:..$%sA*>>? >?? 7|a !EFFNN5!OOA||T\\:! >@FG  ((,,U__dCBz#//557GDwwt++!88^  8
 B~,.)Q 0 =wP/   EOO$<$< <==r   c                	   VP                  ^4      pVP                  4       pV'       g   \        4       hW#8w  dD   \        RVP                  ^4      4      ^ ,          pVP                  V4      P	                  R4      pMRpVR8X  d   RpEMVR8X  d   RpEMVR8X  d   RpEMVR	8X  d%   \        R
VP                  ^4      4      ^ ,          pEMVR8X  d%   \        RVP                  ^4      4      ^ ,          pEMiVR8X  d%   \        RVP                  ^4      4      ^ ,          pEM>VR8X  d%   \        RVP                  ^4      4      ^ ,          pEMVR8X  dn   \        RVP                  ^4      4      ^ ,          pV^8X  d#   \        RVP                  ^4      4      ^ ,          pVP                  V4      P	                  R4      pEMVR8X  EdK   \        RVP                  ^4      4      ^ ,          pV^8  d   V^8H  p\        RVP                  ^4      4      ^ ,          pV P
                  '       d>   \        V'       d   TMR4      pVP                  WP                  V P                  4       EMV'       d+   \        V4       U	u. uF  qP                  V4      NK  	  pp	EM. p  VP                  V P                  V4      4       K#  V^8X  d#   \        RVP                  ^4      4      ^ ,          p\        V4       U	u. uF  qP                  V4      NK  	  pp	EMMVR8X  d   \        4       p\        RVP                  ^4      4      ^ ,          pV^8X  d#   \        RVP                  ^4      4      ^ ,          p\        V4       F  p	\        RVP                  ^4      4      ^ ,          p
V
^8X  d#   \        RVP                  ^4      4      ^ ,          p
V
^ 8  g   Q hVP                  V
4      P	                  R4      pV P                  V4      Wk&   K  	  MWVR8X  d?   V P                  '       d   \        VR34      pM0\        VR34      pVP                  4       pM\!        RV,          4      hVeP   V P"                  P%                  VR4      pVe   VP	                  W4      pV# \&        P)                  RV,          4       V# u up	i   \         d     Lgi ; iu up	i )zMain decoder function.r   r   Nri   rj   Trk   Frl   z<hrn   ro   rr   rs   rp   rq   rt   r   ru   rrv   rw   zParse error %rz'BSDF warning: no extension found for %r)r   rD   EOFErrorr   decoderJ   r   r   r}   r   ranger   r~   rK   r   	get_bytesRuntimeErrorr1   rC   rZ   r[   )r6   r   charr   r   r"   r   n_sclosedr   n_namerX   r   r9   s   &&            r   r   BsdfSerializer._decodeD  s    vvayJJL *Y$q	*1-AVVAY%%g.FF9E$YE$YE$YdAFF1I.q1E$YdAFF1I.q1E$YdAFF1I.q1E$YdAFF1I.q1E$YD!&&),Q/CczaffQi03FF3K&&w/E$Y$q	*1-ACxcdAFF1I.q1'''&Fq<EOOA||T\\B6;Ah?h\\!_hE?EE"!LLa9
 8!$q	215A27(;(Qa(;$YFE$q	*1-ACxdAFF1I.q11X"43A6S=&tQVVAY7:Fz!zvvf~,,W5"ll1o  $YaYQJ'(/$677 ((,,VT:I$!((5  H6QRU @ $  <s   <R4#R9 5S
9SSc                X    \        4       pV P                  W!4       VP                  4       # )zSave the given object to bytes.)r   savegetvalue)r6   obr   s   && r   r   BsdfSerializer.encode  s!    I		!zz|r   c                   VP                  R4       VP                  \        P                  ! R\        ^ ,          4      4       VP                  \        P                  ! R\        ^,          4      4       . pV P	                  WVR4       \        V4      ^ 8  d6   V^ ,          pVP                  VP                  4       8w  d   \        R4      hR# R# )z0Write the given object to the given file object.   BSDFr   Nz8The stream object must be the last object to be encoded.)	ry   structpackVERSIONr}   r    
_start_postellr   )r6   r   r   r   streams   &&&  r   r   BsdfSerializer.save  s    		D'!*-.	D'!*-. QGT* w<!QZF  AFFH, Q  - r   c                :    \        V4      pV P                  V4      # )z@Load the data structure that is BSDF-encoded in the given bytes.)r   load)r6   r#   r   s   && r   r   BsdfSerializer.decode  s    BKyy|r   c                   VP                  ^4      pVR8w  d   \        RV,          4      h\        RVP                  ^4      4      ^ ,          p\        RVP                  ^4      4      ^ ,          pRW43,          pV\        ^ ,          8w  d   Rp\        V\        V3,          4      hV\        ^,          8  d%   Rp\
        P                  V\        V3,          4       V P                  V4      # )z6Load a BSDF-encoded object from the given file object.r   z'This does not look like a BSDF file: %rr   z%i.%izLReading file with different major version (%s) from the implementation (%s).zWBSDF warning: reading file with higher minor version (%s) than the implementation (%s).)r   r   r   r   __version__rZ   r[   r   )r6   r   f4major_versionminor_versionfile_versionr   s   &&     r   r   BsdfSerializer.load  s     VVAY=H2MNN!$q	215!$q	215-!??GAJ&0  qK#>>??71:%0  NN1\::;||Ar   )rF   r1   r2   rI   rK   rJ   rH   r   )r@   FTFF)r   
__module____qualname____firstlineno____doc__r:   r5   r4   rf   r}   r   r   r   r   r   __static_attributes____classdictcell____classdict__s   @r   r.   r.   t   sF     <'*0)V1Y>vXt&
 r   r.   c                   D   a  ] tR tRt o RtRR ltR t]R 4       tRt	V t
R# )	r   i  zBase class for streams.c                    ^ V n         RV n        \        V\        4      '       d
   Wn        RpMVR8X  d   ^ V n        VR9   g   Q hWn        RV n        ^ V n        R# )r@   r   rx   N)r   rx   )_i_countr&   int_mode_fr   )r6   r   s   &&r   r:   BaseStream.__init__  sV    dC  KDS[DKz!!!
r   c                    V P                   e   \        R4      hWn         V P                   P                  4       V n        W n        W0n        R # )Nz(Stream object cannot be activated twice?)r   IOErrorr   r   r}   r   )r6   fileencode_funcdecode_funcs   &&&&r   r   BaseStream._activate  s8    77DEE'',,.""r   c                    V P                   # )z$The mode of this stream: 'r' or 'w'.)r   r6   s   &r   r   BaseStream.mode  s     zzr   )r   r   r}   r   r   r   r   N)rx   )r   r   r   r   r   r:   r   propertyr   r   r   r   s   @r   r   r     s&     !#  r   r   c                   f   a  ] tR tRt o Rt]R 4       t]R 4       tR tRR lt	R t
R tR	 tR
tV tR# )r   i  zbA streamable list object used for writing or reading.
In read mode, it can also be iterated over.
c                    V P                   # )zTThe number of elements in the stream (can be -1 for unclosed
streams in read-mode).
r   r   s   &r   countListStream.count  s    
 {{r   c                    V P                   # )z/The current index of the element to read/write.)r   r   s   &r   indexListStream.index  s     wwr   c                r   V P                   V P                  8w  d   \        R4      hV P                  f   \        R4      hV P                  P                  '       d   \        R4      hV P                  V P                  W.R4       V ;P                  ^,          un        V ;P                   ^,          un         R# )zoAppend an item to the streaming list. The object is immediately
serialized and written to the underlying file.
z/Can only append items to the end of the stream.Nz.List stream is not associated with a file yet.zCannot stream to a close file.)r   r   r   r   r   r}   )r6   items   &&r   r   ListStream.append  s     ;;$''!KLL77?JKK77>>>:;;TWWdFD11qr   c                ^   V P                   V P                  8w  d   \        R4      hV P                  f   \        R4      hV P                  P                  '       d   \        R4      hV P                  P                  4       pV P                  P                  V P                  ^,
          ^,
          4       V P                  P                  \        RV'       d   ^M^4      4       V P                  P                  \        RV P                   4      4       V P                  P                  V4       R# )zClose the stream, marking the number of written elements. New
elements may still be appended, but they won't be read during decoding.
If ``unstream`` is False, the stream is turned into a regular list
(not streaming).
z-Can only close when at the end of the stream.N-ListStream is not associated with a file yet.z&Cannot close a stream on a close file.r   r   )
r   r   r   r   r   r   seekr   ry   r   )r6   unstreamr   s   && r   closeListStream.close  s     ;;$''!IJJ77?IJJ77>>>BCCGGLLNT__q(1,-eD#s;<eD$++./Qr   c                R   V P                   R8w  d   \        R4      hV P                  f   \        R4      h\        V P                  RR4      '       d   \        R4      hV P                  ^ 8  dZ   V P
                  V P                  8  d   \        4       hV ;P
                  ^,          un        V P                  V P                  4      #  V P                  V P                  4      pV ;P
                  ^,          un        V#   \         d    T P
                  T n        \        4       hi ; i)ziRead and return the next element in the streaming list.
Raises StopIteration if the stream is exhausted.
r   z$This ListStream in not in read mode.Nr   r   z'Cannot read a stream from a close file.)	r   r   r   getattrr   r   StopIterationr   r   )r6   ress   & r   nextListStream.next,  s     ::@AA77?IJJ477Hd++CDD;;!ww$++%#o%GGqLG<<((&ll477+1
 &"gg#o%&s   	5C? ?'D&c                >    V P                   R 8w  d   \        R4      hV # )r   z/Cannot iterate: ListStream in not in read mode.)r   r   r   s   &r   __iter__ListStream.__iter__E  s    ::KLLr   c                "    V P                  4       # r   )r   r   s   &r   __next__ListStream.__next__J  s    yy{r   r   N)F)r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   s   @r   r   r     sP          (&2
 r   r   c                   d   a  ] tR tRt o RtRR ltR tR tR tR t	R t
R	 tR
 tR tR tRtV tR# )r   iN  a(  Object to represent a blob of bytes. When used to write a BSDF file,
it's a wrapper for bytes plus properties such as what compression to apply.
When used to read a BSDF file, it can be used to read the data lazily, and
also modify the data if reading in 'r+' mode and the blob isn't compressed.
c                   \        V\        4      '       dD   R V n        V P                  W4      V n        W n        V P                  V,           V n        W@n        R # \        V\        4      '       d`   \        V4      ^8X  dP   \        V^ ,          R4      '       d7   Vw  V n        pR V n        V P                  V P                  V4       RV n        R # \        R4      h)Nr   FzWrong argument to create Blob.)r&   r   r   _from_bytes
compressedrL   	used_sizeallocated_sizerM   r]   r    hasattr
_from_file	_modifiedrE   )r6   r#   rL   
extra_sizerM   
allow_seeks   &&&&& r   r:   Blob.__init__X  s    b%  DG"..r?DO*"&..:"=D ,E""s2w!|1v8N8N"$DGZ"DOOODGGZ0"DN<==r   c                    V^ 8X  d   TpMEV^8X  d   \         P                  ! V^	4      pM&V^8X  d   \        P                  ! V^	4      pMQ R4       h\        V4      V n        \        V4      V n        V# )z"When used to wrap bytes in a blob.zUnknown compression identifier)r>   compressr?   r    	data_sizer   )r6   r   rL   r   s   &&& r   r   Blob._from_bytesg  sf    !JAua0JAeQ/J:::5UZr   c                   V P                   ^8:  d   V P                  ^ 8X  dp   VP                  \        RV P                   4      4       VP                  \        RV P                  4      4       VP                  \        V P                  4      4       MrVP                  \        R^V P                   4      4       VP                  \        R^V P                  4      4       VP                  \        R^V P                  4      4       VP                  \        RV P                  4      4       V P                  '       dF   VP                  R\        P                  ! V P                  4      P                  4       ,           4       MVP                  R4       V P                  ^ 8X  dZ   ^VP                  4       ^,           ^,          ,
          pVP                  \        RV4      4       VP                  RV,          4       MVP                  \        R^ 4      4       VP                  V P                  4       VP                  RV P                   V P                  ,
          ,          4       R# )zBPrivate friend method called by encoder to write a blob to a file.r   r   B       N)r   rL   ry   r   r   r   r  rM   hashlibmd5r   digestr   )r6   r   	alignments   && r   r   Blob._to_filev  s    #%$*:*:a*?GGE$ 3 345GGE$/0GGGDNN+,GGE%d&9&9:;GGE%dnn56GGE%dnn56	c4++,-GGGgkk$//:AACCDGGGq QVVX\Q..IGGE$	*+GGGi'(GGE$N#	 	4..?@Ar   c                l   \        RVP                  ^4      4      ^ ,          pV^8X  d#   \        RVP                  ^4      4      ^ ,          p\        RVP                  ^4      4      ^ ,          pV^8X  d#   \        RVP                  ^4      4      ^ ,          p\        RVP                  ^4      4      ^ ,          pV^8X  d#   \        RVP                  ^4      4      ^ ,          p\        RVP                  ^4      4      ^ ,          p\        RVP                  ^4      4      ^ ,          pV'       d   VP                  ^4      p\        RVP                  ^4      4      ^ ,          p	VP                  V	4       V'       dQ   VP                  4       V n        V P                  V,           V n        VP                  V P                  V,           4       M;RV n        RV n        VP                  V4      V n        VP                  W4,
          4       Wn        W`n        V'       d   XMRV n	        W@n
        W0n        WPn        R# )z(Used when a blob is read by the decoder.r   r   N)r   r   r   	start_posend_posr   r   r  rL   rM   r   r   r  )
r6   r   r   r   r   r  rL   has_checksumchecksumr  s
   &&&       r   r   Blob._from_file  s    #43A6S &tQVVAY7:NdAFF1I.q1	!$q	215IdAFF1I.q1	!$q	215IaffQi03 qvvay1!4vvbzHdAFF1I.q1		yVVXDN>>I5DLFF4>>N23!DNDLffY/DOFF>-."&(4H$","r   c                   V P                   f   \        R4      hV^ 8  d   V P                  V,           pV^ 8  g   WP                  8  d   \        R4      hV P                   P	                  V P
                  V,           4       R# )z8Seek to the given position (relative to the blob start).Nz>Cannot seek in a blob that is not created by the BSDF decoder.zSeek beyond blob boundaries.)r   r   r   r   r   r  )r6   ps   &&r   r   	Blob.seek  sk    77?S  q5##a'Aq5A+++899T^^a'(r   c                    V P                   f   \        R4      hV P                   P                  4       V P                  ,
          # )zCGet the current file pointer position (relative to the blob start).z>Cannot tell in a blob that is not created by the BSDF decoder.)r   r   r   r  r   s   &r   r   	Blob.tell  s6    77?S  ww||~..r   c                :   V P                   f   \        R4      hV P                  '       d   \        R4      hV P                   P	                  4       \        V4      ,           V P                  8  d   \        R4      hRV n        V P                   P                  V4      # )zWrite bytes to the blob.z?Cannot write in a blob that is not created by the BSDF decoder.z,Cannot arbitrarily write in compressed blob.zWrite beyond blob boundaries.T)	r   r   rL   r   r   r    r  r   ry   )r6   r#   s   &&r   ry   
Blob.write  sz    77?T  HII77<<>CG#dll29::ww}}R  r   c                   V P                   f   \        R4      hV P                  '       d   \        R4      hV P                   P	                  4       V,           V P
                  8  d   \        R4      hV P                   P                  V4      # )zRead n bytes from the blob.z>Cannot read in a blob that is not created by the BSDF decoder.z+Cannot arbitrarily read in compressed blob.zRead beyond blob boundaries.)r   r   rL   r   r   r  r   )r6   r   s   &&r   r   	Blob.read  sn    77?S  GHH77<<>A,899ww||Ar   c                   V P                   e   V P                   pMkV P                  P                  4       pV P                  ^ 4       V P                  P	                  V P
                  4      pV P                  P                  V4       V P                  ^ 8X  d   TpV# V P                  ^8X  d   \        P                  ! V4      pV# V P                  ^8X  d   \        P                  ! V4      pV# \        RV P                  ,          4      h)z&Get the contents of the blob as bytes.zInvalid compression %i)r   r   r   r   r   r   rL   r>   
decompressr?   r   )r6   r   r   r   s   &   r   r   Blob.get_bytes  s    ??&JAIIaLdnn5JGGLLOq E  "OOJ/E
 	 "NN:.E  7$:J:JJKKr   c                   V P                   '       d   V P                  '       d   V P                  ^ 4       V P                  P	                  V P
                  4      pV P                  P                  V P                  V P                  ,
          ^,
          ^,
          4       V P                  P                  \        P                  ! V4      P                  4       4       R# R# R# )zJReset the blob's checksum if present. Call this after modifying
the data.
N)rM   r   r   r   r   r   r  r  ry   r
  r  r  )r6   r   s   & r   update_checksumBlob.update_checksum  s    
 IIaLdnn5JGGLL$..81<rABGGMM'++j188:;	 "0r   )r   r   r  r   r   rL   r  r  r  rM   r   N)r@   r@   F)r   r   r   r   r   r:   r   r   r   r   r   ry   r   r   r"  r   r   r   s   @r   r   r   N  sC     >B8%#N
)/!
&	< 	<r   r   c                <    \        V3/ VB pVP                  V 4      # )zjSave (BSDF-encode) the given object to bytes.
See `BSDFSerializer` for details on extensions and options.
)r.   r   )r   r7   r8   r+   s   &&, r   r   r     !     	z-W-A88B<r   c                    \        V3/ VB p\        V \        4      '       d1   \        V R4      ;_uu_ 4       pVP	                  WQ4      uuRRR4       # VP	                  W4      #   + '       g   i     R# ; i)zSave (BSDF-encode) the given object to the given filename or
file object. See` BSDFSerializer` for details on extensions and options.
wbN)r.   r&   r'   openr   )r   r   r7   r8   r+   fps   &&&,  r   r   r     sY     	z-W-A!\""!T]]b66"> ] vva} ]]s   A$$A5	c                <    \        V3/ VB pVP                  V 4      # )zhLoad a (BSDF-encoded) structure from bytes.
See `BSDFSerializer` for details on extensions and options.
)r.   r   )r#   r7   r8   r+   s   &&, r   r   r     r%  r   c                \   \        V3/ VB p\        V \        4      '       dg   V P                  R4      '       d    \        P
                  P                  V 4      p \        V R4      ;_uu_ 4       pVP                  V4      uuRRR4       # VP                  V 4      #   + '       g   i     R# ; i)zLoad a (BSDF-encoded) structure from the given filename or file object.
See `BSDFSerializer` for details on extensions and options.
rbN)z~/z~\)	r.   r&   r'   
startswithospath
expanduserr(  r   )r   r7   r8   r+   r)  s   &&,  r   r   r   $  s|     	z-W-A!\""<<&&""1%A!T]]b66": ] vvay ]]s   -BB+	c                   D   a  ] tR tRt o RtRtRtR tR tR t	R t
RtV tR	# )
rW   i>  a  Base class to implement BSDF extensions for special data types.

Extension classes are provided to the BSDF serializer, which
instantiates the class. That way, the extension can be somewhat dynamic:
e.g. the NDArrayExtension exposes the ndarray class only when numpy
is imported.

A extension instance must have two attributes. These can be attributes of
the class, or of the instance set in ``__init__()``:

* name (str): the name by which encoded values will be identified.
* cls (type): the type (or list of types) to match values with.
  This is optional, but it makes the encoder select extensions faster.

Further, it needs 3 methods:

* `match(serializer, value) -> bool`: return whether the extension can
  convert the given value. The default is ``isinstance(value, self.cls)``.
* `encode(serializer, value) -> encoded_value`: the function to encode a
  value to more basic data types.
* `decode(serializer, encoded_value) -> value`: the function to decode an
  encoded value back to its intended representation.

 c                P    R V P                   : R\        \        V 4      4      : R2# )z<BSDF extension z at 0x>)rX   hexidr   s   &r   __repr__Extension.__repr__[  s    04		3r$x=IIr   c                ,    \        W P                  4      # r   )r&   r\   r6   r+   r   s   &&&r   r)   Extension.match^  s    !XX&&r   c                    \        4       hr   NotImplementedErrorr:  s   &&&r   r   Extension.encodea      !##r   c                    \        4       hr   r=  r:  s   &&&r   r   Extension.decoded  r@  r   r0   N)r   r   r   r   r   rX   r\   r7  r)   r   r   r   r   r   s   @r   rW   rW   >  s0     2 D
CJ'$$ $r   rW   c                   4   a  ] tR tRt o Rt]tR tR tRt	V t
R# )ComplexExtensionih  r   c                2    VP                   VP                  3# r   )realimagr:  s   &&&r   r   ComplexExtension.encodel  s    r   c                6    \        V^ ,          V^,          4      # )r@   )complexr:  s   &&&r   r   ComplexExtension.decodeo  s    qtQqT""r   r0   N)r   r   r   r   rX   rJ  r\   r   r   r   r   r   s   @r   rD  rD  h  s     D
C # #r   rD  c                   <   a  ] tR tRt o RtR tR tR tR tRt	V t
R# )	NDArrayExtensionis  ndarrayc                ^    R \         P                  9   d   ^ RIpVP                  V n        R# R# )numpyN)sysmodulesrP  rN  r\   )r6   nps   & r   r:   NDArrayExtension.__init__v  s!    ckk!zzDH "r   c                j    \        VR 4      ;'       d!    \        VR4      ;'       d    \        VR4      # )shapedtypetobytes)r   r:  s   &&&r   r)   NDArrayExtension.match|  s-    q'"TTwq'':TTwq)?TTr   c                t    \        VP                  \        VP                  4      VP	                  4       R 7      # ))rV  rW  data)r~   rV  	text_typerW  rX  r:  s   &&&r   r   NDArrayExtension.encode  s$    !''177);!))+NNr   c                     ^ RI pTP                  TR,          TR,          R7      pTR,          Tn        T#   \         d    Tu # i ; i)r@   Nr[  rW  )rW  rV  )rP  ImportError
frombufferrV  )r6   r+   r   rS  as   &&&  r   r   NDArrayExtension.decode  sL    	 MM!F)1W:M6G*	  	H	s   7 AA)r\   N)r   r   r   r   rX   r:   r)   r   r   r   r   r   s   @r   rM  rM  s  s%     D"UO r   rM  __main__)rB   rA   rB   r   )>r   
__future__r   r   r   r?   r
  loggingr.  r(   r   rQ  typesr>   ior   	getLoggerr   rZ   r   joinr   version_infor   r	   r\  r'   r|   r   rz   rU   r_   basicConfigunicode
basestringlong	ClassTyper   r   unpackr   r   r   r$   r,   objectr.   r   r   r   r   r   r   r   loadsdumpsrW   rD  rM  r3   bsdf_climainr0   r   r   <module>rv     s  
& A @ 
   	 	  
   			8	$ hh/w// 
qQILMMJILM$KMu&J 	MM	$_V _J <T Tnt<6 t<t	 	'$ '$T#y #y 2 ()9:  zMMO	 r   