Passed
Push — master ( 2adcb6...75d235 )
by Markus
01:50
created

tcllib.requests.http.HttpPostRequest.run()   A

Complexity

Conditions 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
nop 1
1
# -*- coding: utf-8 -*-
0 ignored issues
show
Coding Style introduced by
This module should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
2
3
import requests
4
from collections import OrderedDict
0 ignored issues
show
introduced by
standard import "from collections import OrderedDict" should be placed before "import requests"
Loading history...
5
6
class TimeoutException(Exception):
0 ignored issues
show
Coding Style introduced by
This class should have a docstring.

The coding style of this project requires that you add a docstring to this code element. Below, you find an example for methods:

class SomeClass:
    def some_method(self):
        """Do x and return foo."""

If you would like to know more about docstrings, we recommend to read PEP-257: Docstring Conventions.

Loading history...
7
    pass
8
9
class HttpRequest:
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
10
    """Provides all generic features for making HTTP GET requests"""
11
    def __init__(self, url, timeout=10):
12
        self.url = url
13
        self.params = OrderedDict()
14
        self.timeout = timeout
15
        self.headers = {}
16
17
    def reset_session(self):
18
        """Reset everything to default."""
19
        self.sess = requests.Session()
0 ignored issues
show
Coding Style introduced by
The attribute sess was defined outside __init__.

It is generally a good practice to initialize all attributes to default values in the __init__ method:

class Foo:
    def __init__(self, x=None):
        self.x = x
Loading history...
20
        self.sess.headers.update(self.headers)
21
22
    def run(self):
23
        """Run query."""
24
        try:
25
            req = self.sess.get(self.url, params=self.params, timeout=self.timeout)
26
        except requests.exceptions.Timeout as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
27
            raise TimeoutException(e)
28
        return req
29
30
class HttpPostRequest(HttpRequest):
0 ignored issues
show
Unused Code introduced by
The variable __class__ seems to be unused.
Loading history...
31
    """Provides all generic features for making HTTP POST requests"""
32
    def run(self):
33
        """Run query."""
34
        try:
35
            req = self.sess.post(self.url, data=self.params, timeout=self.timeout)
36
        except requests.exceptions.Timeout as e:
0 ignored issues
show
Coding Style Naming introduced by
The name e does not conform to the variable naming conventions ((([a-z][a-z0-9_]{2,30})|(_[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...
37
            raise TimeoutException(e)
38
        return req
39