/snap/core20/2769/usr/lib/python3.8/encodings
NameSizeModeActions
__pycache__/-0755rm
aliases.py156930644editdlrm
ascii.py12480644editdlrm
base64_codec.py15330644editdlrm
big5.py10190644editdlrm
big5hkscs.py10390644editdlrm
bz2_codec.py22490644editdlrm
charmap.py20840644editdlrm
cp037.py131210644editdlrm
cp273.py141320644editdlrm
cp424.py120550644editdlrm
cp437.py345640644editdlrm
cp500.py131210644editdlrm
cp720.py136860644editdlrm
cp737.py346810644editdlrm
cp775.py344760644editdlrm
cp850.py341050644editdlrm
cp852.py350020644editdlrm
cp855.py338500644editdlrm
cp856.py124230644editdlrm
cp857.py339080644editdlrm
cp858.py340150644editdlrm
cp860.py346810644editdlrm
cp861.py346330644editdlrm
cp862.py333700644editdlrm
cp863.py342520644editdlrm
cp864.py336630644editdlrm
cp865.py346180644editdlrm
cp866.py343960644editdlrm
cp869.py329650644editdlrm
cp874.py125950644editdlrm
cp875.py128540644editdlrm
cp932.py10230644editdlrm
cp949.py10230644editdlrm
cp950.py10230644editdlrm
cp1006.py135680644editdlrm
cp1026.py131130644editdlrm
cp1125.py345970644editdlrm
cp1140.py131050644editdlrm
cp1250.py136860644editdlrm
cp1251.py133610644editdlrm
cp1252.py135110644editdlrm
cp1253.py130940644editdlrm
cp1254.py135020644editdlrm
cp1255.py124660644editdlrm
cp1256.py128140644editdlrm
cp1257.py133740644editdlrm
cp1258.py133640644editdlrm
euc_jisx0213.py10510644editdlrm
euc_jis_2004.py10510644editdlrm
euc_jp.py10270644editdlrm
euc_kr.py10270644editdlrm
gb2312.py10270644editdlrm
gb18030.py10310644editdlrm
gbk.py10150644editdlrm
hex_codec.py15080644editdlrm
hp_roman8.py134750644editdlrm
hz.py10110644editdlrm
idna.py90980644editdlrm
iso2022_jp.py10530644editdlrm
iso2022_jp_1.py10610644editdlrm
iso2022_jp_2.py10610644editdlrm
iso2022_jp_3.py10610644editdlrm
iso2022_jp_2004.py10730644editdlrm
iso2022_jp_ext.py10690644editdlrm
iso2022_kr.py10530644editdlrm
iso8859_1.py131760644editdlrm
iso8859_2.py134040644editdlrm
iso8859_3.py130890644editdlrm
iso8859_4.py133760644editdlrm
iso8859_5.py130150644editdlrm
iso8859_6.py108330644editdlrm
iso8859_7.py128440644editdlrm
iso8859_8.py110360644editdlrm
iso8859_9.py131560644editdlrm
iso8859_10.py135890644editdlrm
iso8859_11.py123350644editdlrm
iso8859_13.py132710644editdlrm
iso8859_14.py136520644editdlrm
iso8859_15.py132120644editdlrm
iso8859_16.py135570644editdlrm
johab.py10230644editdlrm
koi8_r.py137790644editdlrm
koi8_t.py131930644editdlrm
koi8_u.py137620644editdlrm
kz1048.py137230644editdlrm
latin_1.py12640644editdlrm
mac_arabic.py364670644editdlrm
mac_centeuro.py141020644editdlrm
mac_croatian.py136330644editdlrm
mac_cyrillic.py134540644editdlrm
mac_farsi.py151700644editdlrm
mac_greek.py137210644editdlrm
mac_iceland.py134980644editdlrm
mac_latin2.py141180644editdlrm
mac_roman.py134800644editdlrm
mac_romanian.py136610644editdlrm
mac_turkish.py135130644editdlrm
mbcs.py12110644editdlrm
oem.py10190644editdlrm
palmos.py135190644editdlrm
ptcp154.py140150644editdlrm
punycode.py68830644editdlrm
quopri_codec.py15250644editdlrm
raw_unicode_escape.py12080644editdlrm
rot_13.py24480755editdlrm
shift_jis.py10390644editdlrm
shift_jisx0213.py10590644editdlrm
shift_jis_2004.py10590644editdlrm
tis_620.py123000644editdlrm
undefined.py12990644editdlrm
unicode_escape.py13040644editdlrm
utf_7.py9460644editdlrm
utf_8.py10050644editdlrm
utf_8_sig.py41330644editdlrm
utf_16.py52360644editdlrm
utf_16_be.py10370644editdlrm
utf_16_le.py10370644editdlrm
utf_32.py51290644editdlrm
utf_32_be.py9300644editdlrm
utf_32_le.py9300644editdlrm
uu_codec.py28510644editdlrm
zlib_codec.py22040644editdlrm
__init__.py55880644editdlrm
Edit: /snap/core20/2769/usr/lib/python3.8/encodings/punycode.py (6883B)
""" Codec for the Punicode encoding, as specified in RFC 3492 Written by Martin v. Löwis. """ import codecs ##################### Encoding ##################################### def segregate(str): """3.1 Basic code point segregation""" base = bytearray() extended = set() for c in str: if ord(c) < 128: base.append(ord(c)) else: extended.add(c) extended = sorted(extended) return bytes(base), extended def selective_len(str, max): """Return the length of str, considering only characters below max.""" res = 0 for c in str: if ord(c) < max: res += 1 return res def selective_find(str, char, index, pos): """Return 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.""" l = len(str) while 1: pos += 1 if pos == l: return (-1, -1) c = str[pos] if c == char: return index+1, pos elif c < char: index += 1 def insertion_unsort(str, extended): """3.2 Insertion unsort coding""" oldchar = 0x80 result = [] oldindex = -1 for c in extended: index = pos = -1 char = ord(c) curlen = selective_len(str, char) delta = (curlen+1) * (char - oldchar) while 1: index,pos = selective_find(str,c,index,pos) if index == -1: break delta += index - oldindex result.append(delta-1) oldindex = index delta = 0 oldchar = char return result def T(j, bias): # Punycode parameters: tmin = 1, tmax = 26, base = 36 res = 36 * (j + 1) - bias if res < 1: return 1 if res > 26: return 26 return res digits = b"abcdefghijklmnopqrstuvwxyz0123456789" def generate_generalized_integer(N, bias): """3.3 Generalized variable-length integers""" result = bytearray() j = 0 while 1: t = T(j, bias) if N < t: result.append(digits[N]) return bytes(result) result.append(digits[t + ((N - t) % (36 - t))]) N = (N - t) // (36 - t) j += 1 def adapt(delta, first, numchars): if first: delta //= 700 else: delta //= 2 delta += delta // numchars # ((base - tmin) * tmax) // 2 == 455 divisions = 0 while delta > 455: delta = delta // 35 # base - tmin divisions += 36 bias = divisions + (36 * delta // (delta + 38)) return bias def generate_integers(baselen, deltas): """3.4 Bias adaptation""" # Punycode parameters: initial bias = 72, damp = 700, skew = 38 result = bytearray() bias = 72 for points, delta in enumerate(deltas): s = generate_generalized_integer(delta, bias) result.extend(s) bias = adapt(delta, points==0, baselen+points+1) return bytes(result) def punycode_encode(text): base, extended = segregate(text) deltas = insertion_unsort(text, extended) extended = generate_integers(len(base), deltas) if base: return base + b"-" + extended return extended ##################### Decoding ##################################### def decode_generalized_number(extended, extpos, bias, errors): """3.3 Generalized variable-length integers""" result = 0 w = 1 j = 0 while 1: try: char = ord(extended[extpos]) except IndexError: if errors == "strict": raise UnicodeError("incomplete punicode string") return extpos + 1, None extpos += 1 if 0x41 <= char <= 0x5A: # A-Z digit = char - 0x41 elif 0x30 <= char <= 0x39: digit = char - 22 # 0x30-26 elif errors == "strict": raise UnicodeError("Invalid extended code point '%s'" % extended[extpos-1]) else: return extpos, None t = T(j, bias) result += digit * w if digit < t: return extpos, result w = w * (36 - t) j += 1 def insertion_sort(base, extended, errors): """3.2 Insertion unsort coding""" char = 0x80 pos = -1 bias = 72 extpos = 0 while extpos < len(extended): newpos, delta = decode_generalized_number(extended, extpos, bias, errors) if delta is None: # There was an error in decoding. We can't continue because # synchronization is lost. return base pos += delta+1 char += pos // (len(base) + 1) if char > 0x10FFFF: if errors == "strict": raise UnicodeError("Invalid character U+%x" % char) char = ord('?') pos = pos % (len(base) + 1) base = base[:pos] + chr(char) + base[pos:] bias = adapt(delta, (extpos == 0), len(base)) extpos = newpos return base def punycode_decode(text, errors): if isinstance(text, str): text = text.encode("ascii") if isinstance(text, memoryview): text = bytes(text) pos = text.rfind(b"-") if pos == -1: base = "" extended = str(text, "ascii").upper() else: base = str(text[:pos], "ascii", errors) extended = str(text[pos+1:], "ascii").upper() return insertion_sort(base, extended, errors) ### Codec APIs class Codec(codecs.Codec): def encode(self, input, errors='strict'): res = punycode_encode(input) return res, len(input) def decode(self, input, errors='strict'): if errors not in ('strict', 'replace', 'ignore'): raise UnicodeError("Unsupported error handling "+errors) res = punycode_decode(input, errors) return res, len(input) class IncrementalEncoder(codecs.IncrementalEncoder): def encode(self, input, final=False): return punycode_encode(input) class IncrementalDecoder(codecs.IncrementalDecoder): def decode(self, input, final=False): if self.errors not in ('strict', 'replace', 'ignore'): raise UnicodeError("Unsupported error handling "+self.errors) return punycode_decode(input, self.errors) class StreamWriter(Codec,codecs.StreamWriter): pass class StreamReader(Codec,codecs.StreamReader): pass ### encodings module API def getregentry(): return codecs.CodecInfo( name='punycode', encode=Codec().encode, decode=Codec().decode, incrementalencoder=IncrementalEncoder, incrementaldecoder=IncrementalDecoder, streamwriter=StreamWriter, streamreader=StreamReader, )