Ë
    Öùd�S  ã                   ój  — d dl mZ d dlmZmZmZmZ d dlmZm	Z	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ d dlmZmZmZmZmZm Z m!Z!m"Z"m#Z#m$Z$ d„ Z%dFd„Z&dGd„Z'dHd	„Z(d
„ Z)d„ Z*d„ Z+d„ Z,d„ Z-d„ Z.d„ Z/d„ Z0d„ Z1d„ Z2d„ Z3d„ Z4d„ Z5d„ Z6d„ Z7d„ Z8d„ Z9d„ Z:d„ Z;d„ Z<d„ Z=d„ Z>d „ Z?d!„ Z@d"„ ZAd#„ ZBd$„ ZCd%„ ZDd&„ ZEd'„ ZFd(„ ZGd)„ ZHd*„ ZId+„ ZJ e,d,«      fd-„ZKd.„ ZLd/„ ZMd0„ ZNd1„ ZOd2„ ZPdId3„ZQd4„ ZRd5„ ZSd6„ ZTd7„ ZUeVfd8„ZWd9„ ZXd:„ ZYd;„ ZZd<„ Z[d=„ Z\	 	 dJd?„Z] e,d,«      d>fd@„Z^dd> e%d>d «      fdA„Z_dB„ Z`dKdC„ZadLdD„ZbdE„ Zcy>)Mé   )Úint2byte)ÚBitStreamReaderÚBitStreamWriterÚ
encode_binÚ
decode_bin)ÚStructÚ	MetaFieldÚStaticFieldÚFormatFieldÚOnDemandÚPointerÚSwitchÚValueÚRepeatUntilÚ	MetaArrayÚSequenceÚRangeÚSelectÚPassÚSizeofErrorÚBufferedÚRestreamÚReconfig)
ÚBitIntegerAdapterÚPaddingAdapterÚConstAdapterÚCStringAdapterÚLengthValueAdapterÚIndexingAdapterÚPaddedStringAdapterÚFlagsAdapterÚStringAdapterÚMappingAdapterc                 óH   — t        |«      rt        | |«      S t        | |«      S )a*  
    A field consisting of a specified number of bytes.

    :param str name: the name of the field
    :param length: the length of the field. the length can be either an integer
      (StaticField), or a function that takes the context as an argument and
      returns the length (MetaField)
    )Úcallabler	   r
   )ÚnameÚlengths     ú;/usr/lib/python3/dist-packages/elftools/construct/macros.pyÚFieldr)      s&   € ô �ÔÜ˜˜vÓ&Ð&ä˜4 Ó(Ð(ó    c                 ó6   — t        t        | |«      ||||¬«      S )a³  
    BitFields, as the name suggests, are fields that operate on raw, unaligned
    bits, and therefore must be enclosed in a BitStruct. Using them is very
    similar to all normal fields: they take a name and a length (in bits).

    :param str name: name of the field
    :param int length: number of bits in the field, or a function that takes
                       the context as its argument and returns the length
    :param bool swapped: whether the value is byte-swapped
    :param bool signed: whether the value is signed
    :param int bytesize: number of bits per byte, for byte-swapping

    >>> foo = BitStruct("foo",
    ...     BitField("a", 3),
    ...     Flag("b"),
    ...     Padding(3),
    ...     Nibble("c"),
    ...     BitField("d", 5),
    ... )
    >>> foo.parse("\xe1\x1f")
    Container(a = 7, b = False, c = 8, d = 31)
    >>> foo = BitStruct("foo",
    ...     BitField("a", 3),
    ...     Flag("b"),
    ...     Padding(3),
    ...     Nibble("c"),
    ...     Struct("bar",
    ...             Nibble("d"),
    ...             Bit("e"),
    ...     )
    ... )
    >>> foo.parse("\xe1\x1f")
    Container(a = 7, b = False, bar = Container(d = 15, e = 1), c = 8)
    )ÚswappedÚsignedÚbytesize)r   r)   )r&   r'   r,   r-   r.   s        r(   ÚBitFieldr/      s'   € ôH œU 4¨Ó0ØØØØô	ð r*   ó    c                 ó2   — t        t        d| «      ||¬«      S )a§  a padding field (value is discarded)
    * length - the length of the field. the length can be either an integer,
      or a function that takes the context as an argument and returns the
      length
    * pattern - the padding pattern (character/byte) to use. default is b"\x00"
    * strict - whether or not to raise an exception is the actual padding
      pattern mismatches the desired pattern. default is False.
    N)ÚpatternÚstrict)r   r)   )r'   r2   r3   s      r(   ÚPaddingr4   H   s    € ô œ%  fÓ-ØØôð r*   c                 ó\   — t        t        | d«      t        |«      t        |«      dœ|¬«      S )a@  
    A flag.

    Flags are usually used to signify a Boolean value, and this construct
    maps values onto the ``bool`` type.

    .. note:: This construct works with both bit and byte contexts.

    .. warning:: Flags default to False, not True. This is different from the
        C and Python way of thinking about truth, and may be subject to change
        in the future.

    :param str name: field name
    :param int truth: value of truth (default 1)
    :param int falsehood: value of falsehood (default 0)
    :param bool default: default value (default False)
    r   ©TF)Údefault)ÚSymmetricMappingr)   r   )r&   ÚtruthÚ	falsehoodr7   s       r(   ÚFlagr;   V   s-   € ô& œE $¨›NÜ˜“¬°)Ó)<Ñ=Øôð r*   c                 ó   — t        | d«      S )z1a 1-bit BitField; must be enclosed in a BitStructr   ©r/   ©r&   s    r(   ÚBitr?   q   ó   € ä�D˜!ÓÐr*   c                 ó   — t        | d«      S )z1a 4-bit BitField; must be enclosed in a BitStructé   r=   r>   s    r(   ÚNibblerC   t   r@   r*   c                 ó   — t        | d«      S )z2an 8-bit BitField; must be enclosed in a BitStructé   r=   r>   s    r(   ÚOctetrF   w   r@   r*   c                 ó   — t        | dd«      S )z"unsigned, big endian 8-bit integerú>ÚB©r   r>   s    r(   ÚUBInt8rK   {   ó   € ä�t˜S #Ó&Ð&r*   c                 ó   — t        | dd«      S )z#unsigned, big endian 16-bit integerrH   ÚHrJ   r>   s    r(   ÚUBInt16rO   ~   rL   r*   c                 ó   — t        | dd«      S )z#unsigned, big endian 32-bit integerrH   ÚLrJ   r>   s    r(   ÚUBInt32rR   �   rL   r*   c                 ó   — t        | dd«      S )z#unsigned, big endian 64-bit integerrH   ÚQrJ   r>   s    r(   ÚUBInt64rU   „   rL   r*   c                 ó   — t        | dd«      S )z signed, big endian 8-bit integerrH   ÚbrJ   r>   s    r(   ÚSBInt8rX   ˆ   rL   r*   c                 ó   — t        | dd«      S )z!signed, big endian 16-bit integerrH   ÚhrJ   r>   s    r(   ÚSBInt16r[   ‹   rL   r*   c                 ó   — t        | dd«      S )z!signed, big endian 32-bit integerrH   ÚlrJ   r>   s    r(   ÚSBInt32r^   Ž   rL   r*   c                 ó   — t        | dd«      S )z!signed, big endian 64-bit integerrH   ÚqrJ   r>   s    r(   ÚSBInt64ra   ‘   rL   r*   c                 ó   — t        | dd«      S )z%unsigned, little endian 8-bit integerú<rI   rJ   r>   s    r(   ÚULInt8rd   •   rL   r*   c                 ó   — t        | dd«      S )z&unsigned, little endian 16-bit integerrc   rN   rJ   r>   s    r(   ÚULInt16rf   ˜   rL   r*   c                 ó   — t        | dd«      S )z&unsigned, little endian 32-bit integerrc   rQ   rJ   r>   s    r(   ÚULInt32rh   ›   rL   r*   c                 ó   — t        | dd«      S )z&unsigned, little endian 64-bit integerrc   rT   rJ   r>   s    r(   ÚULInt64rj   ž   rL   r*   c                 ó   — t        | dd«      S )z#signed, little endian 8-bit integerrc   rW   rJ   r>   s    r(   ÚSLInt8rl   ¢   rL   r*   c                 ó   — t        | dd«      S )z$signed, little endian 16-bit integerrc   rZ   rJ   r>   s    r(   ÚSLInt16rn   ¥   rL   r*   c                 ó   — t        | dd«      S )z$signed, little endian 32-bit integerrc   r]   rJ   r>   s    r(   ÚSLInt32rp   ¨   rL   r*   c                 ó   — t        | dd«      S )z$signed, little endian 64-bit integerrc   r`   rJ   r>   s    r(   ÚSLInt64rr   «   rL   r*   c                 ó   — t        | dd«      S )z(unsigned, native endianity 8-bit integerú=rI   rJ   r>   s    r(   ÚUNInt8ru   ¯   rL   r*   c                 ó   — t        | dd«      S )z)unsigned, native endianity 16-bit integerrt   rN   rJ   r>   s    r(   ÚUNInt16rw   ²   rL   r*   c                 ó   — t        | dd«      S )z)unsigned, native endianity 32-bit integerrt   rQ   rJ   r>   s    r(   ÚUNInt32ry   µ   rL   r*   c                 ó   — t        | dd«      S )z)unsigned, native endianity 64-bit integerrt   rT   rJ   r>   s    r(   ÚUNInt64r{   ¸   rL   r*   c                 ó   — t        | dd«      S )z&signed, native endianity 8-bit integerrt   rW   rJ   r>   s    r(   ÚSNInt8r}   ¼   rL   r*   c                 ó   — t        | dd«      S )z'signed, native endianity 16-bit integerrt   rZ   rJ   r>   s    r(   ÚSNInt16r   ¿   rL   r*   c                 ó   — t        | dd«      S )z'signed, native endianity 32-bit integerrt   r]   rJ   r>   s    r(   ÚSNInt32r�   Â   rL   r*   c                 ó   — t        | dd«      S )z'signed, native endianity 64-bit integerrt   r`   rJ   r>   s    r(   ÚSNInt64rƒ   Å   rL   r*   c                 ó   — t        | dd«      S )z-big endian, 32-bit IEEE floating point numberrH   ÚfrJ   r>   s    r(   ÚBFloat32r†   É   rL   r*   c                 ó   — t        | dd«      S )z0little endian, 32-bit IEEE floating point numberrc   r…   rJ   r>   s    r(   ÚLFloat32rˆ   Ì   rL   r*   c                 ó   — t        | dd«      S )z3native endianity, 32-bit IEEE floating point numberrt   r…   rJ   r>   s    r(   ÚNFloat32rŠ   Ï   rL   r*   c                 ó   — t        | dd«      S )z-big endian, 64-bit IEEE floating point numberrH   ÚdrJ   r>   s    r(   ÚBFloat64r�   Ó   rL   r*   c                 ó   — t        | dd«      S )z0little endian, 64-bit IEEE floating point numberrc   rŒ   rJ   r>   s    r(   ÚLFloat64r�   Ö   rL   r*   c                 ó   — t        | dd«      S )z3native endianity, 64-bit IEEE floating point numberrt   rŒ   rJ   r>   s    r(   ÚNFloat64r‘   Ù   rL   r*   c                 óŽ   ‡ — t        ‰ «      rt        ‰ |«      }|S t        ˆ fd„|«      }|j                  |j                  «       |S )aì  
    Repeats the given unit a fixed number of times.

    :param int count: number of times to repeat
    :param ``Construct`` subcon: construct to repeat

    >>> c = Array(4, UBInt8("foo"))
    >>> c.parse("\x01\x02\x03\x04")
    [1, 2, 3, 4]
    >>> c.parse("\x01\x02\x03\x04\x05\x06")
    [1, 2, 3, 4]
    >>> c.build([5,6,7,8])
    '\x05\x06\x07\x08'
    >>> c.build([5,6,7,8,9])
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 4..4, found 5
    c                 ó   •— ‰S ©N© )ÚctxÚcounts    €r(   ú<lambda>zArray.<locals>.<lambda>ø   s   ø€  E€ r*   )r%   r   Ú_clear_flagÚFLAG_DYNAMIC)r—   ÚsubconÚcons   `  r(   ÚArrayr�   á   sE   ø€ ô( �„Ü˜˜vÓ&ˆð €Jô Ó)¨6Ó2ˆØ�‰˜×(Ñ(Ô)Ø€Jr*   r'   c           
      ób   ‡— t        t        | j                  ‰t        ˆfd„| «      d¬«      «      S )zˆan array prefixed by a length field.
    * subcon - the subcon to be repeated
    * length_field - a construct returning an integer
    c                 ó"   •— | ‰j                      S r”   r>   ©r–   Úlength_fields    €r(   r˜   zPrefixedArray.<locals>.<lambda>  s   ø€ ˜c ,×"3Ñ"3Ñ4€ r*   F©Únested)r   r   r&   r�   )r›   r¡   s    `r(   ÚPrefixedArrayr¤   ü   s1   ø€ ô
 Ü�—‘ØÜÓ4°fÓ=Øô	
óð r*   c                 ó(   — ddl m} t        | ||«      S )Né    )Úmaxsize)Úsysr§   r   )Úmincountr›   r§   s      r(   Ú	OpenRangerª   	  s   € ÝÜ�˜7 FÓ+Ð+r*   c                 ó   — t        d| «      S )a‚  
    Repeats the given unit one or more times.

    :param ``Construct`` subcon: construct to repeat

    >>> from construct import GreedyRange, UBInt8
    >>> c = GreedyRange(UBInt8("foo"))
    >>> c.parse("\x01")
    [1]
    >>> c.parse("\x01\x02\x03")
    [1, 2, 3]
    >>> c.parse("\x01\x02\x03\x04\x05\x06")
    [1, 2, 3, 4, 5, 6]
    >>> c.parse("")
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 1..2147483647, found 0
    >>> c.build([1,2])
    '\x01\x02'
    >>> c.build([])
    Traceback (most recent call last):
      ...
    construct.core.RangeError: expected 1..2147483647, found 0
    r   ©rª   ©r›   s    r(   ÚGreedyRanger®     s   € ô4 �Q˜ÓÐr*   c                 ó   — t        d| «      S )a˜  
    Repeats the given unit zero or more times. This repeater can't
    fail, as it accepts lists of any length.

    :param ``Construct`` subcon: construct to repeat

    >>> from construct import OptionalGreedyRange, UBInt8
    >>> c = OptionalGreedyRange(UBInt8("foo"))
    >>> c.parse("")
    []
    >>> c.parse("\x01\x02")
    [1, 2]
    >>> c.build([])
    ''
    >>> c.build([1,2])
    '\x01\x02'
    r¦   r¬   r­   s    r(   ÚOptionalGreedyRanger°   )  s   € ô& �Q˜ÓÐr*   c                 ó8   — t        | j                  | t        «      S )zran optional construct. if parsing fails, returns None.
    * subcon - the subcon to optionally parse or build
    )r   r&   r   r­   s    r(   ÚOptionalr²   B  s   € ô �&—+‘+˜v¤tÓ,Ð,r*   c                 óÌ   — d}d„ }| j                  | j                  «      s,| j                  «       |k  rt        | t        t
        |¬«      }|S t        | t        t        |¬«      }|S )zzconverts the stream to bits, and passes the bitstream to subcon
    * subcon - a bitwise construct (usually BitField)
    i    c                 ó.   — | dz  rt        d| «      ‚| dz	  S )Né   zsize must be a multiple of 8é   )r   )r'   s    r(   ÚresizerzBitwise.<locals>.resizerO  s!   € Ø�AŠ:ÜÐ<¸fÓEÐEØ˜‰{Ðr*   )ÚencoderÚdecoderr·   )Ústream_readerÚstream_writerr·   )	Ú_is_flagrš   Úsizeofr   r   r   r   r   r   )r›   Ú
MAX_BUFFERr·   rœ   s       r(   ÚBitwiser¿   H  si   € ð €Jòð �?‰?˜6×.Ñ.Ô/°F·M±M³OÀjÒ4PÜ�vÜ Ü Øô
ˆð €Jô	 �vÜ+Ü+Øôˆð €Jr*   c                 ó|   ‡ ‡— ‰dk  rt        d‰«      ‚ˆˆ fd„}t        ‰ j                  ‰ t        ||¬«      d¬«      S )zÉaligns subcon to modulus boundary using padding pattern
    * subcon - the subcon to align
    * modulus - the modulus boundary (default is 4)
    * pattern - the padding pattern (default is \x00)
    é   zmodulus must be >= 2c                 ó8   •— ‰‰j                  | «      ‰z  z
  ‰z  S r”   )Ú_sizeof)r–   Úmodulusr›   s    €€r(   Ú	padlengthzAligned.<locals>.padlengthh  s!   ø€ Ø˜6Ÿ>™>¨#Ó.°Ñ8Ñ9¸WÑDÐDr*   )r2   Fr¢   )Ú
ValueErrorÚSeqOfOner&   r4   )r›   rÄ   r2   rÅ   s   ``  r(   ÚAlignedrÈ   `  sE   ù€ ð �‚{ÜÐ/°Ó9Ð9õEä�F—K‘KØô
 	�	 WÔ-Øôð r*   c                 ó6   — t        t        | g|¢­i |¤Žd¬«      S )zÎa sequence of one element. only the first element is meaningful, the
    rest are discarded
    * name - the name of the sequence
    * args - subconstructs
    * kw - any keyword arguments to Sequence
    r¦   )Úindex)r   r   )r&   ÚargsÚkws      r(   rÇ   rÇ   t  s    € ô œ8 DÐ6¨4Ò6°2Ñ6ÀÔBÐBr*   c                 óD   — t        | j                  | | j                  «      S )zRembeds a struct into the enclosing struct.
    * subcon - the struct to embed
    )r   r&   Ú
FLAG_EMBEDr­   s    r(   ÚEmbeddedrÏ   }  s   € ô �F—K‘K ¨×):Ñ):Ó;Ð;r*   c                 ó   — t        | |«      S )zcrenames an existing construct
    * newname - the new name
    * subcon - the subcon to rename
    )r   )Únewnamer›   s     r(   ÚRenamerÒ   ƒ  s   € ô
 �G˜VÓ$Ð$r*   c                 ó"   ‡— t        | ˆfd„«      S )z†creates an alias for an existing element in a struct
    * newname - the new name
    * oldname - the name of an existing element
    c                 ó   •— | ‰   S r”   r•   )r–   Úoldnames    €r(   r˜   zAlias.<locals>.<lambda>�  s   ø€  c¨'¡l€ r*   )r   )rÑ   rÕ   s    `r(   ÚAliasrÖ   Š  s   ø€ ô
 �Ó2Ó3Ð3r*   c                 ób   — t        d„ |j                  «       D «       «      }t        | ||||¬«      S )a€  defines a symmetrical mapping: a->b, b->a.
    * subcon - the subcon to map
    * mapping - the encoding mapping (a dict); the decoding mapping is
      achieved by reversing this mapping
    * default - the default value to use when no mapping is found. if no
      default value is given, and exception is raised. setting to Pass would
      return the value "as is" (unmapped)
    c              3   ó*   K  — | ]  \  }}||f–— Œ y ­wr”   r•   )Ú.0ÚkÚvs      r(   ú	<genexpr>z#SymmetricMapping.<locals>.<genexpr>ž  s   è ø€ Ò?¡t q¨!˜Q œFÑ?ùs   ‚)ÚencodingÚdecodingÚ
encdefaultÚ
decdefault)ÚdictÚitemsr#   )r›   Úmappingr7   Úreversed_mappings       r(   r8   r8   •  s6   € ô Ñ?¨w¯}©}«Ô?Ó?ÐÜ˜&ØØ#ØØô	ð r*   c                 óD   — t        | ||j                  dt        «      «      S )a„  a set of named values mapping.
    * subcon - the subcon to map
    * kw - keyword arguments which serve as the encoding mapping
    * _default_ - an optional, keyword-only argument that specifies the
      default value to use when the mapping is undefined. if not given,
      and exception is raised when the mapping is undefined. use `Pass` to
      pass the unmapped value as-is
    Ú	_default_)r8   ÚpopÚNotImplemented©r›   rÌ   s     r(   ÚEnumrê   ¦  s   € ô ˜F B¨¯©¨{¼NÓ(KÓLÐLr*   c                 ó   — t        | |«      S )z„a set of flag values mapping.
    * subcon - the subcon to map
    * kw - keyword arguments which serve as the encoding mapping
    )r!   ré   s     r(   Ú	FlagsEnumrì   ±  s   € ô
 ˜ Ó#Ð#r*   c                 ó.   ‡— t        | gˆfd„|D «       ¢­Ž S )zÄa struct of aligned fields
    * name - the name of the struct
    * subcons - the subcons that make up this structure
    * kw - keyword arguments to pass to Aligned: 'modulus' and 'pattern'
    c              3   ó6   •K  — | ]  }t        |fi ‰¤Ž–— Œ y ­wr”   )rÈ   )rÙ   ÚscrÌ   s     €r(   rÜ   z AlignedStruct.<locals>.<genexpr>Â  s   øè ø€ Ò>°œ' "Ñ+¨Õ+Ñ>ùs   ƒ)r   )r&   ÚsubconsrÌ   s     `r(   ÚAlignedStructrñ   ¼  s   ø€ ô �$Ð?Ó>°gÔ>Ò?Ð?r*   c                 ó,   — t        t        | g|¢­Ž «      S )z{a struct of bitwise fields
    * name - the name of the struct
    * subcons - the subcons that make up this structure
    )r¿   r   )r&   rð   s     r(   Ú	BitStructró   Ä  s   € ô
 ”6˜$Ð) Ò)Ó*Ð*r*   c                  ó>   — t        t        t        dg| ¢­Ž «      «      S )zian embedded BitStruct. no name is necessary.
    * subcons - the subcons that make up this structure
    N)r¿   rÏ   r   )rð   s    r(   ÚEmbeddedBitStructrõ   Ë  s   € ô ”8œF 4Ð2¨'Ò2Ó3Ó4Ð4r*   Nc                 óV   — t        t        | |«      |¬«      }|�t        ||||¬«      }|S )ae  
    A configurable, fixed-length string field.

    The padding character must be specified for padding and trimming to work.

    :param str name: name
    :param int length: length, in bytes
    :param str encoding: encoding (e.g. "utf8") or None for no encoding
    :param str padchar: optional character to pad out strings
    :param str paddir: direction to pad out strings; one of "right", "left",
                       or "both"
    :param str trim: direction to trim strings; one of "right", "left"

    >>> from construct import String
    >>> String("foo", 5).parse("hello")
    'hello'
    >>>
    >>> String("foo", 12, encoding = "utf8").parse("hello joh\xd4\x83n")
    u'hello joh\u0503n'
    >>>
    >>> foo = String("foo", 10, padchar = "X", paddir = "right")
    >>> foo.parse("helloXXXXX")
    'hello'
    >>> foo.build("hello")
    'helloXXXXX'
    ©rÝ   )ÚpadcharÚpaddirÚtrimdir)r"   r)   r    )r&   r'   rÝ   rø   rù   rú   rœ   s          r(   ÚStringrû   Ô  s5   € ô: œ˜d FÓ+°hÔ
?€CØÐÜ! #¨w¸vØôˆà€Jr*   c                 ó`   ‡— t        t        t        | ‰t        dˆfd„«      «      «      |¬«      S )a-  
    A length-prefixed string.

    ``PascalString`` is named after the string types of Pascal, which are
    length-prefixed. Lisp strings also follow this convention.

    The length field will appear in the same ``Container`` as the
    ``PascalString``, with the given name.

    :param str name: name
    :param ``Construct`` length_field: a field which will store the length of
                                       the string
    :param str encoding: encoding (e.g. "utf8") or None for no encoding

    >>> foo = PascalString("foo")
    >>> foo.parse("\x05hello")
    'hello'
    >>> foo.build("hello world")
    '\x0bhello world'
    >>>
    >>> foo = PascalString("foo", length_field = UBInt16("length"))
    >>> foo.parse("\x00\x05hello")
    'hello'
    >>> foo.build("hello")
    '\x00\x05hello'
    Údatac                 ó"   •— | ‰j                      S r”   r>   r    s    €r(   r˜   zPascalString.<locals>.<lambda>  s   ø€ ¨#¨l×.?Ñ.?Ñ*@€ r*   r÷   )r"   r   r   r)   )r&   r¡   rÝ   s    ` r(   ÚPascalStringrÿ   ÷  s7   ø€ ô8 ÜÜ�TØÜ�fÓ@ÓAóó	
ð ôð r*   c           	      óN   ‡— t        | t        t        ˆfd„|«      ‰|¬«      «      S )aH  
    A string ending in a terminator.

    ``CString`` is similar to the strings of C, C++, and other related
    programming languages.

    By default, the terminator is the NULL byte (b``0x00``).

    :param str name: name
    :param iterable terminators: sequence of valid terminators, in order of
                                 preference
    :param str encoding: encoding (e.g. "utf8") or None for no encoding
    :param ``Construct`` char_field: construct representing a single character

    >>> foo = CString("foo")
    >>> foo.parse(b"hello\x00")
    b'hello'
    >>> foo.build(b"hello")
    b'hello\x00'
    >>> foo = CString("foo", terminators = b"XYZ")
    >>> foo.parse(b"helloX")
    b'hello'
    >>> foo.parse(b"helloY")
    b'hello'
    >>> foo.parse(b"helloZ")
    b'hello'
    >>> foo.build(b"hello")
    b'helloX'
    c                 ó   •— | ‰v S r”   r•   )Úobjr–   Úterminatorss     €r(   r˜   zCString.<locals>.<lambda>?  s   ø€ ¨°Ð);€ r*   )r  rÝ   )rÒ   r   r   )r&   r  rÝ   Ú
char_fields    `  r(   ÚCStringr    s.   ø€ ô@ �$ÜÜÓ;¸ZÓHØ#Øô	
óð r*   c                 ó*   ‡— t        | ˆfd„||dœ«      S )a«  an if-then-else conditional construct: if the predicate indicates True,
    `then_subcon` will be used; otherwise `else_subcon`
    * name - the name of the construct
    * predicate - a function taking the context as an argument and returning
      True or False
    * then_subcon - the subcon that will be used if the predicate returns True
    * else_subcon - the subcon that will be used if the predicate returns False
    c                 ó&   •— t         ‰| «      «      S r”   )Úbool)r–   Ú	predicates    €r(   r˜   zIfThenElse.<locals>.<lambda>R  s   ø€ ¤D©°3«Ó$8€ r*   r6   )r   )r&   r	  Úthen_subconÚelse_subcons    `  r(   Ú
IfThenElser  I  s"   ø€ ô �$Ó8àØñ	
óð r*   c           
      óN   ‡— t        |j                  | |t        dˆfd„«      «      S )a²  an if-then conditional construct: if the predicate indicates True,
    subcon will be used; otherwise, `elsevalue` will be returned instead.
    * predicate - a function taking the context as an argument and returning
      True or False
    * subcon - the subcon that will be used if the predicate returns True
    * elsevalue - the value that will be used should the predicate return False.
      by default this value is None.
    Ú	elsevaluec                 ó   •— ‰S r”   r•   )r–   r  s    €r(   r˜   zIf.<locals>.<lambda>e  s   ø€  y€ r*   )r  r&   r   )r	  r›   r  s     `r(   ÚIfr  Y  s)   ø€ ô �f—k‘kØØÜˆkÓ0Ó1óð r*   c                 ó2   — t        t        | |«      d|¬«      S )a$  an on-demand pointer.
    * offsetfunc - a function taking the context as an argument and returning
      the absolute stream position
    * subcon - the subcon that will be parsed from the `offsetfunc()` stream
      position on demand
    * force_build - see OnDemand. by default True.
    F)Úadvance_streamÚforce_build)r   r   )Ú
offsetfuncr›   r  s      r(   ÚOnDemandPointerr  l  s    € ô ”G˜J¨Ó/ØØ!ôð r*   c                 ó@   — t        t        d t        | «      «      | «      S r”   )r   r)   Úlen)rý   s    r(   ÚMagicr  y  s   € Üœ˜d¤C¨£IÓ.°Ó5Ð5r*   )FFrE   )r0   F)r   r¦   F)rB   r0   )NNÚrightr  r”   )T)dÚlib.py3compatr   Úlibr   r   r   r   Úcorer   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   Úadaptersr   r   r   r   r   r   r    r!   r"   r#   r)   r/   r4   r;   r?   rC   rF   rK   rO   rR   rU   rX   r[   r^   ra   rd   rf   rh   rj   rl   rn   rp   rr   ru   rw   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è   r8   rê   rì   rñ   ró   rõ   rû   rÿ   r  r  r  r  r  r•   r*   r(   ú<module>r     s®  ðÝ #÷ó ÷=÷ =÷ =÷ =÷ =÷F÷ F÷ Fò)ó)óVóò6òòò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'ò'òñ6 *0°Ó)9ó ò,ò ò8 ò2-òó0ò(Cò<ò%ò4ð 1?ó ò"	Mò$ò@ò+ò5ð >EØó!ñF %+¨8Ó$4¸tó $ðL &°Ù˜T 1“~ó&òXó ó&ó6r*   