Skip to content

Commit 5189bda

Browse files
committed
Replace old-style except statements with modern as syntax #280
Signed-off-by: Thomas Druez <[email protected]>
1 parent 8b72bae commit 5189bda

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/attributecode/api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def request_license_data(url, api_key, license_key):
135135
if not license_data['results']:
136136
msg = (u"Invalid 'license': " + license_key)
137137
errors.append(Error(ERROR, msg))
138-
except urllib2.HTTPError, http_e:
138+
except urllib2.HTTPError as http_e:
139139
# some auth problem
140140
if http_e.code == 403:
141141
msg = (u"Authorization denied. Invalid '--api_key'. License generation is skipped.")

src/attributecode/attrib.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def generate(abouts, template_string=None):
100100

101101
rendered = template.render(abouts=abouts, common_licenses=COMMON_LICENSES, license_key_and_context=sorted_license_key_and_context,
102102
license_text_name_and_key=license_text_name_and_key, license_key_to_license_name=license_key_to_license_name)
103-
except Exception, e:
103+
except Exception as e:
104104
line = getattr(e, 'lineno', None)
105105
ln_msg = ' at line: %r' % line if line else ''
106106
err = getattr(e, 'message', '')
@@ -115,7 +115,7 @@ def check_template(template_string):
115115
"""
116116
try:
117117
jinja2.Template(template_string)
118-
except (jinja2.TemplateSyntaxError, jinja2.TemplateAssertionError,), e:
118+
except (jinja2.TemplateSyntaxError, jinja2.TemplateAssertionError) as e:
119119
return e.lineno, e.message
120120

121121

src/attributecode/gen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ def generate(location, base_dir, mapping, license_notice_text_location, fetch_li
263263
for e in file_field_not_exist_errors:
264264
errors.append(Error(ERROR, e))
265265

266-
except Exception, e:
266+
except Exception as e:
267267
# only keep the first 100 char of the exception
268268
emsg = repr(e)[:100]
269269
msg = (u'Failed to write ABOUT file at : '

src/attributecode/model.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def validate(self, *args, **kwargs):
122122
try:
123123
validation_errors = self._validate(*args, **kwargs)
124124
errors.extend(validation_errors)
125-
except Exception, e:
125+
except Exception as e:
126126
emsg = repr(e)
127127
msg = u'Error validating field %(name)s: %(value)r: %(emsg)r'
128128
errors.append(Error(CRITICAL, msg % locals()))
@@ -496,7 +496,7 @@ def _validate(self, *args, **kwargs):
496496
location = add_unc(location)
497497
text = codecs.open(location, encoding='utf-8', errors='ignore').read()
498498
self.value[path] = text
499-
except Exception, e:
499+
except Exception as e:
500500
# only keep the first 100 char of the exception
501501
emsg = repr(e)[:100]
502502
msg = (u'Field %(name)s: Failed to load text at path: '
@@ -949,7 +949,7 @@ def load(self, location):
949949
running_inventory = True
950950
errs = self.load_dict(saneyaml.load(input_text), base_dir, running_inventory)
951951
errors.extend(errs)
952-
except Exception, e:
952+
except Exception as e:
953953
msg = 'Cannot load invalid ABOUT file: %(location)r: %(e)r\n' + str(e)
954954
errors.append(Error(CRITICAL, msg % locals()))
955955

@@ -1430,7 +1430,7 @@ def valid_api_url(api_url):
14301430
# This will always goes to exception as no key are provided.
14311431
# The purpose of this code is to validate the provided api_url is correct
14321432
response = urllib2.urlopen(request)
1433-
except urllib2.HTTPError, http_e:
1433+
except urllib2.HTTPError as http_e:
14341434
# The 403 error code is refer to "Authentication credentials were not provided.".
14351435
# This is correct as no key are provided.
14361436
if http_e.code == 403:

0 commit comments

Comments
 (0)