MCPcopy Index your code
hub / github.com/python/cpython / _Authenticator

Class _Authenticator

Lib/imaplib.py:1715–1757  ·  view source on GitHub ↗

Private class to provide en/decoding for base64-based authentication conversation.

Source from the content-addressed store, hash-verified

1713
1714
1715class _Authenticator:
1716
1717 """Private class to provide en/decoding
1718 for base64-based authentication conversation.
1719 """
1720
1721 def __init__(self, mechinst):
1722 self.mech = mechinst # Callable object to provide/process data
1723
1724 def process(self, data):
1725 ret = self.mech(self.decode(data))
1726 if ret is None:
1727 return b'*' # Abort conversation
1728 return self.encode(ret)
1729
1730 def encode(self, inp):
1731 #
1732 # Invoke binascii.b2a_base64 iteratively with
1733 # short even length buffers, strip the trailing
1734 # line feed from the result and append. "Even"
1735 # means a number that factors to both 6 and 8,
1736 # so when it gets to the end of the 8-bit input
1737 # there's no partial 6-bit output.
1738 #
1739 oup = b''
1740 if isinstance(inp, str):
1741 inp = inp.encode('utf-8')
1742 while inp:
1743 if len(inp) > 48:
1744 t = inp[:48]
1745 inp = inp[48:]
1746 else:
1747 t = inp
1748 inp = b''
1749 e = binascii.b2a_base64(t)
1750 if e:
1751 oup = oup + e[:-1]
1752 return oup
1753
1754 def decode(self, inp):
1755 if not inp:
1756 return b''
1757 return binascii.a2b_base64(inp)
1758
1759Months = ' Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec'.split(' ')
1760Mon2num = {s.encode():n+1 for n, s in enumerate(Months[1:])}

Callers 1

authenticateMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…