Parsers¶
The regparse package. Contains parsers for ESRI feature services and WMSes.
An ESRI feature “parser” (really the requests library does most of the actual parsing).
Most of the utility functions are exposed but most applications won’t use them :func:make_node is generally the only point of interest here.
-
regparse.esri_feature.
get_base_url
(feature_service_url)¶ Strips trailing / from the feature service URL if present.
Parameters: feature_service_url (str) – A URL pointing to an ESRI feature service Returns: str – A URL pointing to the base URL
-
regparse.esri_feature.
get_legend_mapping
(data, layer_id)¶ Generates a mapping of layer labels to image data URLs.
Parameters: - data (dict) – The initial payload to RCS (should contain a ‘service_url’ entry)
- layer_id – The id of the layer to create the mapping for.
Returns: dict – a mapping of ‘label’ => ‘data URI encoded image’
-
regparse.esri_feature.
get_legend_url
(feature_service_url)¶ Converts a feature service URL into a legend request. Handles the optional ‘/’ at the end of requests.
Parameters: feature_service_url (str) – A URL pointing to an ESRI feature service Returns: str – A URL pointing to a legend request
-
regparse.esri_feature.
make_alias_mapping
(json_data)¶ Generates a mapping of field names to field aliases.
Parameters: json_data (list) – An array of field objects, taken from the fields property of an ESRI feature service endpoint Returns: dict – a mapping of ‘name’ => ‘alias’
-
regparse.esri_feature.
make_data_grid
(json_data)¶ Generate a RAMP datagrid by walking through the attributes. Iterates over all entries in fields that do not have a type of esriFieldTypeGeometry
Parameters: json_data (dict) – A dictionary containing scraped data from an ESRI feature service endpoint Returns: dict – A dictionary with a single entry gridColumns containing an array of datagrid objects
-
regparse.esri_feature.
make_extent
(json_data)¶ Extracts the extent for the layer from ESRI’s JSON config.
Parameters: json_data (dict) – A dictionary containing scraped data from an ESRI feature service endpoint Returns: dict – A dictionary with the same data as the ESRI layerExtent node
-
regparse.esri_feature.
make_grid_col
(**kw)¶ - Generate a RAMP compliant datagrid column object with the following defaults:
- fieldName ‘’ isSortable False sortType ‘string’ alignment 0
Parameters: kw – Takes keyword arguments and just fills in the defaults Returns: dict – a dictionary with the defaults applied
-
regparse.esri_feature.
make_node
(data, id, config)¶ Generate a RAMP layer entry for an ESRI feature service.
Parameters: - data (dict) – The initial payload to RCS (should contain a ‘service_url’ entry)
- id (str) – An identifier for the layer (as this is unique it is generally supplied from :module:rcs )
Returns: dict – a RAMP configuration fragment representing the ESRI layer
-
regparse.esri_feature.
make_symbology
(json_data, data)¶ Generates a symbology node for the RAMP configuration. Handles simple, unique value and class break renders; prefetches all symbology images.
Parameters: - json_data (dict) – A dictionary containing scraped data from an ESRI feature service endpoint
- data (dict) – The initial payload to RCS (should contain a ‘service_url’ entry)
Returns: dict – a symbology node
-
regparse.esri_feature.
test_small_layer
(svc_url, svc_data)¶ Test a service endpoint to see if the layer is small based on some simple rules.
Parameters: - svc_url (str) – The URL pointing to the feature endpoint
- svc_data (dict) – A dictionary containing scraped data from an ESRI feature service endpoint
Returns: bool – True if the layer is considered ‘small’
A WMS “parser” (barely does any parsing at the moment).
-
regparse.wms.
make_feature_info
(data)¶ Make a RAMP feature info node, identifying the correct default parser to be used based on the MIME type of the feature info request.
- Currently accepted MIME types (in order of preference):
- ‘text/html’ ‘text/plain’ ‘application/json’
Parameters: data (dict) – The initial payload to RCS Returns: dict – A feature info configuration fragment; None if no valid mimeType was set
-
regparse.wms.
make_node
(data, id, config=None)¶ Generate a RAMP layer entry for a WMS.
Parameters: - data (dict) – The initial payload to RCS
- id (str) – An identifier for the layer (as this is unique it is generally supplied from :module:rcs )
Returns: dict – a RAMP configuration fragment representing the WMS layer
Tests RCS request signatures for validity
-
regparse.sigcheck.
check_time
(request)¶ Ensure the sent time is within 2 minutes of the current time
Parameters: sent (str) – An ISO8601 encoded date Raises: ParseError – if the datetime cannot be parsed Returns: bool – sent time is within 2 minutes of the current time
-
regparse.sigcheck.
get_logger
()¶ This function does not deserve a comment
-
regparse.sigcheck.
sign
(key, *parts)¶ Creates an HMAC_SHA256 signature from a key and a set of message parts
Parameters: key (str) – The signing key to use Returns: str – a URL safe base64 encoded signature
-
regparse.sigcheck.
test_request
(request)¶ Test the signature of a given request.
Pulls the signature components from the request and generates a reference signature. Tests if the reference signature matches the Authorization header in the request.
Parameters: request – A flask request object containing the request to validate Returns: bool – if the generated signature matches the authorization header
-
regparse.sigcheck.
validate
(func)¶ Wraps a service endpoint and checks the authentication headers.
Tests the signature on the request and ensures the request time is current. Failure results in a 401 HTTP error if SIG_CHECK is enabled, if not validation will always pass.