fname = "%s.%d" % (base_fname, i)
i += 1
- try:
- f = open(fname, "w")
- except:
- sys.stderr.write("Unable to open %s for writing\n" % fname)
- sys.exit(1)
-
- try:
+ with open(fname, 'w') as f:
f.write(unicode(s).encode("utf-8"))
- f.close()
print('Saved patch to %s' % fname)
- except:
+ except IOError:
sys.stderr.write("Failed to write to %s\n" % fname)
sys.exit(1)
# see if the patch is already in this bundle
if BundlePatch.objects.filter(bundle=self,
patch=patch).count():
- raise Exception('patch is already in bundle')
+ return
bp = BundlePatch.objects.create(bundle=self, patch=patch,
order=max_order + 1)
bp.save()
+ return bp
+
def public_url(self):
if not self.public:
return None
import datetime
import itertools
+import smtplib
from django.conf import settings
from django.contrib.auth.models import User
try:
message.send()
- except Exception as ex:
+ except smtplib.SMTPException as ex:
errors.append((recipient, ex))
continue
super(Paginator, self).__init__(objects, items_per_page)
try:
- page_no = int(request.GET.get('page'))
+ page_no = int(request.GET.get('page', 1))
self.current_page = self.page(int(page_no))
- except Exception:
+ except ValueError:
page_no = 1
self.current_page = self.page(page_no)
params = []
try:
- qs_var = template.Variable('list_view.params')
- params = dict(qs_var.resolve(context))
- except Exception:
+ qs_var = template.Variable('list_view.params').resolve(context)
+ params = dict(qs_var)
+ except (TypeError, template.VariableDoesNotExist):
pass
for (k, v) in self.params.items():
try:
bp = BundlePatch.objects.get(bundle=bundle, patch=patch)
bp.delete()
+ except BundlePatch.DoesNotExist:
+ pass
+ else:
messages.success(
request,
"Patch '%s' removed from bundle %s\n" % (patch.name,
bundle.name))
- # TODO(stephenfin): Make this less broad
- except Exception:
- pass
bundle.save()
patch_id = request.POST.get('patch_id', None)
if patch_id:
patch = get_object_or_404(Patch, id=patch_id)
- try:
- bundle.append_patch(patch)
- except Exception:
- pass
+ bundle.append_patch(patch)
bundle.save()
elif action == 'add':
bundle = get_object_or_404(Bundle,
patch_ids = get_patch_ids(request.POST)
for patch_id in patch_ids:
- try:
- patch = Patch.objects.get(id=patch_id)
- bundle.append_patch(patch)
- except:
- pass
+ patch = Patch.objects.get(id=patch_id)
+ bundle.append_patch(patch)
bundle.save()
elif action == 'delete':
bundle = Bundle.objects.get(owner=request.user,
id=request.POST['id'])
bundle.delete()
- except Exception:
+ except Bundle.DoesNotExist:
pass
bundle = None
-
else:
bundle = get_object_or_404(Bundle, owner=request.user,
id=request.POST['bundle_id'])
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from __future__ import absolute_import
+import smtplib
from django.conf import settings as conf_settings
from django.core.mail import send_mail
send_mail('Patchwork %s confirmation' % description, mail,
conf_settings.DEFAULT_FROM_EMAIL, [email])
context['email_sent'] = True
- except Exception:
+ except smtplib.SMTPException:
context['error'] = ('An error occurred during confirmation . '
'Please try again later.')
context['admins'] = conf_settings.ADMINS
elif action == 'addtobundle':
bundle = get_object_or_404(
Bundle, id=request.POST.get('bundle_id'))
- try:
- bundle.append_patch(patch)
- bundle.save()
+ if bundle.append_patch(patch):
messages.success(request,
- 'Patch added to bundle "%s"' % bundle.name)
- except Exception as ex:
+ 'Patch "%s" added to bundle "%s"' % (
+ patch.name, bundle.name))
+ else:
messages.error(request,
- "Couldn't add patch '%s' to bundle %s: %s"
- % (patch.name, bundle.name, ex.message))
+ 'Failed to add patch "%s" to bundle "%s": '
+ 'patch is already in bundle' % (
+ patch.name, bundle.name))
# all other actions require edit privs
elif not editable:
# along with Patchwork; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
-from __future__ import absolute_import
+import smtplib
from django.contrib import auth
from django.contrib.auth.decorators import login_required
context, request=request),
settings.DEFAULT_FROM_EMAIL,
[form.cleaned_data['email']])
- except Exception:
+ except smtplib.SMTPException:
context['confirmation'] = None
context['error'] = ('An error occurred during confirmation. '
'Please try again later')
try:
decoded = base64.b64decode(header.encode('ascii')).decode('ascii')
username, password = decoded.split(':', 1)
- except:
+ except ValueError:
raise Exception('Invalid authentication credentials')
return authenticate(username=username, password=password)
response = self.dumps(response, methodresponse=1)
except six.moves.xmlrpc_client.Fault as fault:
response = self.dumps(fault)
- except:
+ except Exception: # noqa
# report exception back to server
response = self.dumps(
six.moves.xmlrpc_client.Fault(
if request.method == 'POST':
try:
ret = dispatcher._marshaled_dispatch(request)
- except Exception:
+ except Exception: # noqa
return HttpResponseServerError()
else:
ret = dispatcher.generate_html_documentation()