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

Method _connect

Lib/imaplib.py:231–269  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

229
230
231 def _connect(self):
232 # Create unique tag for this session,
233 # and compile tagged response matcher.
234
235 self.tagpre = Int2AP(random.randint(4096, 65535))
236 self.tagre = re.compile(br'(?P<tag>'
237 + self.tagpre
238 + br'\d+) (?P<type>[A-Z]+) (?P<data>.*)', re.ASCII)
239
240 # Get server welcome message,
241 # request and store CAPABILITY response.
242
243 if __debug__:
244 self._cmd_log_len = 10
245 self._cmd_log_idx = 0
246 self._cmd_log = {} # Last '_cmd_log_len' interactions
247 if self.debug >= 1:
248 self._mesg('new IMAP4 connection, tag=%s' % self.tagpre)
249
250 self.welcome = self._get_response()
251 if 'PREAUTH' in self.untagged_responses:
252 self.state = 'AUTH'
253 elif 'OK' in self.untagged_responses:
254 self.state = 'NONAUTH'
255 else:
256 raise self.error(self.welcome)
257
258 self._get_capabilities()
259 if __debug__:
260 if self.debug >= 3:
261 self._mesg('CAPABILITIES: %r' % (self.capabilities,))
262
263 for version in AllowedVersions:
264 if not version in self.capabilities:
265 continue
266 self.PROTOCOL_VERSION = version
267 return
268
269 raise self.error('server not IMAP4 compliant')
270
271
272 def __getattr__(self, attr):

Callers 1

__init__Method · 0.95

Calls 7

_mesgMethod · 0.95
_get_responseMethod · 0.95
_get_capabilitiesMethod · 0.95
Int2APFunction · 0.85
randintMethod · 0.80
compileMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected