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

Proxy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 3
Bugs 0 Features 1
Metric Value
wmc 3
c 3
b 0
f 1
dl 0
loc 46
ccs 8
cts 9
cp 0.8889
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A from_ini() 0 18 1
A default() 0 5 2
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, DefaultProvider
10 1
from .helpers import field_from_ini
11
12
13 1
@zope.interface.implementer(INISerializable)
14 1
@zope.interface.implementer(DefaultProvider)
15 1
class Proxy(Model):
16 1
    host = StringType(
17
        default="",
18
        required=True,
19
    )
20 1
    port = IntType(
21
        default=1080,
22
        required=True,
23
    )
24 1
    user = StringType(
25
        default="",
26
        required=True,
27
    )
28
    password = StringType(
29
        default="",
30
        required=True,
31
    )
32
33 1
    @classmethod
34
    def from_ini(cls, ini):
35
        return cls({
36
            'host': field_from_ini(
37
                cls.host, ini,
38
                'NET', 'socksHost',
39
            ),
40
            'port': field_from_ini(
41
                cls.port, ini,
42
                'NET', 'socksPort',
43
            ),
44
            'user': field_from_ini(
45
                cls.user, ini,
46
                'NET', 'socksUser',
47
            ),
48
            'password': field_from_ini(
49
                cls.password, ini,
50
                'NET', 'socksPwd',
51
            ),
52
        })
53
54 1
    @classmethod
55
    def default(cls):
56
        return cls({
57
            field_name: field.default
58
            for field_name, field in cls.fields.items()
59
        })
60
61
62 1
@zope.interface.implementer(INISerializable)
63 1
@zope.interface.implementer(DefaultProvider)
64 1
class Connection(Model):
65 1
    host = StringType(
66
        default="",
67
        required=True,
68
    )
69 1
    port = IntType(
70
        min_value=1000,
71
        max_value=65000,
72
        default=21000,
73
        required=True,
74
    )
75 1
    max_clients = IntType(
76
        min_value=1,
77
        max_value=128,
78
        default=8,
79
        required=True,
80
    )
81 1
    throughput = IntType(
82
        min_value=300,
83
        max_value=1000000,
84
        default=5000,
85
        required=True,
86
    )
87 1
    proxy = ModelType(
88
        model_spec=Proxy,
89
        required=True,
90
    )
91
92 1
    @classmethod
93
    def from_ini(cls, ini):
94
        return cls({
95
            'host': field_from_ini(
96
                cls.host, ini,
97
                'NET', 'localHost',
98
            ),
99
            'port': field_from_ini(
100
                cls.port, ini,
101
                'NET', 'localPort',
102
            ),
103
            'max_clients': field_from_ini(
104
                cls.max_clients, ini,
105
                'NET', 'serverChannels',
106
            ),
107
            'throughput': field_from_ini(
108
                cls.throughput, ini,
109
                'NET', 'speed',
110
            ),
111
            'proxy': Proxy.from_ini(ini),
112
        })
113
114 1
    @classmethod
115
    def default(cls):
116
        return cls({
117
            'host': cls.host.default,
118
            'port': cls.port.default,
119
            'max_clients': cls.max_clients.default,
120
            'throughput': cls.throughput.default,
121
            'proxy': Proxy.default(),
122
        })
123