|
6 | 6 | from django.utils.dateparse import parse_datetime |
7 | 7 |
|
8 | 8 | from .base import AnymailBaseWebhookView |
9 | | -from ..backends.amazon_ses import _get_anymail_boto3_params |
10 | 9 | from ..exceptions import ( |
11 | | - AnymailAPIError, AnymailConfigurationError, AnymailImproperlyInstalled, AnymailWebhookValidationFailure) |
| 10 | + AnymailAPIError, AnymailConfigurationError, AnymailImproperlyInstalled, AnymailWebhookValidationFailure, |
| 11 | + _LazyError) |
12 | 12 | from ..inbound import AnymailInboundMessage |
13 | 13 | from ..signals import AnymailInboundEvent, AnymailTrackingEvent, EventType, RejectReason, inbound, tracking |
14 | 14 | from ..utils import combine, get_anymail_setting, getfirst |
15 | 15 |
|
16 | 16 | try: |
17 | 17 | import boto3 |
18 | | - import botocore.exceptions |
| 18 | + from botocore.exceptions import ClientError |
| 19 | + from ..backends.amazon_ses import _get_anymail_boto3_params |
19 | 20 | except ImportError: |
20 | | - raise AnymailImproperlyInstalled(missing_package='boto3', backend='amazon_ses') |
| 21 | + # This module gets imported by anymail.urls, so don't complain about boto3 missing |
| 22 | + # unless one of the Amazon SES webhook views is actually used and needs it |
| 23 | + boto3 = _LazyError(AnymailImproperlyInstalled(missing_package='boto3', backend='amazon_ses')) |
| 24 | + ClientError = object |
| 25 | + _get_anymail_boto3_params = _LazyError(AnymailImproperlyInstalled(missing_package='boto3', backend='amazon_ses')) |
21 | 26 |
|
22 | 27 |
|
23 | 28 | class AmazonSESBaseWebhookView(AnymailBaseWebhookView): |
@@ -296,7 +301,7 @@ def esp_to_anymail_events(self, ses_event, sns_message): |
296 | 301 | s3.download_fileobj(bucket_name, object_key, content) |
297 | 302 | content.seek(0) |
298 | 303 | message = AnymailInboundMessage.parse_raw_mime_file(content) |
299 | | - except botocore.exceptions.ClientError as err: |
| 304 | + except ClientError as err: |
300 | 305 | # improve the botocore error message |
301 | 306 | raise AnymailBotoClientAPIError( |
302 | 307 | "Anymail AmazonSESInboundWebhookView couldn't download S3 object '{bucket_name}:{object_key}'" |
@@ -334,11 +339,11 @@ def esp_to_anymail_events(self, ses_event, sns_message): |
334 | 339 | )] |
335 | 340 |
|
336 | 341 |
|
337 | | -class AnymailBotoClientAPIError(AnymailAPIError, botocore.exceptions.ClientError): |
| 342 | +class AnymailBotoClientAPIError(AnymailAPIError, ClientError): |
338 | 343 | """An AnymailAPIError that is also a Boto ClientError""" |
339 | 344 | def __init__(self, *args, **kwargs): |
340 | 345 | raised_from = kwargs.pop('raised_from') |
341 | | - assert isinstance(raised_from, botocore.exceptions.ClientError) |
| 346 | + assert isinstance(raised_from, ClientError) |
342 | 347 | assert len(kwargs) == 0 # can't support other kwargs |
343 | 348 | # init self as boto ClientError (which doesn't cooperatively subclass): |
344 | 349 | super(AnymailBotoClientAPIError, self).__init__( |
|
0 commit comments