def run(self): try: if self.url: self.collection = CollectionStorer(self.url, validateResourceNames=False) authFailures = 0 while authFailures < 2: try: self.result = self.collection.getCollectionContents() if self.collection.getSpecificOption("set-cookie"): self.collection.connection.cookie = self.collection.getSpecificOption( "set-cookie") self.cookie = self.collection.getSpecificOption( "set-cookie") break except AuthorizationError, e: if e.authType == "Basic": self.collection.connection.addBasicAuthorization( self.auth["user"], self.auth["password"]) elif e.authType == "Digest": info = parseDigestAuthInfo(e.authInfo) self.collection.connection.addDigestAuthorization( self.auth["user"], self.auth["password"], realm=info["realm"], qop=info["qop"], nonce=info["nonce"]) else: self.error = "Error: " + str(e) authFailures += 1 except Exception, e: self.error = "Error: " + str(e)
def _createConnection(self): """ Overwrites template method for connection creation. """ protocol = self._configuration.protocol hostname = self._configuration.hostname port = self._configuration.port connection = Connection(hostname, port, protocol=protocol) baseCollection = CollectionStorer(self._configuration.basePath, connection) try: try: baseCollection.validate() except AuthorizationError, error: username = self._configuration.username or "" password = self._configuration.password or "" if error.authType == "Basic": realm = re.search('realm="([^"]+)"', error.authInfo) if not realm is None: realm = realm.group(1) connection.addBasicAuthorization(username, password, realm) elif error.authType == "Digest": authInfo = parseDigestAuthInfo(error.authInfo) connection.addDigestAuthorization(username, password, realm=authInfo["realm"], qop=authInfo["qop"], nonce=authInfo["nonce"]) else: raise PersistenceError("Cannot create connection. Authentication type '%s' is not supported.") except (AttributeError, WebdavError), error: errorMessage = "Cannot create connection.\nReason:'%s'" % error.reason raise PersistenceError(errorMessage)
def _createConnection(self): """ Overwrites template method for connection creation. """ protocol = self._configuration.protocol hostname = self._configuration.hostname port = self._configuration.port connection = Connection(hostname, port, protocol=protocol) baseCollection = CollectionStorer(self._configuration.basePath, connection) try: try: baseCollection.validate() except AuthorizationError, error: username = self._configuration.username or "" password = self._configuration.password or "" if error.authType == "Basic": realm = re.search('realm="([^"]+)"', error.authInfo) if not realm is None: realm = realm.group(1) connection.addBasicAuthorization(username, password, realm) elif error.authType == "Digest": authInfo = parseDigestAuthInfo(error.authInfo) connection.addDigestAuthorization(username, password, realm=authInfo["realm"], qop=authInfo["qop"], nonce=authInfo["nonce"]) else: raise PersistenceError( "Cannot create connection. Authentication type '%s' is not supported." ) except (AttributeError, WebdavError), error: errorMessage = "Cannot create connection.\nReason:'%s'" % error.reason raise PersistenceError(errorMessage)
def run(self): try: if self.url: self.collection = CollectionStorer(self.url, validateResourceNames = False) authFailures = 0 while authFailures < 2: try: self.result = self.collection.getCollectionContents() if self.collection.getSpecificOption("set-cookie"): self.collection.connection.cookie = self.collection.getSpecificOption("set-cookie") self.cookie = self.collection.getSpecificOption("set-cookie") break except AuthorizationError, e: if e.authType == "Basic": self.collection.connection.addBasicAuthorization(self.auth["user"], self.auth["password"]) elif e.authType == "Digest": info = parseDigestAuthInfo(e.authInfo) self.collection.connection.addDigestAuthorization(self.auth["user"], self.auth["password"], realm=info["realm"], qop=info["qop"], nonce=info["nonce"]) else: self.error = "Error: " + str(e) authFailures += 1 except Exception, e: self.error = "Error: " + str(e)
def createConnection(self, webdavLogin, webdavPasswd): from webdav.WebdavClient import CollectionStorer, AuthorizationError, \ parseDigestAuthInfo #from webdav.logger import _defaultLoggerName isConnected = False webdavConnection = CollectionStorer(self.webdavHost + self.webdavBasePath, validateResourceNames=False) webdavConnection.connection.logger.setLevel(logging.WARNING) time_delta = None #Test KhtNotes folder and authenticate authFailures = 0 while authFailures < 4: try: webdavConnection.validate() response = webdavConnection.getSpecificOption('date') print response try: import rfc822 local_datetime = int(time.time()) self.logger.debug('Timezone: %f, Timealtzone: %f', time.timezone, time.altzone) self.logger.debug('Server Time: %s' % response) remote_datetime = rfc822.parsedate(response) self.logger.debug('Parsed server time %s' % str(remote_datetime)) time_delta = local2utc(time.mktime(remote_datetime)) \ - local_datetime self.logger.debug('Time delta: %f' % time_delta) except Exception, err: time_delta = None print 'error parsing date', err self.logger.error('Failed to parse datetime: %s:%s' % (unicode(type(err)), unicode(err))) isConnected = True break # break out of the authorization failure counter except AuthorizationError, err: if err.authType == "Basic": webdavConnection.connection.\ addBasicAuthorization(webdavLogin, webdavPasswd) elif err.authType == "Digest": info = parseDigestAuthInfo(err.authInfo) webdavConnection.connection.\ addDigestAuthorization(webdavLogin, webdavPasswd, realm=info["realm"], qop=info["qop"], nonce=info["nonce"]) elif authFailures >= 2: self.on_error.emit('Wrong login or password') self.logger.error('Wrong login or password') else: self.logger.error('%s:%s' % (unicode(type(err)), unicode(err))) self.on_error.emit(unicode(err) + ':' + unicode(err))
def createConnection(self, webdavLogin, webdavPasswd): from webdav.WebdavClient import CollectionStorer, AuthorizationError, \ parseDigestAuthInfo # from webdav.logger import _defaultLoggerName isConnected = False webdavConnection = CollectionStorer(self.webdavUrl, validateResourceNames=False) webdavConnection.connection.logger.setLevel(logging.WARNING) time_delta = None # Test KhtNotes folder and authenticate authFailures = 0 while authFailures < 4: try: webdavConnection.validate() response = webdavConnection.getSpecificOption('date') local_datetime = int(time.time()) # print response try: import rfc822 self.logger.debug('Timezone: %f, Timealtzone: %f', time.timezone, time.altzone) self.logger.debug('Server Time: %s' % response) remote_datetime = rfc822.parsedate(response) self.logger.debug('Parsed server time %s' % str(remote_datetime)) time_delta = local2utc(time.mktime(remote_datetime)) \ - local_datetime self.logger.debug('Time delta: %f' % time_delta) except Exception as err: time_delta = None print 'error parsing date', err self.logger.error('Failed to parse datetime: %s:%s' % (str(type(err)), str(err))) isConnected = True break # break out of the authorization failure counter except AuthorizationError as err: if err.authType == "Basic": webdavConnection.connection.\ addBasicAuthorization(webdavLogin, webdavPasswd) elif err.authType == "Digest": info = parseDigestAuthInfo(err.authInfo) webdavConnection.connection.\ addDigestAuthorization(webdavLogin, webdavPasswd, realm=info["realm"], qop=info["qop"], nonce=info["nonce"]) elif authFailures >= 2: self.logger.error('Wrong login or password') raise IncorrectSyncParameters('Wrong login or password') else: self.logger.error('%s:%s' % (str(type(err)), str(err))) raise IncorrectSyncParameters('Can\'t connect to server') except Exception as err2: self.logger.error('%s:%s' % (str(type(err2)), str(err2))) raise IncorrectSyncParameters('Can\'t connect to server') authFailures += 1 return (isConnected, webdavConnection, time_delta)