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

class uriregistry.models.UriTemplate(match_uri, applications)[source]

Represents the config for a certain uri template.

Parameters
  • match_uri (string) – A regex that needs to be matched.

  • applications (list) – A list of application uri’s.

matches(uri)[source]

Does the URI match this template?

Parameters

uri (string) – URI to be matched

Return type

boolean

Registry module

class uriregistry.registry.UriRegistry(applications=[], uris=[])[source]

Central registry that tracks uris and the applications they are being used in.

get_applications(uri)[source]

Get all applications that might have a reference to this URI.

Parameters

uri (string) – Uri for which the applications need to be found.

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.UriRegistry

uriregistry.registry.get_uri_registry(registry)[source]

Get the uriregistry.registry.UriRegistry attached to this pyramid application.

Return type

uriregistry.registry.UriRegistry

Views module

uriregistry.views._get_registry_response(application_responses, uri)[source]

Generate the final response by aggregating all the application responses.

Parameters
Returns

pyramid_urireferencer.models.RegistryResponse with all information the registry has collected

Utils module

uriregistry.utils.query_application(app, uri)[source]

Checks if a certain app has references to a URI.

Parameters
  • uriregistry.models.Application – The application to be evaluated

  • uri – The uri that has to be checked

Rtype pyramid_urireferencer.models.ApplicationResponse

pyramid_urireferencer

pyramid_urireferencer._add_referencer(registry)[source]

Gets the Referencer from config and adds it to the registry.

pyramid_urireferencer.get_referencer(registry)[source]

Get the referencer class

Return type

pyramid_urireferencer.referencer.AbstractReferencer

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.

static load_from_json(data)[source]

Load a Item from a dictionary ot string (that will be parsed as json)

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.

static load_from_json(data)[source]

Load a RegistryReponse from a dictionary or a string (that will be parsed as json).

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.

pyramid_urireferencer.protected_resources.protected_view(view, info)[source]

allows adding protected=True to a view_config`

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

requestpyramid.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

pyramid_urireferencer.models.RegistryResponse

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

  • requestpyramid.request.Request with useful configuration information and connections of the application (registry, route_url, session) to determine the references

Return type

pyramid_urireferencer.models.ApplicationResponse

class pyramid_urireferencer.referencer.Referencer(registry_url, **kwargs)[source]

This is an implementation of the AbstractReferencer that adds a generic is_referenced() method and plain methods: references() and get_uri()

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

pyramid_urireferencer.models.RegistryResponse

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

Views module