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

Speedhack.from_ini()   A

Complexity

Conditions 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.125

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 1
cts 2
cp 0.5
rs 9.4285
cc 1
crap 1.125
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