Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __init__(self, parent, reason=EXPIRED):
super(self.__class__, self).__init__(parent=None)
uic.loadUi(RELINK_DIALOG_PATH, self)
# import OAuth2Session here because of ~40 MB memory footprint
from maestral.sync.oauth import OAuth2Session
self._parent = parent
self.auth_session = OAuth2Session()
self.setModal(True)
self.setWindowFlags(Qt.WindowTitleHint | Qt.CustomizeWindowHint)
# format text labels
if reason is self.EXPIRED:
self.titleLabel.setText("Dropbox Access expired")
formatted_text = self.infoLabel.text().format(
"has expired", self.auth_session.get_auth_url())
elif reason is self.REVOKED:
self.titleLabel.setText("Dropbox Access revoked")
formatted_text = self.infoLabel.text().format(
"has been revoked", self.auth_session.get_auth_url())
else:
raise ValueError("'reason' must be RelinkDialog.EXPIRED or "
"RelinkDialog.REVOKED.")
def on_verify_token_finished(self, res):
from maestral.sync.oauth import OAuth2Session
if res == OAuth2Session.Success:
self.auth_session.save_creds()
self.lineEditAuthCode.setText(self.VALID_MSG)
QtWidgets.QApplication.processEvents()
QtCore.QTimer.singleShot(200, self._parent.restart)
elif res == OAuth2Session.InvalidToken:
self.lineEditAuthCode.setText(self.INVALID_MSG)
self.set_ui_idle()
elif res == OAuth2Session.ConnectionFailed:
self.lineEditAuthCode.setText(self.CONNECTION_ERR_MSG)
self.set_ui_idle()
def on_link(self):
self.auth_session = OAuth2Session()
self.auth_url = self.auth_session.get_auth_url()
prompt = self.labelAuthLink.text().format(self.auth_url)
self.labelAuthLink.setText(prompt)
self.stackedWidget.fadeInIdx(1)
self.pushButtonAuthPageLink.setFocus()
def __init__(self):
# get Dropbox session
self.auth = OAuth2Session()
if not self.auth.load_token():
self.auth.link()
self._last_longpoll = None
self._backoff = 0
self._retry_count = 0
# initialize API client
self.dbx = dropbox.Dropbox(self.auth.access_token, session=SESSION,
user_agent=USER_AGENT, timeout=60)
def pending_link():
"""Bool indicating if auth tokens are stored in the system's keychain."""
auth_session = OAuth2Session()
return auth_session.load_token() is None
def __init__(self, timeout=_timeout):
# get Dropbox session
self.auth = OAuth2Session()
if not self.auth.load_token():
self.auth.link()
self._timeout = timeout
self._last_longpoll = None
self._backoff = 0
self._retry_count = 0
# initialize API client
self.dbx = dropbox.Dropbox(
self.auth.access_token,
session=SESSION,
user_agent=USER_AGENT,
timeout=self._timeout
)
def on_verify_token_finished(self, res):
if res == OAuth2Session.Success:
self.auth_session.save_creds()
# switch to next page
self.stackedWidget.slideInIdx(2)
self.pushButtonDropboxPathSelect.setFocus()
self.lineEditAuthCode.clear() # clear since we might come back on unlink
# start Maestral after linking to Dropbox account
self.mdbx = Maestral(run=False)
self.mdbx.get_account_info()
elif res == OAuth2Session.InvalidToken:
msg = "Please make sure that you entered the correct authentication token."
msg_box = UserDialog("Authentication failed.", msg, parent=self)
msg_box.open()
elif res == OAuth2Session.ConnectionFailed:
msg = "Please make sure that you are connected to the internet and try again."