Пример #1
0
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],
    }
Пример #2
0
class LocalClientTransportSchema(BasicClassSchema):
    contents = {
        'path': fields.UnicodeString(
            description='The path to the local client transport, in the format `module.name:ClassName`',
        ),
        'kwargs': fields.Dictionary({
            # server class can be an import path or a class object
            'server_class': fields.Any(
                fields.UnicodeString(
                    description='The path to the `Server` class, in the format `module.name:ClassName`',
                ),
                fields.ObjectInstance(
                    six.class_types,
                    description='A reference to the `Server`-extending class/type',
                ),
                description='The path to the `Server` class to use locally (as a library), or a reference to the '
                            '`Server`-extending class/type itself',
            ),
            # No deeper validation because the Server will perform its own validation
            'server_settings': fields.SchemalessDictionary(
                key_type=fields.UnicodeString(),
                description='The settings to use when instantiating the `server_class`'
            ),
        }),
    }

    optional_keys = ()

    description = 'The settings for the local client transport'
Пример #3
0
class StubClientTransportSchema(BasicClassSchema):
    contents = {
        'path':
        fields.UnicodeString(
            description=
            'The path to the stub client transport, in the format `module.name:ClassName`',
        ),
        'kwargs':
        fields.Dictionary(
            {
                'action_map':
                fields.SchemalessDictionary(
                    key_type=fields.UnicodeString(
                        description='The name of the action to stub', ),
                    value_type=fields.Dictionary(
                        {
                            'body':
                            fields.SchemalessDictionary(
                                description=
                                'The body with which the action should respond',
                            ),
                            'errors':
                            fields.List(
                                fields.Any(
                                    fields.ObjectInstance(Error),
                                    fields.Dictionary(
                                        {
                                            'code':
                                            fields.UnicodeString(),
                                            'message':
                                            fields.UnicodeString(),
                                            'field':
                                            fields.UnicodeString(),
                                            'traceback':
                                            fields.UnicodeString(),
                                            'variables':
                                            fields.SchemalessDictionary(),
                                            'denied_permissions':
                                            fields.List(
                                                fields.UnicodeString()),
                                        }, ),
                                ),
                                description='The ',
                            ),
                        },
                        description=
                        'A dictionary containing either a body dict or an errors list, providing an '
                        'instruction on how the stub action should respond to requests',
                        optional_keys=('body', 'errors'),
                    ),
                ),
            }, ),
    }

    optional_keys = ()

    description = 'The settings for the local transport'
Пример #4
0
class LocalTransportSchema(BasicClassSchema):
    contents = {
        'path':
        fields.UnicodeString(),
        'kwargs':
        fields.Dictionary({
            # server class can be an import path or a class object
            'server_class':
            fields.Any(fields.UnicodeString(),
                       fields.ObjectInstance(six.class_types)),
            # No deeper validation because the Server will perform its own validation
            'server_settings':
            fields.SchemalessDictionary(key_type=fields.UnicodeString()),
        }),
    }
Пример #5
0
    MessageReceiveTimeout,
    TransientPySOATransportError,
)
from pysoa.common.transport.redis_gateway.backend.base import BaseRedisClient
from pysoa.common.transport.redis_gateway.constants import ProtocolVersion
from pysoa.common.transport.redis_gateway.core import RedisTransportClientCore
from pysoa.common.transport.redis_gateway.settings import RedisTransportSchema
from pysoa.common.transport.redis_gateway.utils import make_redis_queue_name


@fields.ClassConfigurationSchema.provider(RedisTransportSchema().extend(
    contents={
        'protocol_version':
        fields.Any(
            fields.Integer(),
            fields.ObjectInstance(valid_type=ProtocolVersion),
            description=
            'The default protocol version between clients and servers was Version 1 prior to PySOA '
            '0.67.0, Version 2 as of 0.67.0, and will be Version 3 as of 1.0.0. The server can only '
            'detect what protocol the client is speaking and respond with the same protocol. However, '
            'the client cannot pre-determine what protocol the server is speaking. So, if you need to '
            'differ from the default (currently Version 2), use this setting to tell the client which '
            'protocol to speak.',
        ),
    },
    optional_keys=('protocol_version', ),
    description='The constructor kwargs for the Redis client transport.',
))
class RedisClientTransport(ClientTransport):
    def __init__(self, service_name, metrics, **kwargs):
        # type: (six.text_type, MetricsRecorder, **Any) -> None
Пример #6
0
""""""  # Empty docstring to make autodoc document this data


@attr.s
class Configuration(object):
    version = attr.ib()  # type: int
    publishers = attr.ib(
        default=attr.Factory(list))  # type: List[MetricsPublisher]
    error_logger_name = attr.ib(default=None)  # type: Optional[six.text_type]
    enable_meta_metrics = attr.ib(default=False)  # type: bool


@validator.validate_call(
    args=fields.Tuple(copy.deepcopy(CONFIGURATION_SCHEMA)),
    kwargs=None,
    returns=fields.ObjectInstance(Configuration),
)
def create_configuration(
        config_dict):  # type: (Dict[six.text_type, Any]) -> Configuration
    """
    Creates a `Configuration` object using the provided configuration dictionary. Works in similar fashion to logging's
    configuration.

    Expected format of config is a dict:

    .. code-block:: python

        {
            'version': 2,
            'error_logger_name': 'pymetrics',  # name of the error logger to use, or `None` (the default) to suppress
            'enable_meta_metrics': False,  # whether to enable the collection of meta-metrics