def connect(self):
retries = <NUM_LIT:0><EOL>while retries < MAX_CONNECTION_RETRIES:<EOL><INDENT>try:<EOL><INDENT>self._connection.connect()<EOL>logger.info('<STR_LIT>')<EOL>return<EOL><DEDENT>except Exception:  <EOL><INDENT>self._connection.close()<EOL>retries += <NUM_LIT:1><EOL>logger.exception('<STR_LIT>', retries, MAX_CONNECTION_RETRIES)<EOL><DEDENT><DEDENT>raise ConnectionFailed()<EOL>
Establish a connection to APNs. If already connected, the function does nothing. If the
connection fails, the function retries up to MAX_CONNECTION_RETRIES times.