ffJdZddlZddlZejddkrGdZdZdZdZd"d Zd Z d Z dd l m Z e Z dd lm Z eZdZdZdZejdefddiZeZn;dZdZdZdZd"dZdZ dZ ddlm Z dd lm Z ddlmZ eZdZdZdZdd lmZeZd!Z[[dS)#aCompatibility code for handling string/bytes changes from Python 2.x to Py3k In Python 2.x, strings (of type ''str'') contain binary data, including encoded Unicode text (e.g. UTF-8). The separate type ''unicode'' holds Unicode text. Unicode literals are specified via the u'...' prefix. Indexing or slicing either type always produces a string of the same type as the original. Data read from a file is always of '''str'' type. In Python 3.x, strings (type ''str'') may only contain Unicode text. The u'...' prefix and the ''unicode'' type are now redundant. A new type (called ''bytes'') has to be used for binary data (including any particular ''encoding'' of a string). The b'...' prefix allows one to specify a binary literal. Indexing or slicing a string produces another string. Slicing a byte string produces another byte string, but the indexing operation produces an integer. Data read from a file is of '''str'' type if the file was opened in text mode, or of ''bytes'' type otherwise. Since PyCrypto aims at supporting both Python 2.x and 3.x, the following helper functions are used to keep the rest of the library as independent as possible from the actual Python version. In general, the code should always deal with binary strings, and use integers instead of 1-byte character strings. b(s) Take a text string literal (with no prefix or with u'...' prefix) and make a byte string. bchr(c) Take an integer and make a 1-character byte string. bord(c) Take the result of indexing on a byte string and make an integer. tobytes(s) Take a text string, a byte string, or a sequence of character taken from a byte string and make a byte string. Nc|SNss w/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib64/python3.11/site-packages/Crypto/Util/py3compat.pybr Bc t|Sr)chrrs r bchrrD 1vv r c t|Sr)strrs r bstrrFrr c t|Sr)ordrs r bordrHrr latin-1cHt|tr||St|tr|St|trt |St|t r|Sd|S)N) isinstanceunicodeencoder bytearraybytes memoryviewtobytesjoinrencodings r r r Js a ! ! 88H%% % 3   H 9 % % 88O : & & 99;; 771:: r c|Srrbss r tostrr'Us r c,t|tSrrrrs r byte_stringr*W!S!!!r )StringIO)maxintc:t|ttfSr)rintlongxs r is_native_intr3as!c4[)))r c,t|tSr)r basestringr1s r is_stringr6ds!Z(((r ct|tp)t|tpt|tSr)rrrrr1s r is_bytesr8gs8!S!!*1i((*1j)) *r ABC __slots__rc,|dSNr)rrs r r r qshhy!!!r c"t|gSr)rrs r rrssaSzzr cjt|trt|dSt|Sr<)rrrrs r rrus/ a   9%% %88Or c|Srrrs r rrzr r c>t|tr|St|trt|St|tr||St|t r|St|gSr)rrrrrrr r"s r r r |s a   H 9 % % 88O #   88H%% % : & & 99;; !:: r c,|dSr<)decoder%s r r'r'syy###r c,t|tSr)rrrs r r*r*s!U###r )BytesIO)maxsizec,t|tSr)rr/r1s r r3r3r+r c,t|tSrr)r1s r r6r6r+r ct|tp)t|tpt|tSr)rrrrr1s r r8r8s8!U##*1i((*1j)) *r )r9ct|tr|||St|trt |||S|||S)zrReturn an immutable copy of a sequence (byte string, byte array, memoryview) in a certain interval [start:seq])rrr rr)startendseqs r _copy_bytesrMsf#z""59~%%''' C # #Ss^$$$59~r )r)__doc__sysabc version_infor rrrr r'r*r,rDr-xrange iter_ranger3r6r8ABCMetaobjectr9IOErrorFileNotFoundErroriorErangerMrr r rZs82""H A!    """"!!!!!GJ***)))*** #+efYb(9 : :C"""     $$$$$$%%%%%%J""""""*** )   CCr