Completed
Push — master ( 9d3bc0...b059cb )
by Oleksandr
01:07
created

Speedhack   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 81.82%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
dl 0
loc 49
ccs 9
cts 11
cp 0.8182
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A default() 0 5 2
A from_ini() 0 18 1
1
# coding: utf-8
2
3 1
import zope.interface
4
5 1
from schematics.models import Model
6 1
from schematics.types import FloatType, BooleanType
7
8 1
from ..interfaces import INISerializable, DefaultProvider
9 1
from ..helpers import field_from_ini
10
11
12 1
@zope.interface.implementer(INISerializable)
13 1
@zope.interface.implementer(DefaultProvider)
14 1
class Speedhack(Model):
15 1
    check_server_time_speed = BooleanType(
16
        default=True,
17
        required=True,
18
    )
19 1
    check_client_time_speed = BooleanType(
20
        default=False,
21
        required=True,
22
    )
23 1
    max_time_difference = FloatType(
24
        min_value=0.01,
25
        default=0.2,
26
        required=True,
27
    )
28 1
    max_time_difference_period = FloatType(
29
        min_value=1,
30
        max_value=1000,
31
        default=17,
32
        required=True,
33
    )
34
35 1
    @classmethod
36
    def from_ini(cls, ini):
37
        return cls({
38
            'check_server_time_speed': field_from_ini(
39
                cls.check_server_time_speed, ini,
40
                'NET', 'checkServerTimeSpeed',
41
            ),
42
            'check_client_time_speed': field_from_ini(
43
                cls.check_client_time_speed, ini,
44
                'NET', 'checkClientTimeSpeed',
45
            ),
46
            'max_time_difference': field_from_ini(
47
                cls.max_time_difference, ini,
48
                'NET', 'checkTimeSpeedDifferense',
49
            ),
50
            'max_time_difference_period': field_from_ini(
51
                cls.max_time_difference_period, ini,
52
                'NET', 'checkTimeSpeedInterval',
53
            ),
54
        })
55
56 1
    @classmethod
57
    def default(cls):
58
        return cls({
59
            field_name: field.default
60
            for field_name, field in cls.fields.items()
61
        })
62