From 05c5e79e4eec87c9930673a8f3dd943c628c4dfb Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Wed, 26 Jun 2024 08:01:03 +1000 Subject: [PATCH] chore: move doc string to top of module --- voluptuous/__init__.py | 75 +++++++++++++++++++++++++++++++++++ voluptuous/schema_builder.py | 77 +----------------------------------- 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/voluptuous/__init__.py b/voluptuous/__init__.py index f809521..99fb3c9 100644 --- a/voluptuous/__init__.py +++ b/voluptuous/__init__.py @@ -1,3 +1,78 @@ +"""Schema validation for Python data structures. + +Given eg. a nested data structure like this: + + { + 'exclude': ['Users', 'Uptime'], + 'include': [], + 'set': { + 'snmp_community': 'public', + 'snmp_timeout': 15, + 'snmp_version': '2c', + }, + 'targets': { + 'localhost': { + 'exclude': ['Uptime'], + 'features': { + 'Uptime': { + 'retries': 3, + }, + 'Users': { + 'snmp_community': 'monkey', + 'snmp_port': 15, + }, + }, + 'include': ['Users'], + 'set': { + 'snmp_community': 'monkeys', + }, + }, + }, + } + +A schema like this: + + >>> settings = { + ... 'snmp_community': str, + ... 'retries': int, + ... 'snmp_version': All(Coerce(str), Any('3', '2c', '1')), + ... } + >>> features = ['Ping', 'Uptime', 'Http'] + >>> schema = Schema({ + ... 'exclude': features, + ... 'include': features, + ... 'set': settings, + ... 'targets': { + ... 'exclude': features, + ... 'include': features, + ... 'features': { + ... str: settings, + ... }, + ... }, + ... }) + +Validate like so: + + >>> schema({ + ... 'set': { + ... 'snmp_community': 'public', + ... 'snmp_version': '2c', + ... }, + ... 'targets': { + ... 'exclude': ['Ping'], + ... 'features': { + ... 'Uptime': {'retries': 3}, + ... 'Users': {'snmp_community': 'monkey'}, + ... }, + ... }, + ... }) == { + ... 'set': {'snmp_version': '2c', 'snmp_community': 'public'}, + ... 'targets': { + ... 'exclude': ['Ping'], + ... 'features': {'Uptime': {'retries': 3}, + ... 'Users': {'snmp_community': 'monkey'}}}} + True +""" # flake8: noqa # fmt: off from voluptuous.schema_builder import * diff --git a/voluptuous/schema_builder.py b/voluptuous/schema_builder.py index 237d5a9..4b95cc7 100644 --- a/voluptuous/schema_builder.py +++ b/voluptuous/schema_builder.py @@ -1,3 +1,4 @@ + # fmt: off from __future__ import annotations @@ -16,82 +17,6 @@ # fmt: on -"""Schema validation for Python data structures. - -Given eg. a nested data structure like this: - - { - 'exclude': ['Users', 'Uptime'], - 'include': [], - 'set': { - 'snmp_community': 'public', - 'snmp_timeout': 15, - 'snmp_version': '2c', - }, - 'targets': { - 'localhost': { - 'exclude': ['Uptime'], - 'features': { - 'Uptime': { - 'retries': 3, - }, - 'Users': { - 'snmp_community': 'monkey', - 'snmp_port': 15, - }, - }, - 'include': ['Users'], - 'set': { - 'snmp_community': 'monkeys', - }, - }, - }, - } - -A schema like this: - - >>> settings = { - ... 'snmp_community': str, - ... 'retries': int, - ... 'snmp_version': All(Coerce(str), Any('3', '2c', '1')), - ... } - >>> features = ['Ping', 'Uptime', 'Http'] - >>> schema = Schema({ - ... 'exclude': features, - ... 'include': features, - ... 'set': settings, - ... 'targets': { - ... 'exclude': features, - ... 'include': features, - ... 'features': { - ... str: settings, - ... }, - ... }, - ... }) - -Validate like so: - - >>> schema({ - ... 'set': { - ... 'snmp_community': 'public', - ... 'snmp_version': '2c', - ... }, - ... 'targets': { - ... 'exclude': ['Ping'], - ... 'features': { - ... 'Uptime': {'retries': 3}, - ... 'Users': {'snmp_community': 'monkey'}, - ... }, - ... }, - ... }) == { - ... 'set': {'snmp_version': '2c', 'snmp_community': 'public'}, - ... 'targets': { - ... 'exclude': ['Ping'], - ... 'features': {'Uptime': {'retries': 3}, - ... 'Users': {'snmp_community': 'monkey'}}}} - True -""" - # options for extra keys PREVENT_EXTRA = 0 # any extra key not in schema will raise an error ALLOW_EXTRA = 1 # extra keys not in schema will be included in output