clarin.sru.server.server

class clarin.sru.server.server.SRUNamespaces(response_NS: str, response_prefix: str, scan_NS: str, scan_prefix: str, diagnostic_NS: str, XCQL_NS: str, diagnostic_prefix: str = 'diag', explain_NS: str = 'http://explain.z3950.org/dtd/2.0/', explain_prefix: str = 'zr')[source]

Bases: object

Interface for decoupling SRU namespaces from implementation to allow to support SRU 1.1/1.2 and SRU 2.0.

response_NS: str

The namespace URI for encoding explain and searchRetrieve operation responses.

response_prefix: str

The namespace prefix for encoding explain and searchRetrieve

scan_NS: str

The namespace URI for encoding scan operation responses.

scan_prefix: str

The namespace prefix for encoding scan operation responses.

diagnostic_NS: str

The namespace URI for encoding SRU diagnostics.

XCQL_NS: str

The namespace URI for encoding XCQL fragments

diagnostic_prefix: str = 'diag'

The namespace prefix for encoding SRU diagnostics.

explain_NS: str = 'http://explain.z3950.org/dtd/2.0/'

The namespace URI for encoding explain record data fragments.

explain_prefix: str = 'zr'

The namespace prefix for encoding explain record data fragments.

static for_legacy_LOC() SRUNamespaces[source]
static for_1_2_OASIS() SRUNamespaces[source]
static for_2_0() SRUNamespaces[source]
static get_namespaces(version: SRUVersion, legacy_ns_mode: LegacyNamespaceMode) SRUNamespaces[source]
class clarin.sru.server.server.SRUSearchEngine[source]

Bases: object

Interface for connecting the SRU protocol implementation to an actual search engine. Base class required for an SRUSearchEngine implementation to be used with the SRUServerApp.

Implementing the explain and scan is optional, but implementing search is mandatory.

The implementation of these methods must be thread-safe.

abstract explain(config: SRUServerConfig, request: SRURequest, diagnostics: SRUDiagnosticList) SRUExplainResult | None[source]

Handle an explain operation. Implementing this method is optional, but is required, if the writeExtraResponseData block of the SRU response needs to be filled. The arguments for this operation are provides by the SRURequest object.

The implementation of this method must be thread-safe.

Parameters:
  • config – the SRUEndpointConfig object that contains the endpoint configuration

  • request – the SRURequest object that contains the request made to the endpoint

  • diagnostics – the SRUDiagnosticList object for storing non-fatal diagnostics

Returns:

SRUExplainResult

a SRUExplainResult object or None

if the search engine does not want to provide write_extra_response_data

Raises:

SRUException – if an fatal error occurred

abstract search(config: SRUServerConfig, request: SRURequest, diagnostics: SRUDiagnosticList) SRUSearchResultSet[source]

Handle a searchRetrieve operation. Implementing this method is mandatory. The arguments for this operation are provides by the SRURequest object.

The implementation of this method must be thread-safe.

Parameters:
  • config – the SRUEndpointConfig object that contains the endpoint configuration

  • request – the SRURequest object that contains the request made to the endpoint

  • diagnostics – the SRUDiagnosticList object for storing non-fatal diagnostics

Returns:

SRUSearchResultSet – a SRUSearchResultSet object

Raises:

SRUException – if an fatal error occurred

abstract scan(config: SRUServerConfig, request: SRURequest, diagnostics: SRUDiagnosticList) SRUScanResultSet | None[source]

Handle a scan operation. Implementing this method is optional. If you don’t need to handle the scan operation, just return None and the SRU server will return the appropiate diagnostic to the client. The arguments for this operation are provides by the SRURequest object.

The implementation of this method must be thread-safe.

Parameters:
  • config – the SRUEndpointConfig object that contains the endpoint configuration

  • request – the SRURequest object that contains the request made to the endpoint

  • diagnostics – the SRUDiagnosticList object for storing non-fatal diagnostics

Returns:

SRUScanResultSet

a SRUScanResultSet object or None

if this operation is not supported by this search engine

Raises:

SRUException – if an fatal error occurred

init(config: SRUServerConfig, query_parser_registry_builder: Builder, params: Dict[str, str]) None[source]

Initialize the search engine.

Parameters:
  • config – the SRUServerConfig object for this search engine

  • query_parser_registry_builder – the SRUQueryParserRegistry.Builder object to be used for this search engine. Use to register additional query parsers with the SRUServer

  • params – additional parameters from the server

Raises:

SRUConfigException – an error occurred during initialization of the search engine

destroy() None[source]

Destroy the search engine. Use this method for any cleanup the search engine needs to perform upon termination.

class clarin.sru.server.server.SRUServer(config: SRUServerConfig, query_parsers: SRUQueryParserRegistry, search_engine: SRUSearchEngine, authentication_info_provider: SRUAuthenticationInfoProvider | None = None)[source]

Bases: object

SRU/CQL protocol implementation for the server-side (SRU/S). This class implements SRU/CQL version 1.1 and and 1.2.

See also

SRU/CQL protocol 1.2: http://www.loc.gov/standards/sru/

handle_request(request: Request, response: Response)[source]

Handle a SRU request.

TEMP_OUTPUT_BUFFERING = False
explain(request: SRURequestImpl, response: Response)[source]
scan(request: SRURequestImpl, response: Response)[source]
search(request: SRURequestImpl, response: Response)[source]