API Documentation¶
uriregistry¶
- uriregistry._load_configuration(path)[source]¶
Load the configuration for the UriRegistry.
- Parameters
path (str) – Path to the config file in YAML format.
- Returns
A
dict
with the config options.
- uriregistry._parse_settings(settings)[source]¶
Parse the relevant settings for this application.
- Parameters
settings (dict) –
- uriregistry.main(global_config, **settings)[source]¶
This function returns a Pyramid WSGI application.
- Parameters
global_config (pyramid.config.Configurator) –
Models module¶
- class uriregistry.models.Application(uri, title, service_url)[source]¶
Represents the config for an application.
- Parameters
uri (string) – A uri that identifies the application
title (string) – A title for the application
service_url (string) – The url for the service that can be queried
Registry module¶
- class uriregistry.registry.UriRegistry(applications=[], uris=[])[source]¶
Central registry that tracks uris and the applications they are being used in.
- uriregistry.registry._build_uri_registry(registry, registryconfig)[source]¶
- Parameters
registry (pyramid.registry.Registry) – Pyramid registry
registryconfig (dict) – UriRegistry config in dict form.
- Return type
- uriregistry.registry.get_uri_registry(registry)[source]¶
Get the
uriregistry.registry.UriRegistry
attached to this pyramid application.- Return type
Views module¶
- uriregistry.views._get_registry_response(application_responses, uri)[source]¶
Generate the final response by aggregating all the application responses.
- Parameters
application_responses (list) – All
pyramid_urireferencer.models.ApplicationResponse
instances.uri (str) – Uri that was evaluated
base_uri (str) – Base uri of the uri that was evaluated
- Returns
pyramid_urireferencer.models.RegistryResponse
with all information the registry has collected
Utils module¶
pyramid_urireferencer¶
- pyramid_urireferencer._add_referencer(registry)[source]¶
Gets the Referencer from config and adds it to the registry.
- pyramid_urireferencer.includeme(config)[source]¶
this function adds some configuration for the application
Models module¶
- class pyramid_urireferencer.models.ApplicationResponse(title, uri, service_url, success, has_references, count, items)[source]¶
Represents what a certain application will send back to the registry when asked if a certain uri is used by the application.
- Parameters
title (string) – Title of the application
uri (string) – A uri for the application, not guaranteed to be a http url.
service_url (string) – The url that answered the question
success (boolean) – Was the querie successful?
has_references (boolean) – Were any references found?
count (int) – How many references were found?
items (list) – A list of items that have a reference to the uri under survey. Limited to 5 items for performance reasons.
- static load_from_json(data)[source]¶
Load a
ApplicationResponse
from a dictionary or string (that will be parsed as json).
- class pyramid_urireferencer.models.Item(title, uri)[source]¶
A single item that holds a reference to the queried uri.
- Parameters
title (string) – Title of the item.
uri (string) – Uri of the item.
- class pyramid_urireferencer.models.RegistryResponse(query_uri, success, has_references, count, applications)[source]¶
Represents what the registry will send back to a client when asked if a certain uri is used somewhere.
- Parameters
query_uri (string) – Uri of the resource unser survey.
success (boolean) – Were all the queries successful?
has_references (boolean) – Were any references found?
count (int) – How many references were found?
applications (list) – A list of application results.
Protected resources module¶
Thids module is used when blocking operations on a certain uri that might be used in external applications. .. versionadded:: 0.4.0
- pyramid_urireferencer.protected_resources.protected_operation(fn)[source]¶
Use this decorator to prevent an operation from being executed when the related uri resource is still in use. The parent_object must contain:
- a request
with a registry.queryUtility(IReferencer)
- Raises
pyramid.httpexceptions.HTTPConflict – Signals that we don’t want to delete a certain URI because it’s still in use somewhere else.
pyramid.httpexceptions.HTTPInternalServerError – Raised when we were unable to check that the URI is no longer being used.
- pyramid_urireferencer.protected_resources.protected_operation_with_request(fn)[source]¶
Use this decorator to prevent an operation from being executed when the related uri resource is still in use. The request must contain a registry.queryUtility(IReferencer) :raises pyramid.httpexceptions.HTTPConflict: Signals that we don’t want to
delete a certain URI because it’s still in use somewhere else.
- Raises
pyramid.httpexceptions.HTTPInternalServerError – Raised when we were unable to check that the URI is no longer being used.
Referencer module¶
- class pyramid_urireferencer.referencer.AbstractReferencer[source]¶
This is an abstract class that defines what a Referencer needs to be able to handle.
It does two things:
Check if a uri is being used in this application and report on this.
Check if a certain uri is being used in another application by query a central registry. * this requires a function
get_uri()
to determine the uri of the current request
- abstract get_uri(request)[source]¶
This method extracts a uri from the request. This is the uri that needs to be checked.
- Parameters
request –
pyramid.request.Request
with useful configuration information and connections of the application (registry, route_url, session) to determine the references- Return type
string uri: URI of the resource we need to check for
- abstract is_referenced(uri)[source]¶
This method checks if a certain uri is being referenced from resources in other applications.
- Parameters
uri (string) – URI of the resource that needs to be checked
- Return type
- abstract references(uri, request)[source]¶
This method checks if a certain uri is being referenced by any other resource within this application.
- Parameters
uri (string) – URI of the resource we need to check for
request –
pyramid.request.Request
with useful configuration information and connections of the application (registry, route_url, session) to determine the references
- Return type
- class pyramid_urireferencer.referencer.Referencer(registry_url, **kwargs)[source]¶
This is an implementation of the
AbstractReferencer
that adds a genericis_referenced()
method and plain methods:references()
andget_uri()
Rendererers module¶
- pyramid_urireferencer.renderers.application_adapter(obj, request)[source]¶
Adapter for rendering a
pyramid_urireferencer.models.ApplicationResponse
to json.- Parameters
obj (pyramid_urireferencer.models.ApplicationResponse) – The response to be rendered.
- Return type
dict
- pyramid_urireferencer.renderers.registry_adapter(obj, request)[source]¶
Adapter for rendering a
pyramid_urireferencer.models.RegistryResponse
to json.- Parameters
obj (pyramid_urireferencer.models.RegistryResponse) – The response to be rendered.
- Return type
dict