launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26273
[Merge] ~cjwatson/launchpad:py3-exception-argument-extraction into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-exception-argument-extraction into launchpad:master.
Commit message:
Update exception argument extraction for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397863
Exceptions are no longer directly indexable, and no longer have a 'message' attribute by default.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-exception-argument-extraction into launchpad:master.
diff --git a/lib/lp/archiveuploader/tests/test_changesfile.py b/lib/lp/archiveuploader/tests/test_changesfile.py
index 3daf5cc..b599019 100644
--- a/lib/lp/archiveuploader/tests/test_changesfile.py
+++ b/lib/lp/archiveuploader/tests/test_changesfile.py
@@ -348,7 +348,7 @@ class ChangesFileTests(TestCase):
changes = self.createChangesFile("mypkg_0.1_i386.changes", contents)
[error] = list(changes.processFiles())
self.assertEqual(
- "Mismatch between Checksums-Sha1 and Files fields.", error[0])
+ "Mismatch between Checksums-Sha1 and Files fields.", error.args[0])
def test_processFiles_rejects_duplicate_filenames(self):
# processFiles ensures that Files lists each file only once.
@@ -356,7 +356,7 @@ class ChangesFileTests(TestCase):
contents['Files'].append(contents['Files'][0])
changes = self.createChangesFile("mypkg_0.1_i386.changes", contents)
[error] = list(changes.processFiles())
- self.assertEqual("Duplicate filenames in Files field.", error[0])
+ self.assertEqual("Duplicate filenames in Files field.", error.args[0])
class TestSignatureVerification(TestCase):
diff --git a/lib/lp/archiveuploader/tests/test_dscfile.py b/lib/lp/archiveuploader/tests/test_dscfile.py
index a82aa6b..1e8bf36 100644
--- a/lib/lp/archiveuploader/tests/test_dscfile.py
+++ b/lib/lp/archiveuploader/tests/test_dscfile.py
@@ -143,7 +143,7 @@ class TestDSCFileWithDatabase(TestCaseWithFactory):
dsc = DSCFile(
path, {}, 426, 'main/editors', 'priority',
'badhash', '1.0-1', FakeChangesFile(), policy, DevNullLogger())
- errors = [e[0] for e in dsc.verify()]
+ errors = [e.args[0] for e in dsc.verify()]
self.assertEqual(
['File badhash_1.0-1.tar.gz mentioned in the changes has a SHA256'
' mismatch. a29ec2370df83193c3fb2cc9e1287dbfe9feba04108ccfa490bb'
diff --git a/lib/lp/bugs/browser/bugalsoaffects.py b/lib/lp/bugs/browser/bugalsoaffects.py
index b4f5ea5..b65e691 100644
--- a/lib/lp/bugs/browser/bugalsoaffects.py
+++ b/lib/lp/bugs/browser/bugalsoaffects.py
@@ -177,7 +177,7 @@ class ChooseProductStep(LinkPackgingMixin, AlsoAffectsStep):
try:
validate_new_target(self.context.bug, data.get('product'))
except IllegalTarget as e:
- self.setFieldError('product', e[0])
+ self.setFieldError('product', e.args[0])
return
entered_product = self.request.form.get(self.widgets['product'].name)
@@ -460,9 +460,9 @@ class DistroBugTaskCreationStep(BugTaskCreationStep):
data['sourcepackagename'] = target
except IllegalTarget as e:
if sourcepackagename:
- self.setFieldError('sourcepackagename', e[0])
+ self.setFieldError('sourcepackagename', e.args[0])
else:
- self.setFieldError('distribution', e[0])
+ self.setFieldError('distribution', e.args[0])
super(DistroBugTaskCreationStep, self).validateStep(data)
@@ -852,7 +852,7 @@ class BugAlsoAffectsProductWithProductCreationView(LinkPackgingMixin,
try:
validate_target(self.context.bug, project)
except IllegalTarget as e:
- self.setFieldError('existing_product', e[0])
+ self.setFieldError('existing_product', e.args[0])
@action('Use Existing Project', name='use_existing_product',
validator=validate_existing_product)
diff --git a/lib/lp/bugs/browser/bugtask.py b/lib/lp/bugs/browser/bugtask.py
index f21c742..a9d9953 100644
--- a/lib/lp/bugs/browser/bugtask.py
+++ b/lib/lp/bugs/browser/bugtask.py
@@ -1369,7 +1369,7 @@ class BugTaskEditView(LaunchpadEditFormView, BugTaskBugWatchMixin,
self.context.validateTransitionToTarget(
new_target, check_source_package=False)
except IllegalTarget as e:
- self.setFieldError(error_field, e[0])
+ self.setFieldError(error_field, e.args[0])
def updateContextFromData(self, data, context=None):
"""Updates the context object using the submitted form data.
diff --git a/lib/lp/bugs/mail/commands.py b/lib/lp/bugs/mail/commands.py
index 89426f0..6c5b831 100644
--- a/lib/lp/bugs/mail/commands.py
+++ b/lib/lp/bugs/mail/commands.py
@@ -630,7 +630,7 @@ class AffectsEmailCommand(EmailCommand):
'cannot-add-task.txt',
error_templates=error_templates,
bug_id=bug.id,
- target_name=bug_target.name, reason=e[0]),
+ target_name=bug_target.name, reason=e.args[0]),
stop_processing=True)
event = ObjectCreatedEvent(bugtask)
diff --git a/lib/lp/bugs/model/bugtask.py b/lib/lp/bugs/model/bugtask.py
index d30232a..d82c3b0 100644
--- a/lib/lp/bugs/model/bugtask.py
+++ b/lib/lp/bugs/model/bugtask.py
@@ -341,7 +341,7 @@ def validate_target(bug, target, retarget_existing=True,
target.distribution.guessPublishedSourcePackageName(
target.sourcepackagename.name)
except NotFoundError as e:
- raise IllegalTarget(e[0])
+ raise IllegalTarget(e.args[0])
legal_types = target.pillar.getAllowedBugInformationTypes()
new_pillar = target.pillar not in bug.affected_pillars
diff --git a/lib/lp/code/browser/branch.py b/lib/lp/code/browser/branch.py
index 6ea17ac..f7502e7 100644
--- a/lib/lp/code/browser/branch.py
+++ b/lib/lp/code/browser/branch.py
@@ -791,7 +791,7 @@ class BranchEditFormView(LaunchpadEditFormView):
try:
self.context.setTarget(self.user, project=target)
except BranchTargetError as e:
- self.setFieldError('target', e.message)
+ self.setFieldError('target', e.args[0])
return
changed = True
diff --git a/lib/lp/code/browser/gitrepository.py b/lib/lp/code/browser/gitrepository.py
index 2552ffb..89600f9 100644
--- a/lib/lp/code/browser/gitrepository.py
+++ b/lib/lp/code/browser/gitrepository.py
@@ -642,7 +642,7 @@ class GitRepositoryEditFormView(LaunchpadEditFormView):
try:
self.context.setTarget(target, self.user)
except GitTargetError as e:
- self.setFieldError("target", e.message)
+ self.setFieldError("target", e.args[0])
return
changed = True
if IPerson.providedBy(target):
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index 171f7a3..780c236 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.py
@@ -2575,7 +2575,8 @@ class ProjectAddStepTwo(StepView, ProductLicenseMixin, ReturnToReferrerMixin):
ProductLicenseMixin.validate(self, data)
if data.get('disclaim_maintainer') and self.errors:
# The checkbox supersedes the owner text input.
- errors = [error for error in self.errors if error[0] == 'owner']
+ errors = [
+ error for error in self.errors if error.args[0] == 'owner']
for error in errors:
self.errors.remove(error)
diff --git a/lib/lp/registry/browser/tests/distributionmirror-views.txt b/lib/lp/registry/browser/tests/distributionmirror-views.txt
index 29297df..244f4ce 100644
--- a/lib/lp/registry/browser/tests/distributionmirror-views.txt
+++ b/lib/lp/registry/browser/tests/distributionmirror-views.txt
@@ -88,7 +88,7 @@ not significant).
>>> bad_form['field.http_base_url'] = 'http://secret.me'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
The distribution mirror ... is already registered with this URL.
The same is true for a FTP URL.
@@ -99,7 +99,7 @@ The same is true for a FTP URL.
>>> bad_form['field.ftp_base_url'] = 'ftp://now-here.me'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
The distribution mirror ... is already registered with this URL.
The same is true for a rsync URL.
@@ -109,7 +109,7 @@ The same is true for a rsync URL.
>>> bad_form['field.rsync_base_url'] = 'rsync://nowhere.me'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
The distribution mirror ... is already registered with this URL.
A mirror must have an ftp, HTTPS or http URL.
@@ -127,7 +127,7 @@ The URL cannot contain a fragment.
>>> bad_form['field.http_base_url'] = 'http://secret.me/#fragement'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
URIs with fragment identifiers are not allowed.
The URL cannot contain a query string.
@@ -135,7 +135,7 @@ The URL cannot contain a query string.
>>> bad_form['field.http_base_url'] = 'http://secret.me/?query=string'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
URIs with query strings are not allowed.
The HTTPS URL may not have an HTTP scheme.
@@ -144,7 +144,7 @@ The HTTPS URL may not have an HTTP scheme.
>>> bad_form['field.https_base_url'] = 'http://secret.me/#fragement'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
The URI scheme "http" is not allowed.
Only URIs with the following schemes may be used: https
@@ -154,7 +154,7 @@ The HTTPS URL cannot contain a fragment.
>>> bad_form['field.https_base_url'] = 'https://secret.me/#fragement'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
URIs with fragment identifiers are not allowed.
The URL cannot contain a query string.
@@ -163,7 +163,7 @@ The URL cannot contain a query string.
>>> bad_form['field.https_base_url'] = 'https://secret.me/?query=string'
>>> view = create_initialized_view(ubuntu, '+newmirror', form=bad_form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
URIs with query strings are not allowed.
diff --git a/lib/lp/registry/browser/tests/distroseries-views.txt b/lib/lp/registry/browser/tests/distroseries-views.txt
index 06dc916..7f36c0c 100644
--- a/lib/lp/registry/browser/tests/distroseries-views.txt
+++ b/lib/lp/registry/browser/tests/distroseries-views.txt
@@ -32,9 +32,9 @@ distroseries being tested.
... print('%d errors' % len(view.errors))
... for error in view.errors:
... try:
- ... name, title, message = error
+ ... name, title, message = error.args
... except ValueError:
- ... title, message = error
+ ... title, message = error.args
... print('%s: %s' % (title, message))
... print('Name:', distroseries.name)
... print('Version:', distroseries.version)
@@ -340,7 +340,7 @@ The distroseries name is unique.
>>> form['field.version'] = '2009.07'
>>> view = create_initialized_view(ubuntu, '+addseries', form=form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
sane is already in use by another series.
The distroseries name cannot contain spaces.
@@ -348,7 +348,7 @@ The distroseries name cannot contain spaces.
>>> form['field.name'] = 'insane name'
>>> view = create_initialized_view(ubuntu, '+addseries', form=form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
Invalid name 'insane name'...
@@ -361,7 +361,7 @@ Versions cannot contain spaces.
>>> form['field.version'] = '6.06 LTS'
>>> view = create_initialized_view(ubuntu, '+addseries', form=form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
6.06 LTS is not a valid version
The distroseries version must be a valid debversion.
@@ -369,7 +369,7 @@ The distroseries version must be a valid debversion.
>>> form['field.version'] = 'Hardy-6.06-LTS'
>>> view = create_initialized_view(ubuntu, '+addseries', form=form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
'Hardy-6.06-LTS': Could not parse version...
The distroseries version is unique to a distribution. Version '2009.06'
@@ -382,7 +382,7 @@ cannot be reused by another Ubuntu series.
>>> form['field.version'] = '2009.06'
>>> view = create_initialized_view(ubuntu, '+addseries', form=form)
>>> for error in view.errors:
- ... print(error[2])
+ ... print(error.args[2])
2009.06 is already in use by another version in this distribution.
But version '2009.06' can be used by another distribution.
diff --git a/lib/lp/registry/browser/tests/peoplemerge-views.txt b/lib/lp/registry/browser/tests/peoplemerge-views.txt
index f059ad4..6285bb6 100644
--- a/lib/lp/registry/browser/tests/peoplemerge-views.txt
+++ b/lib/lp/registry/browser/tests/peoplemerge-views.txt
@@ -50,7 +50,7 @@ Attempting to merge a non-existent team results in an error.
>>> len(view.errors)
2
>>> for error in view.errors:
- ... print(error[0])
+ ... print(error.args[0])
Invalid value
Invalid value
diff --git a/lib/lp/registry/browser/tests/person-admin-views.txt b/lib/lp/registry/browser/tests/person-admin-views.txt
index 2564e38..35a7a7b 100644
--- a/lib/lp/registry/browser/tests/person-admin-views.txt
+++ b/lib/lp/registry/browser/tests/person-admin-views.txt
@@ -142,7 +142,7 @@ No one can force account status to an invalid transition:
... 'field.actions.change': 'Change',
... }
>>> view = create_initialized_view(user, '+reviewaccount', form=form)
- >>> [e[2] for e in view.errors]
+ >>> [e.args[2] for e in view.errors]
[AccountStatusError(u'The status cannot change from Suspended to Active')]
diff --git a/lib/lp/registry/browser/tests/test_milestone.py b/lib/lp/registry/browser/tests/test_milestone.py
index 0fa47b7..91a253a 100644
--- a/lib/lp/registry/browser/tests/test_milestone.py
+++ b/lib/lp/registry/browser/tests/test_milestone.py
@@ -191,7 +191,7 @@ class TestAddMilestoneViews(TestCaseWithFactory):
'field.actions.register': 'Register Milestone',
}
view = create_initialized_view(self.series, '+addmilestone', form=form)
- error_msg = view.errors[0].errors[0]
+ error_msg = view.errors[0].errors.args[0]
expected_msg = (
"Date could not be formatted. Provide a date formatted "
"like YYYY-MM-DD format. The year must be after 1900.")
diff --git a/lib/lp/registry/browser/tests/test_person_webservice.py b/lib/lp/registry/browser/tests/test_person_webservice.py
index e161a44..07685fb 100644
--- a/lib/lp/registry/browser/tests/test_person_webservice.py
+++ b/lib/lp/registry/browser/tests/test_person_webservice.py
@@ -336,7 +336,7 @@ class PersonSetWebServiceTests(TestCaseWithFactory):
'/people?ws.op=getByEmail&email=foo@').jsonBody)
# XXX wgrant bug=1088358: This escaping shouldn't be here; it's
# not HTML.
- self.assertEqual("email: Invalid email 'foo@'.", e[0])
+ self.assertEqual("email: Invalid email 'foo@'.", e.args[0])
def test_getByOpenIDIdentifier(self):
# You can get a person by their OpenID identifier URL.
diff --git a/lib/lp/registry/browser/tests/test_product.py b/lib/lp/registry/browser/tests/test_product.py
index 7645a74..70a99ea 100644
--- a/lib/lp/registry/browser/tests/test_product.py
+++ b/lib/lp/registry/browser/tests/test_product.py
@@ -386,7 +386,7 @@ class TestProductAddView(TestCaseWithFactory):
del form['field.disclaim_maintainer']
view = create_initialized_view(self.product_set, '+new', form=form)
self.assertEqual(1, len(view.view.errors))
- self.assertEqual('owner', view.view.errors[0][0])
+ self.assertEqual('owner', view.view.errors[0].args[0])
def test_disclaim_maitainer_empty_supersedes_owner(self):
# Errors for the owner field are ignored when disclaim_maintainer is
diff --git a/lib/lp/services/openid/extensions/macaroon.py b/lib/lp/services/openid/extensions/macaroon.py
index 97a1731..5183e15 100644
--- a/lib/lp/services/openid/extensions/macaroon.py
+++ b/lib/lp/services/openid/extensions/macaroon.py
@@ -85,7 +85,7 @@ def get_macaroon_ns(message):
except KeyError as why:
# An alias for the string 'macaroon' already exists, but it's
# defined for something other than issuing a discharge macaroon.
- raise MacaroonNamespaceError(why[0])
+ raise MacaroonNamespaceError(why.args[0])
return MACAROON_NS
diff --git a/lib/lp/snappy/model/snapbuildjob.py b/lib/lp/snappy/model/snapbuildjob.py
index 298c00f..bcdbcd2 100644
--- a/lib/lp/snappy/model/snapbuildjob.py
+++ b/lib/lp/snappy/model/snapbuildjob.py
@@ -351,7 +351,7 @@ class SnapStoreUploadJob(SnapBuildJobDerived):
except Exception as e:
if (isinstance(e, SnapStoreError) and e.can_retry and
self.attempt_count <= self.max_retries):
- raise RetryableSnapStoreError(e.message, detail=e.detail)
+ raise RetryableSnapStoreError(e.args[0], detail=e.detail)
self.error_message = str(e)
self.error_messages = getattr(e, "messages", None)
self.error_detail = getattr(e, "detail", None)
diff --git a/test_on_merge.py b/test_on_merge.py
index bf353b8..b6e04af 100755
--- a/test_on_merge.py
+++ b/test_on_merge.py
@@ -185,7 +185,7 @@ def run_test_process():
# nb: select.error doesn't expose a named 'errno' attribute,
# at least in python 2.6.5; see
# <http://mail.python.org/pipermail/python-dev/2000-October/009671.html>
- if e[0] == errno.EINTR:
+ if e.args[0] == errno.EINTR:
continue
else:
raise