コード例 #1
0
 def exception_handler(self):
     try:
         yield
     except requests.ConnectionError:
         raise exceptions.ConnectionFailure(self)
     except:
         raise exceptions.ProviderOperationFailure(self)
コード例 #2
0
ファイル: BoxProvider.py プロジェクト: Cloudxtreme/daruma
    def finish_connection(self, url):
        params = parse_url(url)

        try:  # get auth_token
            auth_token = params["code"]
            assert self.csrf_token == params["state"]
        except AssertionError:  # csrf mismatch or csrf not found
            raise exceptions.AuthFailure(self)
        except KeyError:
            try:
                error_code = params["error"]
            except KeyError:
                raise exceptions.ProviderOperationFailure(self)
            if error_code == "invalid_request" or error_code == "unsupported_response_type":
                raise exceptions.ProviderOperationFailure(self)
            elif error_code == "access_denied" or error_code == "server_error":
                raise exceptions.AuthFailure(self)
            elif error_code == "temporarily_unavailable":
                raise exceptions.ConnectionFailure(self)
            else:
                raise exceptions.ProviderOperationFailure(self)

        credentials = {}
        with self.exception_handler():
            credentials["access_token"], credentials["refresh_token"] = self.oauth.authenticate(auth_token)

        self._connect(credentials)
コード例 #3
0
ファイル: TestProvider.py プロジェクト: Cloudxtreme/daruma
    def exception_handler(self, check_failing=True):
        print "done"
        self.state_timer -= 1
        if self.state_timer == 0:
            self.state = TestProviderState.ACTIVE

        if self.state == TestProviderState.OFFLINE:
            raise exceptions.ConnectionFailure(self)
        if self.state == TestProviderState.UNAUTHENTICATED:
            raise exceptions.AuthFailure(self)
        if check_failing and self.state == TestProviderState.FAILING:
            raise exceptions.ProviderOperationFailure(self)
        yield
コード例 #4
0
ファイル: BoxProvider.py プロジェクト: Cloudxtreme/daruma
 def exception_handler(self):
     try:
         yield
     except BoxOAuthException:
         raise exceptions.AuthFailure(self)
     except BoxAPIException:
         raise exceptions.ProviderOperationFailure(self)
     except ReadTimeout:
         raise exceptions.ConnectionFailure(self)
     except Exception:
         raise exceptions.ProviderOperationFailure(self)
     finally:
         self._persist_tokens()
コード例 #5
0
 def exception_handler(self):
     try:
         yield
     except exceptions.ProviderFailure:
         raise
     except HttpError as e:
         logger.error("HttpError in GoogleDriveProvider: %s", e)
         if e.resp.status in [401, 403]:
             raise exceptions.AuthFailure(self)
         raise exceptions.ProviderOperationFailure(self)
     except httplib2.ServerNotFoundError as e:
         logger.error("ServerNotFoundError in GoogleDriveProvider: %s", e)
         raise exceptions.ConnectionFailure(self)
     except Exception as e:
         logger.error("General error in GoogleDriveProvider: %s", e)
         raise exceptions.ProviderOperationFailure(self)
コード例 #6
0
 def connect(self, provider_path):
     """
     Connects to the provider
     provider_path: an optional string holding the relative or
         absolute base path for the backing directory on the filesystem.
         Defaults to the current directory.
     """
     self.provider_path = provider_path
     try:
         translated_root_dir = self._get_translated_filepath("")
         os.makedirs(translated_root_dir, DIRECTORY_MODE)
     except (IOError, OSError) as error:
         if error.errno is not errno.EEXIST:
             raise exceptions.ConnectionFailure(
                 self, "errno was %d in connect" % error.errno)
     self.credential_manager.set_user_credentials(self.__class__, self.uid,
                                                  None)
コード例 #7
0
ファイル: DropboxProvider.py プロジェクト: Cloudxtreme/daruma
    def exception_handler(self):
        try:
            yield

        except (dropbox.oauth.NotApprovedException,
                dropbox.oauth.BadStateException, dropbox.oauth.CsrfException,
                dropbox.oauth.BadRequestException):
            raise exceptions.AuthFailure(self)

        except dropbox.oauth.ProviderException:
            raise exceptions.ProviderOperationFailure(self)

        except urllib3.exceptions.MaxRetryError:
            raise exceptions.ConnectionFailure(self)

        except dropbox.rest.ErrorResponse as e:
            if e.status in [401, 400]:
                raise exceptions.AuthFailure(self)
            raise exceptions.ProviderOperationFailure(self)

        except Exception:
            raise exceptions.ProviderOperationFailure(self)