Completed
Pull Request — master (#9)
by George
02:20
created

SNSMessageTranslator.translate()   A

Complexity

Conditions 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 3
dl 0
loc 13
rs 9.4285
1
# -*- coding: utf-8 -*-
2
# vi:si:et:sw=4:sts=4:ts=4
3
4
import json
5
import logging
6
7
logger = logging.getLogger(__name__)
1 ignored issue
show
Coding Style Naming introduced by
The name logger does not conform to the constant naming conventions ((([A-Z_][A-Z0-9_]*)|(__.*__))$).

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
8
9
10
class SQSMessageTranslator(object):
11
12
    def translate(self, message):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
13
        try:
14
            body = message['Body']
15
        except (KeyError, TypeError):
16
            logger.error('Missing Body key in SQS message. It really came from SQS ?')
17
            return {'content': None}
18
19
        try:
20
            return {'content': json.loads(body)}
21
        except json.decoder.JSONDecodeError as exc:
1 ignored issue
show
Bug introduced by
The Module json.decoder does not seem to have a member named JSONDecodeError.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
22
            logger.exception(exc)
23
            return {'content': None}
24
25
26
class SNSMessageTranslator(object):
27
    def translate(self, message):
0 ignored issues
show
Coding Style introduced by
This method could be written as a function/class method.

If a method does not access any attributes of the class, it could also be implemented as a function or static method. This can help improve readability. For example

class Foo:
    def some_method(self, x, y):
        return x + y;

could be written as

class Foo:
    @classmethod
    def some_method(cls, x, y):
        return x + y;
Loading history...
28
        try:
29
            body = json.loads(message['Body'])
30
            message = body['Message']
31
        except (KeyError, TypeError):
32
            logger.error('Missing Body or Message key in SQS message. It really came from SNS ?')
33
            return {'content': None}
34
35
        try:
36
            return {'content': json.loads(message)}
37
        except (json.decoder.JSONDecodeError, TypeError) as exc:
1 ignored issue
show
Bug introduced by
The Module json.decoder does not seem to have a member named JSONDecodeError.

This check looks for calls to members that are non-existent. These calls will fail.

The member could have been renamed or removed.

Loading history...
38
            logger.exception(exc)
39
            return {'content': None}
40