for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
# coding: utf-8
import zope.interface
from schematics.models import Model
from schematics.types import StringType, IntType
from schematics.types.compound import ModelType
from .interfaces import INISerializable, DefaultProvider
from .helpers import field_from_ini
@zope.interface.implementer(INISerializable)
@zope.interface.implementer(DefaultProvider)
class Proxy(Model):
host = StringType(
default="",
required=True,
)
port = IntType(
default=1080,
user = StringType(
password = StringType(
@classmethod
def from_ini(cls, ini):
return cls({
'host': field_from_ini(
cls.host, ini,
'NET', 'socksHost',
),
'port': field_from_ini(
cls.port, ini,
'NET', 'socksPort',
'user': field_from_ini(
cls.user, ini,
'NET', 'socksUser',
'password': field_from_ini(
cls.password, ini,
'NET', 'socksPwd',
})
def default(cls):
field_name: field.default
for field_name, field in cls.fields.items()
class Connection(Model):
min_value=1000,
max_value=65000,
default=21000,
max_clients = IntType(
min_value=1,
max_value=128,
default=8,
throughput = IntType(
min_value=300,
max_value=1000000,
default=5000,
proxy = ModelType(
model_spec=Proxy,
'NET', 'localHost',
'NET', 'localPort',
'max_clients': field_from_ini(
cls.max_clients, ini,
'NET', 'serverChannels',
'throughput': field_from_ini(
cls.throughput, ini,
'NET', 'speed',
'proxy': Proxy.from_ini(ini),
'host': cls.host.default,
'port': cls.port.default,
'max_clients': cls.max_clients.default,
'throughput': cls.throughput.default,
'proxy': Proxy.default(),