clarin.sru.server.request¶
- class clarin.sru.server.request.SRURequest[source]¶
Bases:
object
Provides information about a SRU request.
- abstract get_operation() SRUOperation [source]¶
Get the
operation
parameter of this request. Available for explain, searchRetrieve and scan requests.
- abstract get_version() SRUVersion [source]¶
Get the version parameter of this request. Available for explain, searchRetrieve and scan requests.
- is_version(version: SRUVersion) bool [source]¶
Check if this request is of a specific version.
- Parameters:
version – the version to check
- Returns:
bool –
True
if this request is in the requestedversion,
False
otherwise
- is_version_between(min: SRUVersion, max: SRUVersion) bool [source]¶
Check if version of this request is at least min and at most max.
- Parameters:
min – the minimum version
max – the maximum version
- Returns:
bool –
True
if this request is in the requestedversion,
False
otherwise
- abstract get_record_xml_escaping() SRURecordXmlEscaping [source]¶
Get the recordXmlEscpaing (SRU 2.0) or recordPacking (SRU 1.1 and SRU 1.2) parameter of this request. Only available for explain and searchRetrieve requests.
- Returns:
SRURecordXmlEscaping – the record XML escaping method
- abstract get_record_packing() SRURecordPacking [source]¶
Get the recordPacking (SRU 2.0) parameter of this request. Only available for searchRetrieve requests.
- Returns:
SRURecordPacking – the record packing method
- abstract get_query() SRUQuery[Any] | None [source]¶
Get the query parameter of this request. Only available for searchRetrieve requests.
- Returns:
SRUQuery[Any] –
- an SRUQuery instance tailored for the
used queryType or None if not a searchRetrieve request
- get_query_type() str | None [source]¶
Get the queryType parameter of this request. Only available for searchRetrieve requests.
- Returns:
str –
- the queryType of the parsed query or None if not a
searchRetrieve request
- is_query_type(query_type: str) bool [source]¶
Check if the request was made with the given queryType. Only available for searchRetrieve requests.
- Parameters:
query_type – the queryType to compare with
- Returns:
bool –
True
if the queryType matches,False
otherwise
- abstract get_start_record() int [source]¶
Get the startRecord parameter of this request. Only available for searchRetrieve requests. If the client did not provide a value for the request, it is set to
1
.- Returns:
int – the number of the start record
- abstract get_maximum_records() int [source]¶
Get the maximumRecords parameter of this request. Only available for searchRetrieve requests. If no value was supplied with the request, the server will automatically set a default value.
- Returns:
int – the maximum number of records
- abstract get_record_schema_identifier() str | None [source]¶
Get the record schema identifier derived from the recordSchema parameter of this request. Only available for searchRetrieve requests. If the request was send with the short record schema name, it will automatically expanded to the record schema identifier.
- Returns:
str –
- the record schema identifier or None if no
recordSchema parameter was supplied for this request
- abstract get_record_xpath() str | None [source]¶
Get the recordXPath parameter of this request. Only available for searchRetrieve requests and version 1.1 requests.
- Returns:
str –
- the record XPath or None of no value was supplied
for this request
- abstract get_resultSet_TTL() int [source]¶
Get the resultSetTTL parameter of this request. Only available for searchRetrieve requests.
- Returns:
int –
- the result set TTL or
-1
if no value was supplied for this request
- the result set TTL or
- abstract get_sortKeys() str | None [source]¶
Get the sortKeys parameter of this request. Only available for searchRetrieve requests and version 1.1 requests.
- Returns:
str –
- the record XPath or None of no value was supplied
for this request
- abstract get_scan_clause() CQLQuery | None [source]¶
Get the scanClause parameter of this request. Only available for scan requests.
- Returns:
cql.CQLQuery –
- the parsed scan clause or None if not a
scan request
- abstract get_response_position() int [source]¶
Get the responsePosition parameter of this request. Only available for scan requests. If the client did not provide a value for the request, it is set to
1
.- Returns:
int – the response position
- abstract get_maximum_terms() int [source]¶
Get the maximumTerms parameter of this request. Available for any type of request.
- Returns:
int –
- the maximum number of terms or
-1
if no value was supplied for this request
- the maximum number of terms or
- abstract get_stylesheet() str | None [source]¶
Get the stylesheet parameter of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
str –
- the stylesheet or None if no value was supplied
for this request
- abstract get_renderBy() SRURenderBy | None [source]¶
Get the renderBy parameter of this request.
- Returns:
SRURenderBy –
- the renderBy parameter or None if no value
was supplied for this request
- abstract get_response_type() str | None [source]¶
(SRU 2.0) The request parameter responseType, paired with the Internet media type specified for the response (via either the httpAccept parameter or http accept header) determines the schema for the response.
- Returns:
str –
- the value of the responeType request parameter or
None if no value was supplied for this request
- abstract get_http_accept() str | None [source]¶
(SRU 2.0) The request parameter httpAccept may be supplied to indicate the preferred format of the response. The value is an Internet media type.
- Returns:
str –
- the value of the httpAccept request parameter or
None if no value was supplied for
- abstract get_protocol_schema() str [source]¶
Get the protocol schema which was used of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
str – the protocol scheme
- abstract get_extra_request_data_names() List[str] [source]¶
Get the names of extra parameters of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
List[str] – a possibly empty list of parameter names
- abstract get_extra_request_data(name: str) str | None [source]¶
Get the value of an extra parameter of this request. Available for explain, searchRetrieve and scan requests.
- Parameters:
name – name of the extra parameter. Must be prefixed with
x-
- Returns:
str –
- the value of the parameter of None of extra
parameter with that name exists
- class clarin.sru.server.request.ParameterInfo(parameter: clarin.sru.server.request.ParameterInfo.Parameter, mandatory: bool, min: clarin.sru.constants.SRUVersion, max: clarin.sru.constants.SRUVersion)[source]¶
Bases:
object
- class Parameter(value)[source]¶
-
An enumeration.
- STYLESHEET = 'stylesheet'¶
- RENDER_BY = 'render_by'¶
- HTTP_ACCEPT = 'http_accept'¶
- RESPONSE_TYPE = 'response_type'¶
- START_RECORD = 'start_record'¶
- MAXIMUM_RECORDS = 'maximum_records'¶
- RECORD_XML_ESCAPING = 'record_xml_escaping'¶
- RECORD_PACKING = 'record_packing'¶
- RECORD_SCHEMA = 'record_schema'¶
- RECORD_XPATH = 'record_xpath'¶
- RESULT_SET_TTL = 'result_set_ttl'¶
- SORT_KEYS = 'sort_keys'¶
- SCAN_CLAUSE = 'scan_clause'¶
- RESPONSE_POSITION = 'response_position'¶
- MAXIMUM_TERMS = 'maximum_terms'¶
- min: SRUVersion¶
- max: SRUVersion¶
- name(version: SRUVersion) str | None [source]¶
- is_for_version(version: SRUVersion) bool [source]¶
- class clarin.sru.server.request.ParameterInfoSets(value)[source]¶
Bases:
Enum
An enumeration.
- EXPLAIN = [ParameterInfo(parameter=<Parameter.STYLESHEET: 'stylesheet'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_1_2: '1.2'>), ParameterInfo(parameter=<Parameter.RECORD_XML_ESCAPING: 'record_xml_escaping'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_1_2: '1.2'>)]¶
- SCAN = [ParameterInfo(parameter=<Parameter.STYLESHEET: 'stylesheet'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.HTTP_ACCEPT: 'http_accept'>, mandatory=False, min=<SRUVersion.VERSION_2_0: '2.0'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.SCAN_CLAUSE: 'scan_clause'>, mandatory=True, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RESPONSE_POSITION: 'response_position'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.MAXIMUM_TERMS: 'maximum_terms'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>)]¶
- SEARCH_RETRIEVE = [ParameterInfo(parameter=<Parameter.STYLESHEET: 'stylesheet'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_1_2: '1.2'>), ParameterInfo(parameter=<Parameter.HTTP_ACCEPT: 'http_accept'>, mandatory=False, min=<SRUVersion.VERSION_2_0: '2.0'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RENDER_BY: 'render_by'>, mandatory=False, min=<SRUVersion.VERSION_2_0: '2.0'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RESPONSE_TYPE: 'response_type'>, mandatory=False, min=<SRUVersion.VERSION_2_0: '2.0'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.START_RECORD: 'start_record'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.MAXIMUM_RECORDS: 'maximum_records'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RECORD_XML_ESCAPING: 'record_xml_escaping'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RECORD_PACKING: 'record_packing'>, mandatory=False, min=<SRUVersion.VERSION_2_0: '2.0'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RECORD_SCHEMA: 'record_schema'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RESULT_SET_TTL: 'result_set_ttl'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>), ParameterInfo(parameter=<Parameter.RECORD_XPATH: 'record_xpath'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_1_2: '1.2'>), ParameterInfo(parameter=<Parameter.SORT_KEYS: 'sort_keys'>, mandatory=False, min=<SRUVersion.VERSION_1_1: '1.1'>, max=<SRUVersion.VERSION_2_0: '2.0'>)]¶
- classmethod for_operation(operation: SRUOperation | None) List[ParameterInfo] | None [source]¶
- class clarin.sru.server.request.SRURequestImpl(config: SRUServerConfig, query_parsers: SRUQueryParserRegistry, request: Request, authentication_info_provider: SRUAuthenticationInfoProvider | None = None)[source]¶
Bases:
SRUDiagnosticList
,SRURequest
- get_operation() SRUOperation [source]¶
Get the
operation
parameter of this request. Available for explain, searchRetrieve and scan requests.
- get_version() SRUVersion [source]¶
Get the version parameter of this request. Available for explain, searchRetrieve and scan requests.
- get_authentication() SRUAuthenticationInfo | None [source]¶
- get_query() SRUQuery[Any] | None [source]¶
Get the query parameter of this request. Only available for searchRetrieve requests.
- Returns:
SRUQuery[Any] –
- an SRUQuery instance tailored for the
used queryType or None if not a searchRetrieve request
- get_record_xml_escaping() SRURecordXmlEscaping [source]¶
Get the recordXmlEscpaing (SRU 2.0) or recordPacking (SRU 1.1 and SRU 1.2) parameter of this request. Only available for explain and searchRetrieve requests.
- Returns:
SRURecordXmlEscaping – the record XML escaping method
- get_record_packing() SRURecordPacking [source]¶
Get the recordPacking (SRU 2.0) parameter of this request. Only available for searchRetrieve requests.
- Returns:
SRURecordPacking – the record packing method
- get_start_record() int [source]¶
Get the startRecord parameter of this request. Only available for searchRetrieve requests. If the client did not provide a value for the request, it is set to
1
.- Returns:
int – the number of the start record
- get_maximum_records() int [source]¶
Get the maximumRecords parameter of this request. Only available for searchRetrieve requests. If no value was supplied with the request, the server will automatically set a default value.
- Returns:
int – the maximum number of records
- get_record_schema_identifier() str | None [source]¶
Get the record schema identifier derived from the recordSchema parameter of this request. Only available for searchRetrieve requests. If the request was send with the short record schema name, it will automatically expanded to the record schema identifier.
- Returns:
str –
- the record schema identifier or None if no
recordSchema parameter was supplied for this request
- get_record_xpath() str | None [source]¶
Get the recordXPath parameter of this request. Only available for searchRetrieve requests and version 1.1 requests.
- Returns:
str –
- the record XPath or None of no value was supplied
for this request
- get_resultSet_TTL() int [source]¶
Get the resultSetTTL parameter of this request. Only available for searchRetrieve requests.
- Returns:
int –
- the result set TTL or
-1
if no value was supplied for this request
- the result set TTL or
- get_sortKeys() str | None [source]¶
Get the sortKeys parameter of this request. Only available for searchRetrieve requests and version 1.1 requests.
- Returns:
str –
- the record XPath or None of no value was supplied
for this request
- get_scan_clause() CQLQuery | None [source]¶
Get the scanClause parameter of this request. Only available for scan requests.
- Returns:
cql.CQLQuery –
- the parsed scan clause or None if not a
scan request
- get_response_position() int [source]¶
Get the responsePosition parameter of this request. Only available for scan requests. If the client did not provide a value for the request, it is set to
1
.- Returns:
int – the response position
- get_maximum_terms() int [source]¶
Get the maximumTerms parameter of this request. Available for any type of request.
- Returns:
int –
- the maximum number of terms or
-1
if no value was supplied for this request
- the maximum number of terms or
- get_stylesheet() str | None [source]¶
Get the stylesheet parameter of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
str –
- the stylesheet or None if no value was supplied
for this request
- get_renderBy() SRURenderBy | None [source]¶
Get the renderBy parameter of this request.
- Returns:
SRURenderBy –
- the renderBy parameter or None if no value
was supplied for this request
- get_response_type() str | None [source]¶
(SRU 2.0) The request parameter responseType, paired with the Internet media type specified for the response (via either the httpAccept parameter or http accept header) determines the schema for the response.
- Returns:
str –
- the value of the responeType request parameter or
None if no value was supplied for this request
- get_version_raw() SRUVersion | None [source]¶
- get_http_accept() str | None [source]¶
(SRU 2.0) The request parameter httpAccept may be supplied to indicate the preferred format of the response. The value is an Internet media type.
- Returns:
str –
- the value of the httpAccept request parameter or
None if no value was supplied for
- get_protocol_schema() str [source]¶
Get the protocol schema which was used of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
str – the protocol scheme
- add_diagnostic(uri: str, details: str | None = None, message: str | None = None) None [source]¶
Add a non surrogate diagnostic to the response.
- Parameters:
uri – the diagnostic’s identifying URI
details – supplementary information available, often in a format specified by the diagnostic or
None
message – human readable message to display to the end user or
None
- add_diagnostic_obj(diagnostic: SRUDiagnostic)[source]¶
- check_parameters() bool [source]¶
Validate incoming request parameters
- Returns:
bool –
True
if successful,False
if somethingwent wrong
- check_parameters_version_operation() bool [source]¶
Validate incoming request parameters version and operation.
- Returns:
bool –
True
if successful,False
if somethingwent wrong
- get_extra_request_data_names() List[str] [source]¶
Get the names of extra parameters of this request. Available for explain, searchRetrieve and scan requests.
- Returns:
List[str] – a possibly empty list of parameter names
- get_extra_request_data(name: str) str | None [source]¶
Get the value of an extra parameter of this request. Available for explain, searchRetrieve and scan requests.
- Parameters:
name – name of the extra parameter. Must be prefixed with
x-
- Returns:
str –
- the value of the parameter of None of extra
parameter with that name exists