nserver.server 🔗
Blueprint 🔗
Bases: Scaffold
Class that can replicate many of the functions of a NameServer
.
They can be used to construct or extend applications.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the server. This is used for internal logging. |
required |
after_query 🔗
Decorator for registering after_query hook.
These functions are after the rule function is run and may modify the response.
before_first_query 🔗
Decorator for registering before_first_query hook.
These functions are called when the server receives it's first query, but before any further processesing.
before_query 🔗
Decorator for registering before_query hook.
These functions are called before processing each query.
entrypoint 🔗
Entrypoint into this Blueprint
.
This method should be passed to rules as the function to run.
exception_handler 🔗
Decorator for registering a function as an exception handler
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
The |
required |
register_after_query 🔗
Register a function to be run on the result of a query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
AfterQueryHook
|
the function to register |
required |
register_before_first_query 🔗
Register a function to be run before the first query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeFirstQueryHook
|
the function to register |
required |
register_before_query 🔗
Register a function to be run before every query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeQueryHook
|
the function to register
If |
required |
register_blueprint 🔗
register_blueprint(
blueprint: Blueprint,
rule_: Union[Type[RuleBase], str, Pattern],
*args,
**kwargs
) -> None
Register a blueprint using smart_make_rule
.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blueprint |
Blueprint
|
the |
required |
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
register_exception_handler 🔗
register_exception_handler(
exception_class: Type[Exception],
handler: middleware.ExceptionHandler,
) -> None
Register an exception handler for the QueryMiddleware
Only one handler can exist for a given exception type.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
the type of exception to handle |
required |
handler |
ExceptionHandler
|
the function to call when handling an exception |
required |
register_middleware 🔗
Add a QueryMiddleware
to this server.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_middleware |
QueryMiddleware
|
the middleware to add |
required |
register_rule 🔗
Register the given rule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
RuleBase
|
the rule to register |
required |
rule 🔗
Decorator for registering a function using smart_make_rule
.
Changed in 2.0
: This method now uses smart_make_rule
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
NameServer 🔗
Bases: Scaffold
NameServer for responding to requests.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the server. This is used for internal logging. |
required |
settings |
Optional[Settings]
|
settings to use with this |
None
|
after_query 🔗
Decorator for registering after_query hook.
These functions are after the rule function is run and may modify the response.
before_first_query 🔗
Decorator for registering before_first_query hook.
These functions are called when the server receives it's first query, but before any further processesing.
before_query 🔗
Decorator for registering before_query hook.
These functions are called before processing each query.
exception_handler 🔗
Decorator for registering a function as an exception handler
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
The |
required |
raw_exception_handler 🔗
Decorator for registering a function as an raw exception handler
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
The |
required |
register_after_query 🔗
Register a function to be run on the result of a query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
AfterQueryHook
|
the function to register |
required |
register_before_first_query 🔗
Register a function to be run before the first query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeFirstQueryHook
|
the function to register |
required |
register_before_query 🔗
Register a function to be run before every query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeQueryHook
|
the function to register
If |
required |
register_blueprint 🔗
register_blueprint(
blueprint: Blueprint,
rule_: Union[Type[RuleBase], str, Pattern],
*args,
**kwargs
) -> None
Register a blueprint using smart_make_rule
.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blueprint |
Blueprint
|
the |
required |
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
register_exception_handler 🔗
register_exception_handler(
exception_class: Type[Exception],
handler: middleware.ExceptionHandler,
) -> None
Register an exception handler for the QueryMiddleware
Only one handler can exist for a given exception type.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
the type of exception to handle |
required |
handler |
ExceptionHandler
|
the function to call when handling an exception |
required |
register_middleware 🔗
Add a QueryMiddleware
to this server.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_middleware |
QueryMiddleware
|
the middleware to add |
required |
register_raw_exception_handler 🔗
register_raw_exception_handler(
exception_class: Type[Exception],
handler: middleware.RawRecordExceptionHandler,
) -> None
Register a raw exception handler for the RawRecordMiddleware
.
Only one handler can exist for a given exception type.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
the type of exception to handle |
required |
handler |
RawRecordExceptionHandler
|
the function to call when handling an exception |
required |
register_raw_middleware 🔗
Add a RawRecordMiddleware
to this server.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw_middleware |
RawRecordMiddleware
|
the middleware to add |
required |
register_rule 🔗
Register the given rule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
RuleBase
|
the rule to register |
required |
rule 🔗
Decorator for registering a function using smart_make_rule
.
Changed in 2.0
: This method now uses smart_make_rule
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
run 🔗
Start running the server
Returns:
Type | Description |
---|---|
int
|
|
Scaffold 🔗
Base class for shared functionality between NameServer
and Blueprint
New in 2.0
.
Attributes:
Name | Type | Description |
---|---|---|
rules |
List[RuleBase]
|
registered rules |
hook_middleware |
hook middleware |
|
exception_handler_middleware |
Query exception handler middleware |
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
The name of the server. This is used for internal logging. |
required |
after_query 🔗
Decorator for registering after_query hook.
These functions are after the rule function is run and may modify the response.
before_first_query 🔗
Decorator for registering before_first_query hook.
These functions are called when the server receives it's first query, but before any further processesing.
before_query 🔗
Decorator for registering before_query hook.
These functions are called before processing each query.
exception_handler 🔗
Decorator for registering a function as an exception handler
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
The |
required |
register_after_query 🔗
Register a function to be run on the result of a query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
AfterQueryHook
|
the function to register |
required |
register_before_first_query 🔗
Register a function to be run before the first query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeFirstQueryHook
|
the function to register |
required |
register_before_query 🔗
Register a function to be run before every query.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
func |
BeforeQueryHook
|
the function to register
If |
required |
register_blueprint 🔗
register_blueprint(
blueprint: Blueprint,
rule_: Union[Type[RuleBase], str, Pattern],
*args,
**kwargs
) -> None
Register a blueprint using smart_make_rule
.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
blueprint |
Blueprint
|
the |
required |
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |
register_exception_handler 🔗
register_exception_handler(
exception_class: Type[Exception],
handler: middleware.ExceptionHandler,
) -> None
Register an exception handler for the QueryMiddleware
Only one handler can exist for a given exception type.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
exception_class |
Type[Exception]
|
the type of exception to handle |
required |
handler |
ExceptionHandler
|
the function to call when handling an exception |
required |
register_middleware 🔗
Add a QueryMiddleware
to this server.
New in 2.0
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
query_middleware |
QueryMiddleware
|
the middleware to add |
required |
register_rule 🔗
Register the given rule
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule |
RuleBase
|
the rule to register |
required |
rule 🔗
Decorator for registering a function using smart_make_rule
.
Changed in 2.0
: This method now uses smart_make_rule
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
rule_ |
Union[Type[RuleBase], str, Pattern]
|
rule as per |
required |
args |
extra arguments to provide |
()
|
|
kwargs |
extra keyword arguments to provide |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if |