o w[e@sdZddlZddZddZddZd d Zd d Zd ZddZddZ ddZ ddZ ddZ ddZ ddZGdddejZGdddejZGd d!d!ejZGd"d#d#eejZGd$d%d%eejZd&d'ZdS)(uY Codec for the Punicode encoding, as specified in RFC 3492 Written by Martin v. Löwis. NcCsPt}t}|D]}t|dkr|t|q||qt|}t||fS)z 3.1 Basic code point segregation) bytearraysetordappendaddsortedbytes)strbaseextendedcr)/usr/lib/python3.10/encodings/punycode.py segregate s   rcCs&d}|D] }t||kr|d7}q|S)z@Return the length of str, considering only characters below max.r)r)r maxresr rrr selective_lens  rcCsLt|} |d7}||krdS||}||kr|d|fS||kr%|d7}q)aReturn a pair (index, pos), indicating the next occurrence of char in str. index is the position of the character considering only ordinals up to and including char, and pos is the position in the full string. index/pos is the starting position in the full string.r)r)len)r charindexposlr rrrselective_finds rc Csd}g}d}|D]:}d}}t|}t||} | d||} t||||\}}|dkr.n| ||7} || d|}d} q |}q|S)3.2 Insertion unsort codingrrrr)rrrr) r r oldcharresultoldindexr rrrcurlendeltarrrinsertion_unsort0s&  r"cCs,d|d|}|dkrdS|dkrdS|S)N$rr)jbiasrrrrTFs  r's$abcdefghijklmnopqrstuvwxyz0123456789cCslt}d} t||}||kr|t|t|S|t|||d|||d|}|d7}q)(3.3 Generalized variable-length integersrrr#)rr'rdigitsr )Nr&rr%trrrgenerate_generalized_integerNs r,cCs^|r|d}n|d}|||7}d}|dkr#|d}|d7}|dks|d||d}|S)Niri#r#&r)r!firstnumchars divisionsr&rrradapt[s  r3cCsPt}d}t|D]\}}t||}||t||dk||d}q t|S)z3.4 Bias adaptationHrr)r enumerater,extendr3r )baselendeltasrr&pointsr!srrrgenerate_integersjs  r;cCs8t|\}}t||}tt||}|r|d|S|S)N-)rr"r;r)textr r r8rrrpunycode_encodeus   r>c Csd}d}d} zt||}Wnty&|dkrtd|ddfYSw|d7}d|kr5dkrrselfinputrHrrrrrSs z Codec.encodecCs*|dvr td|t||}|t|fSN)r?replaceignorezUnsupported error handling )rFrWrrZrrrdecodes   z Codec.decodeN)r?)__name__ __module__ __qualname__rSr`rrrrrXs rXc@eZdZdddZdS)IncrementalEncoderFcCst|SrY)r>r[r\finalrrrrSszIncrementalEncoder.encodeNF)rarbrcrSrrrrrerec@rd)IncrementalDecoderFcCs$|jdvr td|jt||jSr])rHrFrWrfrrrr`s  zIncrementalDecoder.decodeNrh)rarbrcr`rrrrrjrirjc@ eZdZdS) StreamWriterNrarbrcrrrrrlrlc@rk) StreamReaderNrmrrrrrornroc Cs tjdtjtjttttdS)Npunycode)namerSr`incrementalencoderincrementaldecoder streamwriter streamreader) codecs CodecInforXrSr`rerjrlrorrrr getregentrysrx)__doc__rvrrrr"r'r)r,r3r;r>rKrOrWrXrerjrlrorxrrrrs*