# HG changeset patch # User Chris Cannam # Date 1544016051 0 # Node ID e4d18e8ef4305a5fde08f3b96799bb3e9e027510 # Parent 88fa1544b4077865c42633a422aaff2e734ef260 Update for newer APIs diff -r 88fa1544b407 -r e4d18e8ef430 easyhg.py --- a/easyhg.py Wed Dec 05 09:44:10 2018 +0000 +++ b/easyhg.py Wed Dec 05 13:20:51 2018 +0000 @@ -35,7 +35,7 @@ sys.path.append(easyhg_import_path + "/" + version_suffix) sys.path.append(easyhg_import_path) -# Try to load the PyQt4 module that we need. If this fails, we should +# Try to load the PyQt5 module that we need. If this fails, we should # bail out later (in uisetup), because if we bail out now, Mercurial # will just continue without us and report success. The invoking # application needs to be able to discover whether the module load @@ -44,7 +44,7 @@ # easyhg_pyqt_ok = True try: - from PyQt4 import QtCore, QtGui + from PyQt5 import QtCore, QtGui, QtWidgets except ImportError: easyhg_pyqt_ok = False easyhg_qtapp = None @@ -82,15 +82,13 @@ self.auth_file = self.ui.config('easyhg', 'authfile') self.use_auth_file = (easyhg_authfile_imports_ok and - self.auth_key and self.auth_file) + self.auth_key and self.auth_file) self.auth_config = None self.auth_cipher = None self.remember = False if self.use_auth_file: - self.auth_cipher = AES.new(self.auth_key, AES.MODE_CBC, - os.urandom(16)) self.auth_file = os.path.expanduser(self.auth_file) self.load_auth_data() @@ -98,19 +96,22 @@ if self.use_auth_file: self.save_auth_data() - def encrypt(self, text): + def encrypt(self, utext): iv = os.urandom(12) + text = utext.encode('utf-8') text = '%s.%d.%s.easyhg' % (base64.b64encode(iv), len(text), text) text += (16 - (len(text) % 16)) * ' ' - ctext = base64.b64encode(self.auth_cipher.encrypt(text)) + cipher = AES.new(self.auth_key, AES.MODE_CBC, os.urandom(16)) + ctext = base64.b64encode(cipher.encrypt(text)) return ctext def decrypt(self, ctext): try: - text = self.auth_cipher.decrypt(base64.b64decode(ctext)) + cipher = AES.new(self.auth_key, AES.MODE_CBC, os.urandom(16)) + text = cipher.decrypt(base64.b64decode(ctext)) (iv, d, text) = text.partition('.') (tlen, d, text) = text.partition('.') - return text[0:int(tlen)] + return text[0:int(tlen)].decode('utf-8') except: self.ui.write("failed to decrypt/convert cached data!") return '' @@ -243,41 +244,41 @@ if not repeat: return (self.auth_store.user, self.auth_store.passwd) - dialog = QtGui.QDialog() - layout = QtGui.QGridLayout() + dialog = QtWidgets.QDialog() + layout = QtWidgets.QGridLayout() dialog.setLayout(layout) heading = _('Login required') if repeat: heading = _('Login failed: please try again') label_text = _(('
Please provide your login details for the repository at%s
:') % (heading, self.auth_store.argless_url()))
- layout.addWidget(QtGui.QLabel(label_text), 0, 0, 1, 2)
+ layout.addWidget(QtWidgets.QLabel(label_text), 0, 0, 1, 2)
- user_field = QtGui.QLineEdit()
+ user_field = QtWidgets.QLineEdit()
if self.auth_store.user: user_field.setText(self.auth_store.user)
- layout.addWidget(QtGui.QLabel(_('User:')), 1, 0)
+ layout.addWidget(QtWidgets.QLabel(_('User:')), 1, 0)
layout.addWidget(user_field, 1, 1)
- passwd_field = QtGui.QLineEdit()
- passwd_field.setEchoMode(QtGui.QLineEdit.Password)
+ passwd_field = QtWidgets.QLineEdit()
+ passwd_field.setEchoMode(QtWidgets.QLineEdit.Password)
if self.auth_store.passwd: passwd_field.setText(self.auth_store.passwd)
- layout.addWidget(QtGui.QLabel(_('Password:')), 2, 0)
+ layout.addWidget(QtWidgets.QLabel(_('Password:')), 2, 0)
layout.addWidget(passwd_field, 2, 1)
user_field.textChanged.connect(passwd_field.clear)
remember_field = None
if self.auth_store.use_auth_file:
- remember_field = QtGui.QCheckBox()
+ remember_field = QtWidgets.QCheckBox()
remember_field.setChecked(self.auth_store.remember)
remember_field.setText(_('Remember these details while EasyMercurial is running'))
layout.addWidget(remember_field, 3, 1)
- warning_field = QtGui.QLabel()
+ warning_field = QtWidgets.QLabel()
warning_field.setText(_('