class SettingsToTest(settings.Settings):
    schema: settings.SettingsSchema = {
        'one': fields.Dictionary({
            'a': fields.ClassConfigurationSchema(base_class=ClassUsingAttrs27HintsToTest, description='Nifty schema.'),
            'b': fields.PythonPath(value_schema=fields.UnicodeString(), description='Must be a path, yo.'),
            'c': fields.TypeReference(base_classes=ClassHoldingSigsToTest, description='Refer to that thing!'),
        }),
        'two': fields.SchemalessDictionary(key_type=fields.UnicodeString(), value_type=fields.Boolean()),
        'three': fields.List(fields.Integer()),
        'four': fields.Nullable(fields.Set(fields.ByteString())),
        'five': fields.Any(fields.Integer(), fields.Float()),
        'six': fields.ObjectInstance(valid_type=ClassUsingAttrs27HintsToTest, description='Y u no instance?'),
        'seven': fields.Polymorph(
            'thing',
            {
                'thing1': fields.Dictionary({'z': fields.Boolean()}, allow_extra_keys=True),
                'thing2': fields.Dictionary({'y': fields.Boolean()}, allow_extra_keys=True, optional_keys=('y', )),
            },
        ),
    }

    defaults: settings.SettingsData = {
        'one': {
            'b': 'foo.bar:Class',
        },
        'three': [1, 5, 7],
    }
Esempio n. 2
0
class PolymorphicServerSettings(ServerSettings):
    """
    Settings for Servers that can use any type of transport, while performing validation on certain transport types.
    """
    defaults = {
        'transport': {
            'path':
            'pysoa.common.transport.redis_gateway.server:RedisServerTransport',
        }
    }
    schema = {
        'transport':
        fields.Polymorph(
            switch_field='path',
            contents_map={
                'pysoa.common.transport.local:LocalServerTransport':
                LocalTransportSchema(LocalServerTransport),
                'pysoa.common.transport:LocalServerTransport':
                LocalTransportSchema(LocalServerTransport),
                'pysoa.common.transport.redis_gateway.server:RedisServerTransport':
                RedisTransportSchema(RedisServerTransport, ),
                '__default__':
                BasicClassSchema(BaseServerTransport),
            }),
    }
Esempio n. 3
0
CONFIGURATION_SCHEMA = fields.Polymorph(
    switch_field='version',
    contents_map={
        2:
        fields.Dictionary(
            {
                'version':
                fields.Constant(2),
                'enable_meta_metrics':
                fields.Boolean(
                    description=
                    'If true, meta-metrics will be recorded documenting the performance of '
                    'PyMetrics itself.', ),
                'error_logger_name':
                fields.UnicodeString(
                    description=
                    'By default, errors encountered when publishing metrics are suppressed and lost. If '
                    'this value is truthy, a Logger is created with this name and used to log publication '
                    'errors.', ),
                'publishers':
                fields.Sequence(
                    fields.ClassConfigurationSchema(
                        base_class=MetricsPublisher,
                        description=
                        'Import path and arguments for a publisher.',
                    ),
                    min_length=1,
                    description='The configuration for all publishers.',
                ),
            },
            optional_keys=('enable_meta_metrics', 'error_logger_name'),
        ),
    },
    description=
    'The configuration schema changes slightly based on which config version you specify.',
)