Completed
Push — master ( b95acc...a5fbcd )
by Oleksandr
01:06
created

Proxy.from_ini()   A

Complexity

Conditions 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
ccs 1
cts 1
cp 1
rs 9.4285
cc 1
crap 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 StringType, IntType
7 1
from schematics.types.compound import ModelType
8
9 1
from .interfaces import INISerializable
10
11
12 1
@zope.interface.implementer(INISerializable)
13 1
class Proxy(Model):
14 1
    host = StringType(
15
        default="",
16
        required=True,
17
    )
18 1
    port = IntType(
19
        default=1080,
20
        required=True,
21
    )
22 1
    user = StringType(
23
        default="",
24
        required=True,
25
    )
26
    password = StringType(
27
        default="",
28
        required=True,
29
    )
30
31 1
    @classmethod
32
    def from_ini(cls, ini):
33
        return cls({
34
            'host': ini.get(
35
                'NET', 'socksHost',
36
                fallback=cls.host.default,
37
            ),
38
            'port': ini.getint(
39
                'NET', 'socksPort',
40
                fallback=cls.port.default,
41
            ),
42
            'user': ini.get(
43
                'NET', 'socksUser',
44
                fallback=cls.user.default,
45
            ),
46
            'password': ini.get(
47
                'NET', 'socksPwd',
48
                fallback=cls.password.default,
49
            ),
50
        })
51
52
53 1
@zope.interface.implementer(INISerializable)
54 1
class Connection(Model):
55 1
    host = StringType(
56
        default="",
57
        required=True,
58
    )
59 1
    port = IntType(
60
        min_value=1000,
61
        max_value=65000,
62
        default=21000,
63
        required=True,
64
    )
65 1
    max_clients = IntType(
66
        min_value=1,
67
        max_value=128,
68
        default=8,
69
        required=True,
70
    )
71 1
    throughput = IntType(
72
        min_value=300,
73
        max_value=1000000,
74
        default=5000,
75
        required=True,
76
    )
77 1
    proxy = ModelType(
78
        model_spec=Proxy,
79
        required=True,
80
    )
81
82 1
    @classmethod
83
    def from_ini(cls, ini):
84
        return cls({
85
            'host': ini.get(
86
                'NET', 'localHost',
87
                fallback=cls.host.default,
88
            ),
89
            'port': ini.getint(
90
                'NET', 'localPort',
91
                fallback=cls.port.default,
92
            ),
93
            'max_clients': ini.getint(
94
                'NET', 'serverChannels',
95
                fallback=cls.max_clients.default,
96
            ),
97
            'throughput': ini.getint(
98
                'NET', 'speed',
99
                fallback=cls.throughput.default,
100
            ),
101
            'proxy': Proxy.from_ini(ini),
102
        })
103